From b6964f5fbeda7ac6b531653bcecf5bfd37f39cc2 Mon Sep 17 00:00:00 2001
From: npmrun <1549469775@qq.com>
Date: Thu, 27 Mar 2025 00:55:24 +0800
Subject: [PATCH] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E7=BC=A9=E8=BF=9B=E4=B8=BA2=E4=B8=AA=E7=A9=BA=E6=A0=BC?=
=?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB?=
=?UTF-8?q?=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
此次提交主要将代码中的缩进统一调整为2个空格,替换原有的4个空格或Tab缩进。这一改动不影响代码功能,但有助于提升代码的一致性和可读性。
---
.prettierrc | 60 +-
.vscode/extensions.json | 2 +-
.vscode/launch.json | 74 +-
.vscode/settings.json | 32 +-
config/index.ts | 54 +-
electron-builder.yml | 62 +-
electron.vite.config.ts | 180 +--
package.json | 152 +--
pnpm-workspace.yaml | 2 +-
resources/fuck.html | 17 +-
src/common/_ioc.main.ts | 8 +-
src/common/event/PlatForm/index.ts | 36 +-
src/common/event/PlatForm/main/command.ts | 124 +--
src/common/event/Tabs/index.ts | 100 +-
src/common/event/Tabs/main/command.ts | 88 +-
src/common/event/update/index.ts | 6 +-
src/common/event/update/main/command.ts | 8 +-
src/common/event/update/main/index.ts | 2 +-
src/common/lib/_Base.ts | 16 +-
src/common/lib/abstract.ts | 78 +-
src/common/lib/browser.ts | 44 +-
src/common/lib/electron.ts | 26 +-
src/common/usePlatform.ts | 8 +-
src/main/App copy.ts | 278 ++---
src/main/App.ts | 120 +-
src/main/_ioc.ts | 6 +-
src/main/_iocClass.ts | 24 +-
src/main/base/base.ts | 6 +-
src/main/controller/BasicService.ts | 30 +-
src/main/controller/TabsService.ts | 54 +-
src/main/controller/_ioc.ts | 6 +-
src/main/index.ts | 90 +-
src/main/modules/_ioc.ts | 38 +-
src/main/modules/api/index.ts | 152 +--
src/main/modules/api/readme.md | 1 -
src/main/modules/api/test.ts | 1 -
src/main/modules/commands/index.ts | 166 +--
src/main/modules/db/custom.ts | 44 +-
src/main/modules/db/index.ts | 116 +-
src/main/modules/setting/index.ts | 356 +++---
src/main/modules/tabs/Constant.ts | 8 +-
src/main/modules/tabs/Tab.ts | 484 ++++----
src/main/modules/tabs/index.ts | 204 ++--
src/main/modules/updater/hot/index.ts | 126 +--
src/main/modules/updater/index.ts | 218 ++--
src/main/modules/window-manager/index.ts | 612 +++++-----
src/main/modules/window-manager/windowsMap.ts | 216 ++--
src/main/modules/zephyr/index.ts | 734 ++++++------
src/main/utils/index.ts | 28 +-
src/preload/call.ts | 106 +-
src/preload/index.ts | 84 +-
src/renderer/about.html | 48 +-
src/renderer/auto-imports.d.ts | 1177 ++++++++++----------
src/renderer/index.html | 27 +-
src/renderer/src/App.vue | 32 +-
src/renderer/src/assets/libs/scrollbot.ts | 427 ++++---
src/renderer/src/assets/style/_common.scss | 38 +-
src/renderer/src/bridge/PopupMenu.ts | 98 +-
src/renderer/src/components/AdjustLine.vue | 758 ++++++-------
.../CodeEditor/PlaceholderContentWidget.ts | 86 +-
src/renderer/src/components/CodeEditor/a.d.ts | 2 +-
.../src/components/CodeEditor/code-editor.vue | 441 ++++----
src/renderer/src/components/CodeEditor/readme.md | 2 +-
src/renderer/src/components/CodeEditor/utils.ts | 58 +-
src/renderer/src/components/NavBar.vue | 138 +--
src/renderer/src/components/Versions.vue | 14 +-
src/renderer/src/composables/useTest.ts | 2 +-
src/renderer/src/env.d.ts | 8 +-
src/renderer/src/i18n/index.ts | 14 +-
src/renderer/src/layouts/default.vue | 12 +-
src/renderer/src/main.ts | 8 +-
src/renderer/src/pages/[...all].vue | 2 +-
src/renderer/src/pages/_ui/App.vue | 14 +-
src/renderer/src/pages/_ui/Browser.vue | 404 +++----
src/renderer/src/pages/about/index.vue | 58 +-
src/renderer/src/pages/browser.vue | 218 ++--
src/renderer/src/pages/index.vue | 42 +-
src/renderer/src/router/index.ts | 6 +-
src/renderer/src/shims.d.ts | 2 +-
src/renderer/src/utils/index.ts | 8 +-
src/types/global.d.ts | 25 +-
src/types/popup-menu.ts | 10 +-
uno.config.ts | 136 +--
vue-macros.config.ts | 2 +-
推荐.md | 4 -
85 files changed, 4908 insertions(+), 4900 deletions(-)
diff --git a/.prettierrc b/.prettierrc
index ed0ee55..3d6170c 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -1,32 +1,32 @@
{
- "tabWidth": 2,
- "useTabs": false,
- "semi": false,
- "singleQuote": false,
- "trailingComma": "all",
- "bracketSpacing": true,
- "arrowParens": "avoid",
- "printWidth": 140,
- "htmlWhitespaceSensitivity": "ignore",
- "proseWrap": "preserve",
- "endOfLine": "auto",
- "vueIndentScriptAndStyle": true,
- "embeddedLanguageFormatting": "auto",
- "jsxSingleQuote": false,
- "jsxBracketSameLine": false,
- "quoteProps": "as-needed",
- "overrides": [
- {
- "files": "*.json",
- "options": {
- "printWidth": 80
- }
- },
- {
- "files": ["*.vue", "*.tsx"],
- "options": {
- "singleAttributePerLine": false
- }
- }
- ]
+ "tabWidth": 2,
+ "useTabs": false,
+ "semi": false,
+ "singleQuote": false,
+ "trailingComma": "all",
+ "bracketSpacing": true,
+ "arrowParens": "avoid",
+ "printWidth": 140,
+ "htmlWhitespaceSensitivity": "ignore",
+ "proseWrap": "preserve",
+ "endOfLine": "auto",
+ "vueIndentScriptAndStyle": true,
+ "embeddedLanguageFormatting": "auto",
+ "jsxSingleQuote": false,
+ "jsxBracketSameLine": false,
+ "quoteProps": "as-needed",
+ "overrides": [
+ {
+ "files": "*.json",
+ "options": {
+ "printWidth": 80
+ }
+ },
+ {
+ "files": ["*.vue", "*.tsx"],
+ "options": {
+ "singleAttributePerLine": false
+ }
+ }
+ ]
}
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index 82d8334..b669e89 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -1,3 +1,3 @@
{
- "recommendations": ["dbaeumer.vscode-eslint", "lokalise.i18n-ally"]
+ "recommendations": ["dbaeumer.vscode-eslint", "lokalise.i18n-ally"]
}
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 344cf45..0b6b9a6 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -1,39 +1,39 @@
{
- "version": "0.2.0",
- "configurations": [
- {
- "name": "Debug Main Process",
- "type": "node",
- "request": "launch",
- "cwd": "${workspaceRoot}",
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
- "windows": {
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
- },
- "runtimeArgs": ["--sourcemap"],
- "env": {
- "REMOTE_DEBUGGING_PORT": "9222"
- }
- },
- {
- "name": "Debug Renderer Process",
- "port": 9222,
- "request": "attach",
- "type": "chrome",
- "webRoot": "${workspaceFolder}/src/renderer",
- "timeout": 60000,
- "presentation": {
- "hidden": true
- }
- }
- ],
- "compounds": [
- {
- "name": "Debug All",
- "configurations": ["Debug Main Process", "Debug Renderer Process"],
- "presentation": {
- "order": 1
- }
- }
- ]
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug Main Process",
+ "type": "node",
+ "request": "launch",
+ "cwd": "${workspaceRoot}",
+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
+ "windows": {
+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
+ },
+ "runtimeArgs": ["--sourcemap"],
+ "env": {
+ "REMOTE_DEBUGGING_PORT": "9222"
+ }
+ },
+ {
+ "name": "Debug Renderer Process",
+ "port": 9222,
+ "request": "attach",
+ "type": "chrome",
+ "webRoot": "${workspaceFolder}/src/renderer",
+ "timeout": 60000,
+ "presentation": {
+ "hidden": true
+ }
+ }
+ ],
+ "compounds": [
+ {
+ "name": "Debug All",
+ "configurations": ["Debug Main Process", "Debug Renderer Process"],
+ "presentation": {
+ "order": 1
+ }
+ }
+ ]
}
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 4c61b65..d59e66d 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,18 +1,18 @@
{
- "[typescript]": {
- "editor.defaultFormatter": "esbenp.prettier-vscode"
- },
- "[javascript]": {
- "editor.defaultFormatter": "esbenp.prettier-vscode"
- },
- "[json]": {
- "editor.defaultFormatter": "esbenp.prettier-vscode"
- },
- "i18n-ally.localesPaths": ["packages/locales/languages"],
- "i18n-ally.sourceLanguage": "zh",
- "i18n-ally.displayLanguage": "zh",
- "i18n-ally.keystyle": "nested",
- "i18n-ally.extract.autoDetect": true,
- "i18n-ally.enabledFrameworks": ["vue"],
- "i18n-ally.enabledParsers": ["json"]
+ "[typescript]": {
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
+ },
+ "[javascript]": {
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
+ },
+ "[json]": {
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
+ },
+ "i18n-ally.localesPaths": ["packages/locales/languages"],
+ "i18n-ally.sourceLanguage": "zh",
+ "i18n-ally.displayLanguage": "zh",
+ "i18n-ally.keystyle": "nested",
+ "i18n-ally.extract.autoDetect": true,
+ "i18n-ally.enabledFrameworks": ["vue"],
+ "i18n-ally.enabledParsers": ["json"]
}
diff --git a/config/index.ts b/config/index.ts
index aa7e86b..e23e906 100644
--- a/config/index.ts
+++ b/config/index.ts
@@ -7,38 +7,38 @@ type LogoType = "logo" | "bg"
// 配置接口定义
interface IDefaultConfig {
- language: LanguageType
- "common.theme": ThemeType
- "desktop:wallpaper": string
- "update.repo"?: string
- "update.owner"?: string
- "update.allowDowngrade": boolean
- "update.allowPrerelease": boolean
- "editor.bg": string
- "editor.logoType": LogoType
- "editor.fontFamily": string
- storagePath: string
+ language: LanguageType
+ "common.theme": ThemeType
+ "desktop:wallpaper": string
+ "update.repo"?: string
+ "update.owner"?: string
+ "update.allowDowngrade": boolean
+ "update.allowPrerelease": boolean
+ "editor.bg": string
+ "editor.logoType": LogoType
+ "editor.fontFamily": string
+ storagePath: string
}
interface IConfig {
- app_title: string
- default_config: IDefaultConfig
+ app_title: string
+ default_config: IDefaultConfig
}
// 默认配置导出
export default {
- app_title: "zephyr", // 和风
- default_config: {
- storagePath: "$storagePath$",
- language: "zh",
- "common.theme": "auto",
- "desktop:wallpaper": "",
- "editor.bg": "",
- "editor.logoType": "logo",
- "editor.fontFamily": "Cascadia Mono, Consolas, 'Courier New', monospace",
- "update.repo": "wood-desktop",
- "update.owner": "npmrun",
- "update.allowDowngrade": false,
- "update.allowPrerelease": false,
- },
+ app_title: "zephyr", // 和风
+ default_config: {
+ storagePath: "$storagePath$",
+ language: "zh",
+ "common.theme": "auto",
+ "desktop:wallpaper": "",
+ "editor.bg": "",
+ "editor.logoType": "logo",
+ "editor.fontFamily": "Cascadia Mono, Consolas, 'Courier New', monospace",
+ "update.repo": "wood-desktop",
+ "update.owner": "npmrun",
+ "update.allowDowngrade": false,
+ "update.allowPrerelease": false,
+ },
} as const satisfies IConfig
diff --git a/electron-builder.yml b/electron-builder.yml
index 0ccc997..1c7aff4 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -1,45 +1,45 @@
appId: com.zephyr.app
productName: zephyr
directories:
- buildResources: build
+ buildResources: build
files:
- - "!**/.vscode/*"
- - "!src/*"
- - "!electron.vite.config.{js,ts,mjs,cjs}"
- - "!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}"
- - "!{.env,.env.*,.npmrc,pnpm-lock.yaml}"
- - "!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}"
+ - "!**/.vscode/*"
+ - "!src/*"
+ - "!electron.vite.config.{js,ts,mjs,cjs}"
+ - "!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}"
+ - "!{.env,.env.*,.npmrc,pnpm-lock.yaml}"
+ - "!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}"
asarUnpack:
- - resources/**
+ - resources/**
win:
- executableName: zephyr
+ executableName: zephyr
nsis:
- artifactName: ${name}-${version}-setup.${ext}
- shortcutName: ${productName}
- uninstallDisplayName: ${productName}
- createDesktopShortcut: always
+ artifactName: ${name}-${version}-setup.${ext}
+ shortcutName: ${productName}
+ uninstallDisplayName: ${productName}
+ createDesktopShortcut: always
mac:
- entitlementsInherit: build/entitlements.mac.plist
- extendInfo:
- - NSCameraUsageDescription: Application requests access to the device's camera.
- - NSMicrophoneUsageDescription: Application requests access to the device's microphone.
- - NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
- - NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
- notarize: false
+ entitlementsInherit: build/entitlements.mac.plist
+ extendInfo:
+ - NSCameraUsageDescription: Application requests access to the device's camera.
+ - NSMicrophoneUsageDescription: Application requests access to the device's microphone.
+ - NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
+ - NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
+ notarize: false
dmg:
- artifactName: ${name}-${version}.${ext}
+ artifactName: ${name}-${version}.${ext}
linux:
- target:
- - AppImage
- - snap
- - deb
- maintainer: electronjs.org
- category: Utility
+ target:
+ - AppImage
+ - snap
+ - deb
+ maintainer: electronjs.org
+ category: Utility
appImage:
- artifactName: ${name}-${version}.${ext}
+ artifactName: ${name}-${version}.${ext}
npmRebuild: false
publish:
- provider: generic
- url: https://example.com/auto-updates
+ provider: generic
+ url: https://example.com/auto-updates
electronDownload:
- mirror: https://npmmirror.com/mirrors/electron/
+ mirror: https://npmmirror.com/mirrors/electron/
diff --git a/electron.vite.config.ts b/electron.vite.config.ts
index feaba98..319bacd 100644
--- a/electron.vite.config.ts
+++ b/electron.vite.config.ts
@@ -13,100 +13,100 @@ import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"
import monacoEditorPlugin from "vite-plugin-monaco-editor"
export default defineConfig({
- main: {
- resolve: {
- alias: {
- config: resolve("config"),
- main: resolve("src/main"),
- common: resolve("src/common"),
- "@res": resolve("resources"),
- },
- },
- plugins: [externalizeDepsPlugin()],
+ main: {
+ resolve: {
+ alias: {
+ config: resolve("config"),
+ main: resolve("src/main"),
+ common: resolve("src/common"),
+ "@res": resolve("resources"),
+ },
},
- preload: {
- plugins: [externalizeDepsPlugin()],
+ plugins: [externalizeDepsPlugin()],
+ },
+ preload: {
+ plugins: [externalizeDepsPlugin()],
+ },
+ renderer: {
+ root: resolve(__dirname, "./src/renderer"),
+ resolve: {
+ alias: {
+ config: resolve("config"),
+ common: resolve("src/common"),
+ "@": resolve("src/renderer/src"),
+ "@res": resolve("resources"),
+ },
},
- renderer: {
- root: resolve(__dirname, "./src/renderer"),
- resolve: {
- alias: {
- config: resolve("config"),
- common: resolve("src/common"),
- "@": resolve("src/renderer/src"),
- "@res": resolve("resources"),
- },
+ css: {
+ preprocessorOptions: {
+ scss: {
+ additionalData: `@use "@/assets/style/global" as *;\n`,
+ api: "modern-compiler",
},
- css: {
- preprocessorOptions: {
- scss: {
- additionalData: `@use "@/assets/style/global" as *;\n`,
- api: "modern-compiler",
- },
- },
+ },
+ },
+ build: {
+ rollupOptions: {
+ input: {
+ main: resolve(__dirname, "./src/renderer/index.html"),
+ about: resolve(__dirname, "./src/renderer/about.html"),
},
- build: {
- rollupOptions: {
- input: {
- main: resolve(__dirname, "./src/renderer/index.html"),
- about: resolve(__dirname, "./src/renderer/about.html"),
- },
- },
+ },
+ },
+ plugins: [
+ UnoCSS(),
+ VueMacros({
+ plugins: {
+ vue: vue(),
+ vueJsx: vueJsx(),
+ vueRouter: VueRouter({
+ root: resolve(__dirname, "src/renderer"),
+ // https://github.com/posva/unplugin-vue-router
+ extensions: [".vue", ".setup.tsx"],
+ exclude: ["**/_ui"],
+ }),
},
- plugins: [
- UnoCSS(),
- VueMacros({
- plugins: {
- vue: vue(),
- vueJsx: vueJsx(),
- vueRouter: VueRouter({
- root: resolve(__dirname, "src/renderer"),
- // https://github.com/posva/unplugin-vue-router
- extensions: [".vue", ".setup.tsx"],
- exclude: ["**/_ui"],
- }),
- },
- }),
- VueI18nPlugin({
- compositionOnly: false,
- include: resolve(__dirname, "packages/locales/languages/**"),
- }),
- Layouts({
- layoutsDirs: "src/layouts",
- pagesDirs: "src/pages",
- defaultLayout: "default",
- extensions: ["vue", "setup.tsx"],
- exclude: ["**/_ui"],
- }),
- // https://github.com/antfu/unplugin-auto-import
- AutoImport({
- imports: [
- "vue",
- "@vueuse/core",
- VueRouterAutoImports,
- {
- // add any other imports you were relying on
- "vue-router/auto": ["useLink"],
- },
- "vue-i18n",
- ],
- dts: true,
- dirs: ["src/composables"],
- vueTemplate: true,
- }),
- // https://github.com/antfu/vite-plugin-components
- Components({
- dts: true,
- dirs: ["src/components"],
- }),
- // https://wf0.github.io/example/plugins/Formatter.html
- // @ts-ignore ...
- monacoEditorPlugin.default({
- publicPath: "monacoeditorwork",
- customDistPath() {
- return resolve(__dirname, "out/renderer/monacoeditorwork")
- },
- }),
+ }),
+ VueI18nPlugin({
+ compositionOnly: false,
+ include: resolve(__dirname, "packages/locales/languages/**"),
+ }),
+ Layouts({
+ layoutsDirs: "src/layouts",
+ pagesDirs: "src/pages",
+ defaultLayout: "default",
+ extensions: ["vue", "setup.tsx"],
+ exclude: ["**/_ui"],
+ }),
+ // https://github.com/antfu/unplugin-auto-import
+ AutoImport({
+ imports: [
+ "vue",
+ "@vueuse/core",
+ VueRouterAutoImports,
+ {
+ // add any other imports you were relying on
+ "vue-router/auto": ["useLink"],
+ },
+ "vue-i18n",
],
- },
+ dts: true,
+ dirs: ["src/composables"],
+ vueTemplate: true,
+ }),
+ // https://github.com/antfu/vite-plugin-components
+ Components({
+ dts: true,
+ dirs: ["src/components"],
+ }),
+ // https://wf0.github.io/example/plugins/Formatter.html
+ // @ts-ignore ...
+ monacoEditorPlugin.default({
+ publicPath: "monacoeditorwork",
+ customDistPath() {
+ return resolve(__dirname, "out/renderer/monacoeditorwork")
+ },
+ }),
+ ],
+ },
})
diff --git a/package.json b/package.json
index d1548d0..aaa00a7 100644
--- a/package.json
+++ b/package.json
@@ -1,78 +1,78 @@
{
- "name": "zephyr",
- "type": "module",
- "private": true,
- "version": "0.0.1",
- "description": "An Electron application with Vue and TypeScript",
- "main": "./out/main/index.js",
- "author": "example.com",
- "homepage": "https://electron-vite.org",
- "scripts": {
- "runInstall": "node node_modules/electron/install.js",
- "format": "prettier --write .",
- "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
- "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
- "typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false",
- "typecheck": "npm run typecheck:node && npm run typecheck:web",
- "start": "electron-vite preview",
- "dev": "chcp 65001 && set DEBUG=app:*&& electron-vite dev",
- "dev:watch": "chcp 65001 & set DEBUG=app:*& electron-vite dev --watch",
- "build": "npm run typecheck && electron-vite build",
- "postinstall": "electron-builder install-app-deps",
- "build:unpack": "npm run build && electron-builder --dir",
- "build:win": "npm run build && electron-builder --win",
- "build:mac": "npm run build && electron-builder --mac",
- "build:linux": "npm run build && electron-builder --linux"
- },
- "dependencies": {
- "@electron-toolkit/preload": "^3.0.1",
- "@electron-toolkit/utils": "^3.0.0",
- "electron-updater": "^6.3.9",
- "inversify": "^6.2.2",
- "lowdb": "^7.0.1",
- "reflect-metadata": "^0.2.2"
- },
- "devDependencies": {
- "@electron-toolkit/eslint-config": "^1.0.2",
- "@electron-toolkit/eslint-config-ts": "^2.0.0",
- "@electron-toolkit/tsconfig": "^1.0.1",
- "@intlify/unplugin-vue-i18n": "^6.0.3",
- "@rushstack/eslint-patch": "^1.10.5",
- "@types/debug": "^4.1.12",
- "@types/node": "^20.17.19",
- "@unocss/preset-rem-to-px": "^0.64.1",
- "@unocss/reset": "^0.64.1",
- "@vitejs/plugin-vue": "^5.2.1",
- "@vitejs/plugin-vue-jsx": "^4.1.1",
- "@vue/eslint-config-prettier": "^9.0.0",
- "@vue/eslint-config-typescript": "^13.0.0",
- "@vueuse/core": "^12.7.0",
- "debug": "^4.4.0",
- "electron": "^31.7.7",
- "electron-builder": "^24.13.3",
- "electron-vite": "^2.3.0",
- "eslint": "^8.57.1",
- "eslint-plugin-vue": "^9.32.0",
- "extract-zip": "^2.0.1",
- "locales": "workspace:*",
- "lodash-es": "^4.17.21",
- "monaco-editor": "^0.52.2",
- "prettier": "^3.5.1",
- "rotating-file-stream": "^3.2.6",
- "sass": "^1.85.0",
- "simplebar-vue": "^2.4.0",
- "typescript": "^5.7.3",
- "unocss": "^0.64.1",
- "unplugin-auto-import": "^19.1.0",
- "unplugin-vue-components": "^28.4.0",
- "unplugin-vue-macros": "^2.14.2",
- "unplugin-vue-router": "^0.11.2",
- "vite": "^5.4.14",
- "vite-plugin-monaco-editor": "^1.1.0",
- "vite-plugin-vue-layouts": "^0.11.0",
- "vue": "^3.5.13",
- "vue-i18n": "^11.1.1",
- "vue-router": "^4.5.0",
- "vue-tsc": "^2.1.10"
- }
+ "name": "zephyr",
+ "type": "module",
+ "private": true,
+ "version": "0.0.1",
+ "description": "An Electron application with Vue and TypeScript",
+ "main": "./out/main/index.js",
+ "author": "example.com",
+ "homepage": "https://electron-vite.org",
+ "scripts": {
+ "runInstall": "node node_modules/electron/install.js",
+ "format": "prettier --write .",
+ "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
+ "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
+ "typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false",
+ "typecheck": "npm run typecheck:node && npm run typecheck:web",
+ "start": "electron-vite preview",
+ "dev": "chcp 65001 && set DEBUG=app:*&& electron-vite dev",
+ "dev:watch": "chcp 65001 & set DEBUG=app:*& electron-vite dev --watch",
+ "build": "npm run typecheck && electron-vite build",
+ "postinstall": "electron-builder install-app-deps",
+ "build:unpack": "npm run build && electron-builder --dir",
+ "build:win": "npm run build && electron-builder --win",
+ "build:mac": "npm run build && electron-builder --mac",
+ "build:linux": "npm run build && electron-builder --linux"
+ },
+ "dependencies": {
+ "@electron-toolkit/preload": "^3.0.1",
+ "@electron-toolkit/utils": "^3.0.0",
+ "electron-updater": "^6.3.9",
+ "inversify": "^6.2.2",
+ "lowdb": "^7.0.1",
+ "reflect-metadata": "^0.2.2"
+ },
+ "devDependencies": {
+ "@electron-toolkit/eslint-config": "^1.0.2",
+ "@electron-toolkit/eslint-config-ts": "^2.0.0",
+ "@electron-toolkit/tsconfig": "^1.0.1",
+ "@intlify/unplugin-vue-i18n": "^6.0.3",
+ "@rushstack/eslint-patch": "^1.10.5",
+ "@types/debug": "^4.1.12",
+ "@types/node": "^20.17.19",
+ "@unocss/preset-rem-to-px": "^0.64.1",
+ "@unocss/reset": "^0.64.1",
+ "@vitejs/plugin-vue": "^5.2.1",
+ "@vitejs/plugin-vue-jsx": "^4.1.1",
+ "@vue/eslint-config-prettier": "^9.0.0",
+ "@vue/eslint-config-typescript": "^13.0.0",
+ "@vueuse/core": "^12.7.0",
+ "debug": "^4.4.0",
+ "electron": "^31.7.7",
+ "electron-builder": "^24.13.3",
+ "electron-vite": "^2.3.0",
+ "eslint": "^8.57.1",
+ "eslint-plugin-vue": "^9.32.0",
+ "extract-zip": "^2.0.1",
+ "locales": "workspace:*",
+ "lodash-es": "^4.17.21",
+ "monaco-editor": "^0.52.2",
+ "prettier": "^3.5.1",
+ "rotating-file-stream": "^3.2.6",
+ "sass": "^1.85.0",
+ "simplebar-vue": "^2.4.0",
+ "typescript": "^5.7.3",
+ "unocss": "^0.64.1",
+ "unplugin-auto-import": "^19.1.0",
+ "unplugin-vue-components": "^28.4.0",
+ "unplugin-vue-macros": "^2.14.2",
+ "unplugin-vue-router": "^0.11.2",
+ "vite": "^5.4.14",
+ "vite-plugin-monaco-editor": "^1.1.0",
+ "vite-plugin-vue-layouts": "^0.11.0",
+ "vue": "^3.5.13",
+ "vue-i18n": "^11.1.1",
+ "vue-router": "^4.5.0",
+ "vue-tsc": "^2.1.10"
+ }
}
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 6de82ae..dee51e9 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -1,2 +1,2 @@
packages:
- - "packages/*"
+ - "packages/*"
diff --git a/resources/fuck.html b/resources/fuck.html
index 561543f..a101415 100644
--- a/resources/fuck.html
+++ b/resources/fuck.html
@@ -1,11 +1,12 @@
-
+
-
-
-
+
+
+
Document
-
-
- 前往 百度
-
+
+
+ 前往
+ 百度
+
diff --git a/src/common/_ioc.main.ts b/src/common/_ioc.main.ts
index 5efa038..076a82e 100644
--- a/src/common/_ioc.main.ts
+++ b/src/common/_ioc.main.ts
@@ -4,13 +4,13 @@ import PlatFormCommand from "common/event/PlatForm/main/command"
import TabsCommand from "common/event/Tabs/main/command"
const modules = new ContainerModule(bind => {
- bind("TabsCommand").to(TabsCommand).inSingletonScope()
- bind("PlatFormCommand").to(PlatFormCommand).inSingletonScope()
- bind("UpdateCommand").to(UpdateCommand).inSingletonScope()
+ bind("TabsCommand").to(TabsCommand).inSingletonScope()
+ bind("PlatFormCommand").to(PlatFormCommand).inSingletonScope()
+ bind("UpdateCommand").to(UpdateCommand).inSingletonScope()
})
async function destroyAllCommand(ioc: Container) {
- await ioc.unloadAsync(modules)
+ await ioc.unloadAsync(modules)
}
export { modules, destroyAllCommand }
diff --git a/src/common/event/PlatForm/index.ts b/src/common/event/PlatForm/index.ts
index 267076a..a94ba38 100644
--- a/src/common/event/PlatForm/index.ts
+++ b/src/common/event/PlatForm/index.ts
@@ -2,29 +2,29 @@ import { _Base } from "common/lib/_Base"
import { ApiFactory } from "common/lib/abstract"
class PlatForm extends _Base {
- constructor() {
- super()
- }
+ constructor() {
+ super()
+ }
- private get api() {
- return ApiFactory.getApiClient()
- }
+ private get api() {
+ return ApiFactory.getApiClient()
+ }
- async showAbout() {
- return this.api.call("BasicService.showAbout")
- }
+ async showAbout() {
+ return this.api.call("BasicService.showAbout")
+ }
- async isFullScreen() {
- return this.api.call("PlatFormCommand.isFullscreen")
- }
+ async isFullScreen() {
+ return this.api.call("PlatFormCommand.isFullscreen")
+ }
- async toggleFullScreen() {
- return this.api.call("PlatFormCommand.fullscreen")
- }
+ async toggleFullScreen() {
+ return this.api.call("PlatFormCommand.fullscreen")
+ }
- async toggleDevTools() {
- return this.api.call("PlatFormCommand.toggleDevTools")
- }
+ async toggleDevTools() {
+ return this.api.call("PlatFormCommand.toggleDevTools")
+ }
}
export { PlatForm }
diff --git a/src/common/event/PlatForm/main/command.ts b/src/common/event/PlatForm/main/command.ts
index 46f7670..1e0bfe5 100644
--- a/src/common/event/PlatForm/main/command.ts
+++ b/src/common/event/PlatForm/main/command.ts
@@ -4,78 +4,78 @@ import Tabs from "main/modules/tabs"
import WindowManager from "main/modules/window-manager"
export default class PlatFormCommand {
- constructor(
- @inject(WindowManager) private _WindowManager: WindowManager,
- @inject(Tabs) private _Tabs: Tabs,
- ) {}
+ constructor(
+ @inject(WindowManager) private _WindowManager: WindowManager,
+ @inject(Tabs) private _Tabs: Tabs,
+ ) {}
- setTheme(theme: typeof nativeTheme.themeSource) {
- nativeTheme.themeSource = theme
- }
+ setTheme(theme: typeof nativeTheme.themeSource) {
+ nativeTheme.themeSource = theme
+ }
- setTitlBar(options: TitleBarOverlayOptions) {
- const mainWindow = this._WindowManager.getMainWindow()
- if (mainWindow) {
- mainWindow.setTitleBarOverlay(options)
- }
+ setTitlBar(options: TitleBarOverlayOptions) {
+ const mainWindow = this._WindowManager.getMainWindow()
+ if (mainWindow) {
+ mainWindow.setTitleBarOverlay(options)
}
+ }
- showAbout() {
- this._WindowManager.showWindow("about")
- }
+ showAbout() {
+ this._WindowManager.showWindow("about")
+ }
- toggleDevTools() {
- const focusedWindow = this._WindowManager.getFocusWindow()
- if (focusedWindow) {
- // @ts-ignore ...
- focusedWindow.toggleDevTools()
- }
+ toggleDevTools() {
+ const focusedWindow = this._WindowManager.getFocusWindow()
+ if (focusedWindow) {
+ // @ts-ignore ...
+ focusedWindow.toggleDevTools()
}
- fullscreen() {
- const focusedWindow = this._WindowManager.getFocusWindow()
- if (focusedWindow) {
- const isFullScreen = focusedWindow!.isFullScreen()
- focusedWindow!.setFullScreen(!isFullScreen)
- }
+ }
+ fullscreen() {
+ const focusedWindow = this._WindowManager.getFocusWindow()
+ if (focusedWindow) {
+ const isFullScreen = focusedWindow!.isFullScreen()
+ focusedWindow!.setFullScreen(!isFullScreen)
}
+ }
- isFullscreen() {
- const focusedWindow = this._WindowManager.getFocusWindow()
- if (focusedWindow) {
- return focusedWindow!.isFullScreen()
- }
- return false
+ isFullscreen() {
+ const focusedWindow = this._WindowManager.getFocusWindow()
+ if (focusedWindow) {
+ return focusedWindow!.isFullScreen()
}
+ return false
+ }
- relunch() {
- app.relaunch()
- app.exit()
- }
+ relunch() {
+ app.relaunch()
+ app.exit()
+ }
- reload() {
- const focusedWindow = this._WindowManager.getFocusWindow()
- // 重载之后, 刷新并关闭所有的次要窗体
- if (this._WindowManager.length() > 1 && focusedWindow && focusedWindow.$$opts!.name === this._WindowManager.mainInfo.name) {
- const choice = dialog.showMessageBoxSync(focusedWindow, {
- type: "question",
- buttons: ["取消", "是的,继续", "不,算了"],
- title: "警告",
- defaultId: 2,
- cancelId: 0,
- message: "警告",
- detail: "重载主窗口将关闭所有子窗口,是否继续",
- })
- if (choice == 1) {
- this._WindowManager.getWndows().forEach(win => {
- if (win.$$opts!.name !== this._WindowManager.mainInfo.name) {
- win.close()
- }
- })
- } else {
- return
- }
- }
- this._Tabs.closeAll()
- focusedWindow!.reload()
+ reload() {
+ const focusedWindow = this._WindowManager.getFocusWindow()
+ // 重载之后, 刷新并关闭所有的次要窗体
+ if (this._WindowManager.length() > 1 && focusedWindow && focusedWindow.$$opts!.name === this._WindowManager.mainInfo.name) {
+ const choice = dialog.showMessageBoxSync(focusedWindow, {
+ type: "question",
+ buttons: ["取消", "是的,继续", "不,算了"],
+ title: "警告",
+ defaultId: 2,
+ cancelId: 0,
+ message: "警告",
+ detail: "重载主窗口将关闭所有子窗口,是否继续",
+ })
+ if (choice == 1) {
+ this._WindowManager.getWndows().forEach(win => {
+ if (win.$$opts!.name !== this._WindowManager.mainInfo.name) {
+ win.close()
+ }
+ })
+ } else {
+ return
+ }
}
+ this._Tabs.closeAll()
+ focusedWindow!.reload()
+ }
}
diff --git a/src/common/event/Tabs/index.ts b/src/common/event/Tabs/index.ts
index 5b8cd7c..f36ca59 100644
--- a/src/common/event/Tabs/index.ts
+++ b/src/common/event/Tabs/index.ts
@@ -1,54 +1,54 @@
import { _Base } from "../../lib/_Base"
export class Tabs extends _Base {
- constructor() {
- super()
- }
-
- private isListen: boolean = false
-
- private execUpdate = (...args) => {
- this.#fnList.forEach(v => v(...args))
- }
-
- #fnList: ((...args) => void)[] = []
- listenUpdate(cb: (...args) => void) {
- if (!this.isListen) {
- api.on("main:TabsCommand.update", this.execUpdate)
- this.isListen = true
- }
- this.#fnList.push(cb)
- }
-
- unListenUpdate(fn: (...args) => void) {
- this.#fnList = this.#fnList.filter(v => {
- return v !== fn
- })
- if (!this.#fnList.length) {
- api.off("main:TabsCommand.update", this.execUpdate)
- this.isListen = false
- }
- }
-
- bindPosition(data) {
- api.call("TabsCommand.bindElement", data)
- }
-
- closeAll() {
- api.call("TabsCommand.closeAll")
- }
-
- sync() {
- api.call("TabsCommand.sync")
- }
-
- unListenerAll() {
- this.#fnList = []
- api.offAll("main:TabsCommand.update")
- }
-
- async getAllTabs() {
- const res = await api.call("TabsCommand.getAllTabs")
- return res
- }
+ constructor() {
+ super()
+ }
+
+ private isListen: boolean = false
+
+ private execUpdate = (...args) => {
+ this.#fnList.forEach(v => v(...args))
+ }
+
+ #fnList: ((...args) => void)[] = []
+ listenUpdate(cb: (...args) => void) {
+ if (!this.isListen) {
+ api.on("main:TabsCommand.update", this.execUpdate)
+ this.isListen = true
+ }
+ this.#fnList.push(cb)
+ }
+
+ unListenUpdate(fn: (...args) => void) {
+ this.#fnList = this.#fnList.filter(v => {
+ return v !== fn
+ })
+ if (!this.#fnList.length) {
+ api.off("main:TabsCommand.update", this.execUpdate)
+ this.isListen = false
+ }
+ }
+
+ bindPosition(data) {
+ api.call("TabsCommand.bindElement", data)
+ }
+
+ closeAll() {
+ api.call("TabsCommand.closeAll")
+ }
+
+ sync() {
+ api.call("TabsCommand.sync")
+ }
+
+ unListenerAll() {
+ this.#fnList = []
+ api.offAll("main:TabsCommand.update")
+ }
+
+ async getAllTabs() {
+ const res = await api.call("TabsCommand.getAllTabs")
+ return res
+ }
}
diff --git a/src/common/event/Tabs/main/command.ts b/src/common/event/Tabs/main/command.ts
index 0619e17..0962cca 100644
--- a/src/common/event/Tabs/main/command.ts
+++ b/src/common/event/Tabs/main/command.ts
@@ -4,61 +4,61 @@ import WindowManager from "main/modules/window-manager"
import { broadcast } from "main/utils"
class TabsCommand {
- constructor(
- @inject(Tabs) private _Tabs: Tabs,
- @inject(WindowManager) private _WindowManager: WindowManager,
- ) {
- this._Tabs.events.on("update", this.listenerTabActive)
- }
+ constructor(
+ @inject(Tabs) private _Tabs: Tabs,
+ @inject(WindowManager) private _WindowManager: WindowManager,
+ ) {
+ this._Tabs.events.on("update", this.listenerTabActive)
+ }
- listenerTabActive = () => {
- broadcast("main:TabsCommand.update", this.getAllTabs())
- }
+ listenerTabActive = () => {
+ broadcast("main:TabsCommand.update", this.getAllTabs())
+ }
- bindElement(rect) {
- this._Tabs.updateRect(rect)
- }
+ bindElement(rect) {
+ this._Tabs.updateRect(rect)
+ }
- reload() {
- this._WindowManager.getMainWindow()?.reload()
- }
+ reload() {
+ this._WindowManager.getMainWindow()?.reload()
+ }
- sync() {
- this.listenerTabActive()
- if (!this.getAllTabs().length) {
- this.add("about:blank")
- }
+ sync() {
+ this.listenerTabActive()
+ if (!this.getAllTabs().length) {
+ this.add("about:blank")
}
+ }
- add(url) {
- this._Tabs.add(url, true, this._WindowManager.getMainWindow()!)
- }
+ add(url) {
+ this._Tabs.add(url, true, this._WindowManager.getMainWindow()!)
+ }
- nagivate(index: number, url: string) {
- this._Tabs.navigate(+index, url)
- }
+ nagivate(index: number, url: string) {
+ this._Tabs.navigate(+index, url)
+ }
- closeAll() {
- this._Tabs.closeAll()
- }
+ closeAll() {
+ this._Tabs.closeAll()
+ }
- setActive(index) {
- this._Tabs.changeActive(index)
- }
+ setActive(index) {
+ this._Tabs.changeActive(index)
+ }
- closeTab(e) {
- this._Tabs.remove(e.body.active)
- }
+ closeTab(e) {
+ this._Tabs.remove(e.body.active)
+ }
- getAllTabs() {
- return this._Tabs._tabs.map(v => ({
- url: v.url,
- showUrl: v.showUrl,
- title: v.title,
- favicons: v.favicons,
- isActive: v.isActive,
- }))
- }
+ getAllTabs() {
+ return this._Tabs._tabs.map(v => ({
+ url: v.url,
+ showUrl: v.showUrl,
+ title: v.title,
+ favicons: v.favicons,
+ isActive: v.isActive,
+ }))
+ }
}
export { TabsCommand }
diff --git a/src/common/event/update/index.ts b/src/common/event/update/index.ts
index 20f0ad3..55676c4 100644
--- a/src/common/event/update/index.ts
+++ b/src/common/event/update/index.ts
@@ -6,9 +6,9 @@ const curProgress = ref(0)
// })
function useUpdate() {
- return {
- curProgress,
- }
+ return {
+ curProgress,
+ }
}
export { useUpdate }
diff --git a/src/common/event/update/main/command.ts b/src/common/event/update/main/command.ts
index 5407dc3..069ece6 100644
--- a/src/common/event/update/main/command.ts
+++ b/src/common/event/update/main/command.ts
@@ -2,9 +2,9 @@ import { inject } from "inversify"
import Updater from "main/modules/updater"
export default class PlatFormCommand {
- constructor(@inject(Updater) private _Updater: Updater) {}
+ constructor(@inject(Updater) private _Updater: Updater) {}
- async triggerHotUpdate() {
- await this._Updater.triggerHotUpdate()
- }
+ async triggerHotUpdate() {
+ await this._Updater.triggerHotUpdate()
+ }
}
diff --git a/src/common/event/update/main/index.ts b/src/common/event/update/main/index.ts
index aa3132d..9aa935d 100644
--- a/src/common/event/update/main/index.ts
+++ b/src/common/event/update/main/index.ts
@@ -2,7 +2,7 @@ import { broadcast } from "main/utils"
import { AllKeys } from "common/event/common"
function emitHotUpdateReady(...argu) {
- broadcast("hot-update-ready", ...argu)
+ broadcast("hot-update-ready", ...argu)
}
export { emitHotUpdateReady }
diff --git a/src/common/lib/_Base.ts b/src/common/lib/_Base.ts
index 91d8f4b..1638ca1 100644
--- a/src/common/lib/_Base.ts
+++ b/src/common/lib/_Base.ts
@@ -1,12 +1,12 @@
export abstract class _Base {
- static instance
+ static instance
- static getInstance(): T {
- if (!this.instance) {
- // 如果实例不存在,则创建一个新的实例
- // @ts-ignore ...
- this.instance = new this()
- }
- return this.instance
+ static getInstance(): T {
+ if (!this.instance) {
+ // 如果实例不存在,则创建一个新的实例
+ // @ts-ignore ...
+ this.instance = new this()
}
+ return this.instance
+ }
}
diff --git a/src/common/lib/abstract.ts b/src/common/lib/abstract.ts
index 9712b8a..0a025d9 100644
--- a/src/common/lib/abstract.ts
+++ b/src/common/lib/abstract.ts
@@ -3,51 +3,51 @@ import { BrowserApiClient } from "common/lib/browser"
// 定义抽象 API 接口
export interface IApiClient {
- call(command: string, ...args: any[]): Promise
- on(channel: K, callback: (...args: any[]) => void): void
- off(channel: K, callback: (...args: any[]) => void): void
- offAll(channel: K): void
+ call(command: string, ...args: any[]): Promise
+ on(channel: K, callback: (...args: any[]) => void): void
+ off(channel: K, callback: (...args: any[]) => void): void
+ offAll(channel: K): void
}
class NullApiClient implements IApiClient {
- async call(command: string, ...args: any[]): Promise {
- args
- console.warn(`API call to ${command} failed: API client not initialized`)
- return undefined as any
- }
-
- on(channel: K, callback: (...args: any[]) => void): void {
- callback
- console.warn(`Failed to register listener for ${channel}: API client not initialized`)
- }
-
- off(channel: K, callback: (...args: any[]) => void): void {
- callback
- console.warn(`Failed to unregister listener for ${channel}: API client not initialized`)
- }
-
- offAll(channel: K): void {
- console.warn(`Failed to unregister all listeners for ${channel}: API client not initialized`)
- }
+ async call(command: string, ...args: any[]): Promise {
+ args
+ console.warn(`API call to ${command} failed: API client not initialized`)
+ return undefined as any
+ }
+
+ on(channel: K, callback: (...args: any[]) => void): void {
+ callback
+ console.warn(`Failed to register listener for ${channel}: API client not initialized`)
+ }
+
+ off(channel: K, callback: (...args: any[]) => void): void {
+ callback
+ console.warn(`Failed to unregister listener for ${channel}: API client not initialized`)
+ }
+
+ offAll(channel: K): void {
+ console.warn(`Failed to unregister all listeners for ${channel}: API client not initialized`)
+ }
}
// 创建 API 工厂
export class ApiFactory {
- private static instance: IApiClient = new NullApiClient() // 默认使用空实现
-
- static setApiClient(client: IApiClient) {
- this.instance = client
- }
-
- static getApiClient(): IApiClient {
- if (this.instance instanceof NullApiClient) {
- // 根据环境选择合适的 API 客户端
- if (window.api && window.electron) {
- this.instance = new ElectronApiClient()
- } else {
- this.instance = new BrowserApiClient()
- }
- }
- return this.instance
+ private static instance: IApiClient = new NullApiClient() // 默认使用空实现
+
+ static setApiClient(client: IApiClient) {
+ this.instance = client
+ }
+
+ static getApiClient(): IApiClient {
+ if (this.instance instanceof NullApiClient) {
+ // 根据环境选择合适的 API 客户端
+ if (window.api && window.electron) {
+ this.instance = new ElectronApiClient()
+ } else {
+ this.instance = new BrowserApiClient()
+ }
}
+ return this.instance
+ }
}
diff --git a/src/common/lib/browser.ts b/src/common/lib/browser.ts
index 100e60d..e80a478 100644
--- a/src/common/lib/browser.ts
+++ b/src/common/lib/browser.ts
@@ -1,29 +1,29 @@
import { IApiClient } from "./abstract"
export class BrowserApiClient implements IApiClient {
- call(command: string, ...args: any[]): Promise {
- // 浏览器特定实现,可能使用 fetch 或其他方式
- const [service, method] = command.split(".")
- return fetch(`/api/${service}/${method}`, {
- method: "POST",
- body: JSON.stringify(args),
- headers: { "Content-Type": "application/json" },
- }).then(res => res.json())
- }
+ call(command: string, ...args: any[]): Promise {
+ // 浏览器特定实现,可能使用 fetch 或其他方式
+ const [service, method] = command.split(".")
+ return fetch(`/api/${service}/${method}`, {
+ method: "POST",
+ body: JSON.stringify(args),
+ headers: { "Content-Type": "application/json" },
+ }).then(res => res.json())
+ }
- // 实现其他方法...
- on(channel: K, callback: (...args: any[]) => void): void {
- // 浏览器中可能使用 WebSocket 或其他方式
- console.log("不支持 on 方法", channel, callback)
- }
+ // 实现其他方法...
+ on(channel: K, callback: (...args: any[]) => void): void {
+ // 浏览器中可能使用 WebSocket 或其他方式
+ console.log("不支持 on 方法", channel, callback)
+ }
- off(channel: K, callback: (...args: any[]) => void): void {
- // 相应的解绑实现
- console.log("不支持 on 方法", channel, callback)
- }
+ off(channel: K, callback: (...args: any[]) => void): void {
+ // 相应的解绑实现
+ console.log("不支持 on 方法", channel, callback)
+ }
- offAll(channel: K): void {
- // 相应的全部解绑实现
- console.log("不支持 on 方法", channel)
- }
+ offAll(channel: K): void {
+ // 相应的全部解绑实现
+ console.log("不支持 on 方法", channel)
+ }
}
diff --git a/src/common/lib/electron.ts b/src/common/lib/electron.ts
index 27908a5..43da684 100644
--- a/src/common/lib/electron.ts
+++ b/src/common/lib/electron.ts
@@ -1,20 +1,20 @@
import { IApiClient } from "./abstract"
export class ElectronApiClient implements IApiClient {
- call(command: string, ...args: any[]): Promise {
- // Electron 特定实现
- return window.api.call(command, ...args)
- }
+ call(command: string, ...args: any[]): Promise {
+ // Electron 特定实现
+ return window.api.call(command, ...args)
+ }
- on(channel: K, callback: (...args: any[]) => void): void {
- window.api.on(channel, callback)
- }
+ on(channel: K, callback: (...args: any[]) => void): void {
+ window.api.on(channel, callback)
+ }
- off(channel: K, callback: (...args: any[]) => void): void {
- window.api.off(channel, callback)
- }
+ off(channel: K, callback: (...args: any[]) => void): void {
+ window.api.off(channel, callback)
+ }
- offAll(channel: K): void {
- window.api.offAll(channel)
- }
+ offAll(channel: K): void {
+ window.api.offAll(channel)
+ }
}
diff --git a/src/common/usePlatform.ts b/src/common/usePlatform.ts
index 1316845..85f70ea 100644
--- a/src/common/usePlatform.ts
+++ b/src/common/usePlatform.ts
@@ -2,8 +2,8 @@ import { PlatForm } from "./event/PlatForm"
import { Tabs } from "./event/Tabs"
export function usePlatForm() {
- return {
- Tabs: Tabs.getInstance(),
- PlatForm: PlatForm.getInstance(),
- }
+ return {
+ Tabs: Tabs.getInstance(),
+ PlatForm: PlatForm.getInstance(),
+ }
}
diff --git a/src/main/App copy.ts b/src/main/App copy.ts
index 9d0584c..220ca22 100644
--- a/src/main/App copy.ts
+++ b/src/main/App copy.ts
@@ -10,155 +10,155 @@ import { getFileUrl } from "./utils"
import BaseClass from "./base/base"
protocol.registerSchemesAsPrivileged([
- // {
- // scheme: "http",
- // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
- // },
- // {
- // scheme: "https",
- // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
- // },
- // { scheme: "mailto", privileges: { standard: true } },
- {
- scheme: "api",
- privileges: {
- standard: true,
- secure: true,
- supportFetchAPI: true,
- },
+ // {
+ // scheme: "http",
+ // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
+ // },
+ // {
+ // scheme: "https",
+ // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
+ // },
+ // { scheme: "mailto", privileges: { standard: true } },
+ {
+ scheme: "api",
+ privileges: {
+ standard: true,
+ secure: true,
+ supportFetchAPI: true,
},
+ },
])
@injectable()
class App extends BaseClass {
- destroy() {
- // destroyAll()
- // 这里是应用正常退出
- }
- // private _setting: Setting
- // private _db: DB
- private _Api: Api
- private _windowManager: WindowManager
- // private _tabs: Tabs
+ destroy() {
+ // destroyAll()
+ // 这里是应用正常退出
+ }
+ // private _setting: Setting
+ // private _db: DB
+ private _Api: Api
+ private _windowManager: WindowManager
+ // private _tabs: Tabs
- constructor(
- // @inject(Setting) setting: Setting,
- // @inject(DB) db: DB,
- @inject(Api) Api: Api,
- @inject(WindowManager) windowManager: WindowManager,
- // @inject(Tabs) tabs: Tabs,
- ) {
- super()
- // this._setting = setting
- // this._db = db
- this._Api = Api
- this._windowManager = windowManager
- // this._tabs = tabs
- }
+ constructor(
+ // @inject(Setting) setting: Setting,
+ // @inject(DB) db: DB,
+ @inject(Api) Api: Api,
+ @inject(WindowManager) windowManager: WindowManager,
+ // @inject(Tabs) tabs: Tabs,
+ ) {
+ super()
+ // this._setting = setting
+ // this._db = db
+ this._Api = Api
+ this._windowManager = windowManager
+ // this._tabs = tabs
+ }
- async init() {
- this._windowManager.init()
- app.whenReady().then(() => {
- electronApp.setAppUserModelId("top.xieyaxin")
- this.create()
- this._Api.init()
- })
- app.on("window-all-closed", () => {
- if (process.platform !== "darwin") {
- app.quit()
- }
- })
- app.on("will-quit", () => {
- this.destroy()
- })
- }
+ async init() {
+ this._windowManager.init()
+ app.whenReady().then(() => {
+ electronApp.setAppUserModelId("top.xieyaxin")
+ this.create()
+ this._Api.init()
+ })
+ app.on("window-all-closed", () => {
+ if (process.platform !== "darwin") {
+ app.quit()
+ }
+ })
+ app.on("will-quit", () => {
+ this.destroy()
+ })
+ }
- create() {
- this._windowManager.showMainWindow()
- const mainWindow = this._windowManager.getMainWindow()
- if (mainWindow) {
- nativeTheme.themeSource = "light"
- mainWindow.setTitleBarOverlay({
- height: 29, // the smallest size of the title bar on windows accounting for the border on windows 11
- color: "#F8F8F8",
- symbolColor: "#000000",
- })
- this._windowManager.showWindow("main-top")
- const mainTopWindow = this._windowManager.get("main-top")
- setTimeout(() => {
- // console.log(mainWindow.getParentWindow());
- setTimeout(() => {
- mainWindow.contentView.children.length = 0
- const view = new WebContentsView()
- view.addChildView(mainTopWindow!.contentView)
- view.webContents.loadURL(getFileUrl("about.html"))
- // mainTopWindow!.contentView.setBounds({ x: 0, y: 0, width: 100, height: 30 })
- // view.setBounds({ x: 0, y: 0, width: 100, height: 30 })
- mainWindow.contentView.addChildView(view)
- // mainWindow.contentView.children.sort()
- console.log(mainWindow.contentView.children)
- }, 5000)
- // mainWindow.webContents = mainTopWindow!.webContents
- mainWindow.reload()
- console.log(mainWindow.webContents.getURL())
+ create() {
+ this._windowManager.showMainWindow()
+ const mainWindow = this._windowManager.getMainWindow()
+ if (mainWindow) {
+ nativeTheme.themeSource = "light"
+ mainWindow.setTitleBarOverlay({
+ height: 29, // the smallest size of the title bar on windows accounting for the border on windows 11
+ color: "#F8F8F8",
+ symbolColor: "#000000",
+ })
+ this._windowManager.showWindow("main-top")
+ const mainTopWindow = this._windowManager.get("main-top")
+ setTimeout(() => {
+ // console.log(mainWindow.getParentWindow());
+ setTimeout(() => {
+ mainWindow.contentView.children.length = 0
+ const view = new WebContentsView()
+ view.addChildView(mainTopWindow!.contentView)
+ view.webContents.loadURL(getFileUrl("about.html"))
+ // mainTopWindow!.contentView.setBounds({ x: 0, y: 0, width: 100, height: 30 })
+ // view.setBounds({ x: 0, y: 0, width: 100, height: 30 })
+ mainWindow.contentView.addChildView(view)
+ // mainWindow.contentView.children.sort()
+ console.log(mainWindow.contentView.children)
+ }, 5000)
+ // mainWindow.webContents = mainTopWindow!.webContents
+ mainWindow.reload()
+ console.log(mainWindow.webContents.getURL())
- // mainTopWindow?.destroy()
- // mainWindow.contentView.addChildView(mainWindow.contentView)
- console.log(`child count: `, mainWindow.contentView.children.length)
- }, 2000)
- // if (mainTopWindow) {
- // mainTopWindow.setParentWindow(mainWindow)
- // mainTopWindow.setIgnoreMouseEvents(true, { forward: false })
- // const listenMove = () => {
- // if (mainWindow && mainTopWindow) {
- // const pos = mainWindow.getPosition()
- // mainTopWindow.setPosition(pos[0], pos[1])
- // }
- // }
- // mainWindow?.on("move", listenMove)
- // const listenResize = () => {
- // if (mainWindow && mainTopWindow) {
- // const size = mainWindow.getSize()
- // console.log(size)
- // mainTopWindow.setSize(size[0], size[1])
- // const pos = mainWindow.getPosition()
- // mainTopWindow.setPosition(pos[0], pos[1])
- // }
- // }
- // listenResize()
- // mainWindow?.on("resize", listenResize)
- // }
- }
- // 考虑双browserwindow模式
- /**
- * 因为browserwindow可以设置穿透,考虑将tab放在底层window上,其他组件放在上层window上。
- */
- // const webContentsView = new WebContentsView({
- // webPreferences: {
- // preload: join(__dirname, "../preload/index.mjs"),
- // transparent: true,
- // nodeIntegration: true,
- // spellcheck: false,
- // contextIsolation: true,
- // },
- // })
- // // mainWindow!.contentView = webContentsView
- // // setTimeout(() => {
- // mainWindow!.contentView.addChildView(webContentsView)
- // // mainWindow?.setIgnoreMouseEvents(true, { forward: true })
- // // }, 2000);
- // webContentsView.webContents.loadURL(getFileUrl("index.html"))
- // const listenResize = () => {
- // const size = mainWindow!.getSize()
- // webContentsView.setBounds({ x: 0, y: 0, width: size[0], height: size[1] })
- // }
- // listenResize()
- // mainWindow!.addListener("resize", listenResize)
-
- // this._tabs.add("https://baidu.com", true)
- // this._tabs.add("https://zhihu.com")
- return mainWindow
+ // mainTopWindow?.destroy()
+ // mainWindow.contentView.addChildView(mainWindow.contentView)
+ console.log(`child count: `, mainWindow.contentView.children.length)
+ }, 2000)
+ // if (mainTopWindow) {
+ // mainTopWindow.setParentWindow(mainWindow)
+ // mainTopWindow.setIgnoreMouseEvents(true, { forward: false })
+ // const listenMove = () => {
+ // if (mainWindow && mainTopWindow) {
+ // const pos = mainWindow.getPosition()
+ // mainTopWindow.setPosition(pos[0], pos[1])
+ // }
+ // }
+ // mainWindow?.on("move", listenMove)
+ // const listenResize = () => {
+ // if (mainWindow && mainTopWindow) {
+ // const size = mainWindow.getSize()
+ // console.log(size)
+ // mainTopWindow.setSize(size[0], size[1])
+ // const pos = mainWindow.getPosition()
+ // mainTopWindow.setPosition(pos[0], pos[1])
+ // }
+ // }
+ // listenResize()
+ // mainWindow?.on("resize", listenResize)
+ // }
}
+ // 考虑双browserwindow模式
+ /**
+ * 因为browserwindow可以设置穿透,考虑将tab放在底层window上,其他组件放在上层window上。
+ */
+ // const webContentsView = new WebContentsView({
+ // webPreferences: {
+ // preload: join(__dirname, "../preload/index.mjs"),
+ // transparent: true,
+ // nodeIntegration: true,
+ // spellcheck: false,
+ // contextIsolation: true,
+ // },
+ // })
+ // // mainWindow!.contentView = webContentsView
+ // // setTimeout(() => {
+ // mainWindow!.contentView.addChildView(webContentsView)
+ // // mainWindow?.setIgnoreMouseEvents(true, { forward: true })
+ // // }, 2000);
+ // webContentsView.webContents.loadURL(getFileUrl("index.html"))
+ // const listenResize = () => {
+ // const size = mainWindow!.getSize()
+ // webContentsView.setBounds({ x: 0, y: 0, width: size[0], height: size[1] })
+ // }
+ // listenResize()
+ // mainWindow!.addListener("resize", listenResize)
+
+ // this._tabs.add("https://baidu.com", true)
+ // this._tabs.add("https://zhihu.com")
+ return mainWindow
+ }
}
export default App
diff --git a/src/main/App.ts b/src/main/App.ts
index b440f86..e87ba17 100644
--- a/src/main/App.ts
+++ b/src/main/App.ts
@@ -13,74 +13,74 @@ import Zephyr from "./modules/zephyr"
import Updater from "./modules/updater"
protocol.registerSchemesAsPrivileged([
- // {
- // scheme: "http",
- // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
- // },
- // {
- // scheme: "https",
- // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
- // },
- // { scheme: "mailto", privileges: { standard: true } },
- {
- scheme: "api",
- privileges: {
- standard: true,
- secure: true,
- supportFetchAPI: true,
- },
+ // {
+ // scheme: "http",
+ // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
+ // },
+ // {
+ // scheme: "https",
+ // privileges: { standard: true, bypassCSP: true, allowServiceWorkers: true, supportFetchAPI: true, corsEnabled: true, stream: true },
+ // },
+ // { scheme: "mailto", privileges: { standard: true } },
+ {
+ scheme: "api",
+ privileges: {
+ standard: true,
+ secure: true,
+ supportFetchAPI: true,
},
- {
- scheme: "zephyr",
- privileges: {
- standard: true,
- secure: true,
- supportFetchAPI: true,
- },
+ },
+ {
+ scheme: "zephyr",
+ privileges: {
+ standard: true,
+ secure: true,
+ supportFetchAPI: true,
},
+ },
])
@injectable()
class App extends BaseClass {
- destroy() {
- this._IOC.destroy()
- // 这里是应用正常退出, 可以检测应用是不是非正常退出,比如应用启动时记录一个启动时间并删除上一次结束时间和开始时间,结束时记录一个结束时间,
- // 如果存在结束时间或者不存在开始时间则为正常启动
- }
+ destroy() {
+ this._IOC.destroy()
+ // 这里是应用正常退出, 可以检测应用是不是非正常退出,比如应用启动时记录一个启动时间并删除上一次结束时间和开始时间,结束时记录一个结束时间,
+ // 如果存在结束时间或者不存在开始时间则为正常启动
+ }
- constructor(
- @inject(IOC) private _IOC: IOC,
- @inject(Api) private _Api: Api,
- @inject(Command) private _Command: Command,
- @inject(DB) private _DB: DB,
- @inject(WindowManager) private _WindowManager: WindowManager,
- @inject(Zephyr) private _Zephyr: Zephyr,
- @inject(Updater) private _Updater: Updater,
- ) {
- super()
- }
+ constructor(
+ @inject(IOC) private _IOC: IOC,
+ @inject(Api) private _Api: Api,
+ @inject(Command) private _Command: Command,
+ @inject(DB) private _DB: DB,
+ @inject(WindowManager) private _WindowManager: WindowManager,
+ @inject(Zephyr) private _Zephyr: Zephyr,
+ @inject(Updater) private _Updater: Updater,
+ ) {
+ super()
+ }
- async init() {
- this._Updater.init()
- this._DB.init()
- this._Command.init()
- this._WindowManager.init()
- app.whenReady().then(() => {
- this._Api.init()
- this._Zephyr.init()
- electronApp.setAppUserModelId("top.xieyaxin")
- this._WindowManager.showMainWindow()
- this._Command.invoke("PlatFormCommand.setTheme", "light")
- this._Command.invoke("PlatFormCommand.setTitlBar", {
- height: 29,
- color: "#F8F8F8",
- symbolColor: "#000000",
- })
- })
- app.on("will-quit", () => {
- this.destroy()
- })
- }
+ async init() {
+ this._Updater.init()
+ this._DB.init()
+ this._Command.init()
+ this._WindowManager.init()
+ app.whenReady().then(() => {
+ this._Api.init()
+ this._Zephyr.init()
+ electronApp.setAppUserModelId("top.xieyaxin")
+ this._WindowManager.showMainWindow()
+ this._Command.invoke("PlatFormCommand.setTheme", "light")
+ this._Command.invoke("PlatFormCommand.setTitlBar", {
+ height: 29,
+ color: "#F8F8F8",
+ symbolColor: "#000000",
+ })
+ })
+ app.on("will-quit", () => {
+ this.destroy()
+ })
+ }
}
export default App
diff --git a/src/main/_ioc.ts b/src/main/_ioc.ts
index 7613d44..fa0689e 100644
--- a/src/main/_ioc.ts
+++ b/src/main/_ioc.ts
@@ -6,9 +6,9 @@ import iocCommand, { destroyAllCommand } from "common/_ioc.main"
import App from "./App"
async function destroyAll() {
- await destroyAllModules(_ioc)
- await destroyAllController(_ioc)
- await destroyAllCommand(_ioc)
+ await destroyAllModules(_ioc)
+ await destroyAllController(_ioc)
+ await destroyAllCommand(_ioc)
}
const _ioc = new Container()
diff --git a/src/main/_iocClass.ts b/src/main/_iocClass.ts
index 74d1bd9..9bec22a 100644
--- a/src/main/_iocClass.ts
+++ b/src/main/_iocClass.ts
@@ -3,21 +3,21 @@ import BaseClass from "./base/base"
import { destroyAll, _ioc } from "./_ioc"
class IOC extends BaseClass {
- init() {
- // TODO
- }
+ init() {
+ // TODO
+ }
- destroy() {
- destroyAll()
- }
+ destroy() {
+ destroyAll()
+ }
- get(serviceIdentifier: interfaces.ServiceIdentifier) {
- return _ioc.get(serviceIdentifier)
- }
+ get(serviceIdentifier: interfaces.ServiceIdentifier) {
+ return _ioc.get(serviceIdentifier)
+ }
- getAsync(serviceIdentifier: interfaces.ServiceIdentifier) {
- return _ioc.getAsync(serviceIdentifier)
- }
+ getAsync(serviceIdentifier: interfaces.ServiceIdentifier) {
+ return _ioc.getAsync(serviceIdentifier)
+ }
}
export { IOC }
diff --git a/src/main/base/base.ts b/src/main/base/base.ts
index 0976ae4..5305a52 100644
--- a/src/main/base/base.ts
+++ b/src/main/base/base.ts
@@ -1,9 +1,9 @@
import EventEmitter from "node:events"
abstract class BaseClass {
- public _events = new EventEmitter()
- abstract init(...argus: any[])
- abstract destroy()
+ public _events = new EventEmitter()
+ abstract init(...argus: any[])
+ abstract destroy()
}
export { BaseClass }
diff --git a/src/main/controller/BasicService.ts b/src/main/controller/BasicService.ts
index 6c4482c..3668256 100644
--- a/src/main/controller/BasicService.ts
+++ b/src/main/controller/BasicService.ts
@@ -5,24 +5,24 @@ import WindowManager from "main/modules/window-manager"
@injectable()
class BasicService extends BaseContainer {
- constructor(
- @inject(WindowManager) private _WindowManager: WindowManager,
- @inject(Tabs) private _Tabs: Tabs,
- ) {
- super()
- }
+ constructor(
+ @inject(WindowManager) private _WindowManager: WindowManager,
+ @inject(Tabs) private _Tabs: Tabs,
+ ) {
+ super()
+ }
- showAbout() {
- this._WindowManager.showWindow("about")
- return {
- a: "fuck",
- }
+ showAbout() {
+ this._WindowManager.showWindow("about")
+ return {
+ a: "fuck",
}
+ }
- openTabDevtool() {
- // this._Tabs.reload(0)
- this._Tabs.openDevtool(0)
- }
+ openTabDevtool() {
+ // this._Tabs.reload(0)
+ this._Tabs.openDevtool(0)
+ }
}
export { BasicService }
diff --git a/src/main/controller/TabsService.ts b/src/main/controller/TabsService.ts
index fb8b0a2..3d8538d 100644
--- a/src/main/controller/TabsService.ts
+++ b/src/main/controller/TabsService.ts
@@ -5,38 +5,38 @@ import WindowManager from "main/modules/window-manager"
@injectable()
class TabsService extends BaseContainer {
- constructor(
- @inject(Tabs) private _Tabs: Tabs,
- @inject(WindowManager) private _WindowManager: WindowManager,
- ) {
- super()
- }
+ constructor(
+ @inject(Tabs) private _Tabs: Tabs,
+ @inject(WindowManager) private _WindowManager: WindowManager,
+ ) {
+ super()
+ }
- add(e) {
- this._Tabs.add(e.body.url, true, this._WindowManager.getMainWindow()!)
- }
+ add(e) {
+ this._Tabs.add(e.body.url, true, this._WindowManager.getMainWindow()!)
+ }
- setActive(e) {
- this._Tabs.changeActive(e.body.active)
- }
+ setActive(e) {
+ this._Tabs.changeActive(e.body.active)
+ }
- closeTab(e) {
- this._Tabs.remove(e.body.active)
- }
+ closeTab(e) {
+ this._Tabs.remove(e.body.active)
+ }
- closeTabAll(e) {
- this._Tabs.removeAll(e.body.active)
- }
+ closeTabAll(e) {
+ this._Tabs.removeAll(e.body.active)
+ }
- getAllTabs() {
- return this._Tabs._tabs.map(v => ({
- url: v.url,
- showUrl: v.showUrl,
- title: v.title,
- favicons: v.favicons,
- isActive: v.isActive,
- }))
- }
+ getAllTabs() {
+ return this._Tabs._tabs.map(v => ({
+ url: v.url,
+ showUrl: v.showUrl,
+ title: v.title,
+ favicons: v.favicons,
+ isActive: v.isActive,
+ }))
+ }
}
export { TabsService }
diff --git a/src/main/controller/_ioc.ts b/src/main/controller/_ioc.ts
index c1f6e51..f568ca2 100644
--- a/src/main/controller/_ioc.ts
+++ b/src/main/controller/_ioc.ts
@@ -3,12 +3,12 @@ import BasicService from "./BasicService"
import TabsService from "./TabsService"
const modules = new ContainerModule(bind => {
- bind("BasicService").to(BasicService).inSingletonScope()
- bind("TabsService").to(TabsService).inSingletonScope()
+ bind("BasicService").to(BasicService).inSingletonScope()
+ bind("TabsService").to(TabsService).inSingletonScope()
})
async function destroyAllController(ioc: Container) {
- await ioc.unloadAsync(modules)
+ await ioc.unloadAsync(modules)
}
export { modules, destroyAllController }
diff --git a/src/main/index.ts b/src/main/index.ts
index 8c09dd0..b61912c 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -19,56 +19,56 @@ const streams = new Map()
// 转换命名空间为安全路径
function sanitizeNamespace(namespace) {
- return namespace
- .split(":") // 按层级分隔符拆分
- .map(part => part.replace(/[\\/:*?"<>|]/g, "_")) // 替换非法字符
- .join(path.sep) // 拼接为系统路径分隔符(如 / 或 \)
+ return namespace
+ .split(":") // 按层级分隔符拆分
+ .map(part => part.replace(/[\\/:*?"<>|]/g, "_")) // 替换非法字符
+ .join(path.sep) // 拼接为系统路径分隔符(如 / 或 \)
}
// 覆盖 debug.log 方法
const originalLog = debug.log
debug.log = function (...args) {
- // 保留原始控制台输出(可选)
- originalLog.apply(this, args)
- // 获取当前命名空间
- // @ts-ignore ...
- const namespace = this.namespace
- if (!namespace) {
- // TODO 增加容错机制,如果没有命名空间就输出到一个默认文件中
- return
- }
+ // 保留原始控制台输出(可选)
+ originalLog.apply(this, args)
+ // 获取当前命名空间
+ // @ts-ignore ...
+ const namespace = this.namespace
+ if (!namespace) {
+ // TODO 增加容错机制,如果没有命名空间就输出到一个默认文件中
+ return
+ }
- // 生成日志文件路径(示例:logs/app/server.log)
- const sanitizedPath = sanitizeNamespace(namespace)
- // const logFilePath = path.join(LOG_ROOT, `${sanitizedPath}.log`)
+ // 生成日志文件路径(示例:logs/app/server.log)
+ const sanitizedPath = sanitizeNamespace(namespace)
+ // const logFilePath = path.join(LOG_ROOT, `${sanitizedPath}.log`)
- const today = new Date().toISOString().split("T")[0]
- const logFilePath = path.join(LOG_ROOT, sanitizedPath, `${today}.log`)
+ const today = new Date().toISOString().split("T")[0]
+ const logFilePath = path.join(LOG_ROOT, sanitizedPath, `${today}.log`)
- // 确保目录存在
- const dir = path.dirname(logFilePath)
- if (!fs.existsSync(dir)) {
- fs.mkdirSync(dir, { recursive: true }) // 自动创建多级目录
- }
+ // 确保目录存在
+ const dir = path.dirname(logFilePath)
+ if (!fs.existsSync(dir)) {
+ fs.mkdirSync(dir, { recursive: true }) // 自动创建多级目录
+ }
- // 获取或创建文件流
- let stream = streams.get(logFilePath)
- if (!stream) {
- // stream = fs.createWriteStream(logFilePath, { flags: "a" }) // 追加模式
- stream = rfs.createStream(path.parse(logFilePath).base, {
- path: dir,
- size: "10M", // 单个文件最大 10MB
- rotate: 5, // 保留最近 5 个文件
- })
- streams.set(logFilePath, stream)
- }
+ // 获取或创建文件流
+ let stream = streams.get(logFilePath)
+ if (!stream) {
+ // stream = fs.createWriteStream(logFilePath, { flags: "a" }) // 追加模式
+ stream = rfs.createStream(path.parse(logFilePath).base, {
+ path: dir,
+ size: "10M", // 单个文件最大 10MB
+ rotate: 5, // 保留最近 5 个文件
+ })
+ streams.set(logFilePath, stream)
+ }
- // 写入日志(添加时间戳)
- const message = args.join(" ")
- stream.write(`${message}\n`)
+ // 写入日志(添加时间戳)
+ const message = args.join(" ")
+ stream.write(`${message}\n`)
- // const timestamp = new Date().toISOString()
- // stream.write(`[${timestamp}] ${message}\n`)
+ // const timestamp = new Date().toISOString()
+ // stream.write(`[${timestamp}] ${message}\n`)
}
const curApp = _ioc.get(App)
@@ -76,10 +76,10 @@ curApp.init()
const _debug = debug("app:app")
app.on("before-quit", () => {
- _debug("应用关闭")
- streams.forEach(stream => {
- stream.end()
- stream.destroy()
- })
- streams.clear()
+ _debug("应用关闭")
+ streams.forEach(stream => {
+ stream.end()
+ stream.destroy()
+ })
+ streams.clear()
})
diff --git a/src/main/modules/_ioc.ts b/src/main/modules/_ioc.ts
index 7196178..c9ade3e 100644
--- a/src/main/modules/_ioc.ts
+++ b/src/main/modules/_ioc.ts
@@ -9,28 +9,28 @@ import Zephyr from "./zephyr"
import Updater from "./updater"
const modules = new ContainerModule(bind => {
- bind(Setting).toConstantValue(new Setting())
- bind(Zephyr).toSelf().inSingletonScope()
- bind(Updater).toSelf().inSingletonScope()
- bind(Api).toSelf().inSingletonScope()
- bind(WindowManager).toSelf().inSingletonScope()
- bind(Commands).toSelf().inSingletonScope()
- bind(Tabs).toSelf().inSingletonScope()
- bind(DB).toSelf().inSingletonScope()
+ bind(Setting).toConstantValue(new Setting())
+ bind(Zephyr).toSelf().inSingletonScope()
+ bind(Updater).toSelf().inSingletonScope()
+ bind(Api).toSelf().inSingletonScope()
+ bind(WindowManager).toSelf().inSingletonScope()
+ bind(Commands).toSelf().inSingletonScope()
+ bind(Tabs).toSelf().inSingletonScope()
+ bind(DB).toSelf().inSingletonScope()
})
async function destroyAllModules(ioc: Container) {
- await Promise.all([
- ioc.get(Setting).destroy(),
- ioc.get(WindowManager).destroy(),
- ioc.get(Commands).destroy(),
- ioc.get(Updater).destroy(),
- ioc.get(Zephyr).destroy(),
- ioc.get(Tabs).destroy(),
- ioc.get(Api).destroy(),
- ioc.get(DB).destroy(),
- ])
- ioc.unloadAsync(modules)
+ await Promise.all([
+ ioc.get(Setting).destroy(),
+ ioc.get(WindowManager).destroy(),
+ ioc.get(Commands).destroy(),
+ ioc.get(Updater).destroy(),
+ ioc.get(Zephyr).destroy(),
+ ioc.get(Tabs).destroy(),
+ ioc.get(Api).destroy(),
+ ioc.get(DB).destroy(),
+ ])
+ ioc.unloadAsync(modules)
}
export default modules
diff --git a/src/main/modules/api/index.ts b/src/main/modules/api/index.ts
index 6abe99e..a047f12 100644
--- a/src/main/modules/api/index.ts
+++ b/src/main/modules/api/index.ts
@@ -5,85 +5,85 @@ import BaseClass from "main/base/base"
@injectable()
class Api extends BaseClass {
- constructor(@inject(IOC) private _IOC: IOC) {
- super()
- this.interceptHandler = this.interceptHandler.bind(this)
- }
+ constructor(@inject(IOC) private _IOC: IOC) {
+ super()
+ this.interceptHandler = this.interceptHandler.bind(this)
+ }
- destroy() {
- // TODO
- }
- init(partition?: string) {
- // const ses = partition ? session.fromPartition(partition) : session.defaultSession
- const ses = partition ? session.fromPartition(partition) : session.defaultSession
- ses.protocol.handle("api", this.interceptHandler)
- }
- async interceptHandler(request: Request) {
- if (request.url.startsWith("api://fuck/")) {
- let curUrl = request.url
- const isScriteText = curUrl.endsWith("?script")
- if (isScriteText) {
- curUrl = curUrl.replace("?script", "")
- }
- const isPost = request.method.toLowerCase() === "post"
- const file = curUrl.replace("api://fuck/", "")
- const array = file.split("/")
- const routePath = array.slice(0, -1).join("/")
- const fnName = array[array.length - 1]
- // https://vitejs.cn/vite5-cn/guide/features.html#dynamic-import
- const module = await this._IOC.getAsync(routePath)
- // const module = await import(`main/controller/${routePath}.ts`)
- const opts = { body: {}, query: {} }
- if (isPost) {
- opts.body = await request.json()
- }
- const headers: HeadersInit = {}
- if (isScriteText) {
- headers["content-type"] = "text/javascript"
- }
- if (isPost) {
- headers["content-type"] = "application/json"
- }
- if (module && module[fnName]) {
- if (typeof module[fnName] === "string") {
- const result = module[fnName]
- return new Response(result, {
- status: 200,
- headers: Object.keys(headers).length ? headers : undefined,
- })
- }
- if (typeof module[fnName] === "function") {
- let result = await module[fnName](opts)
- if (typeof result === "object") {
- result = JSON.stringify(result)
- }
- return new Response(result, {
- status: 200,
- headers: Object.keys(headers).length ? headers : undefined,
- })
- }
- if (typeof module[fnName] === "object") {
- let result = module[fnName]
- if (typeof result === "object") {
- result = JSON.stringify(result)
- }
- return new Response(result, {
- status: 200,
- headers: Object.keys(headers).length ? headers : undefined,
- })
- }
- }
- return new Response("", {
- status: 500,
- headers: Object.keys(headers).length ? headers : undefined,
- })
- } else if (request.url.startsWith("api://")) {
- return new Response("error", {
- status: 500,
- })
+ destroy() {
+ // TODO
+ }
+ init(partition?: string) {
+ // const ses = partition ? session.fromPartition(partition) : session.defaultSession
+ const ses = partition ? session.fromPartition(partition) : session.defaultSession
+ ses.protocol.handle("api", this.interceptHandler)
+ }
+ async interceptHandler(request: Request) {
+ if (request.url.startsWith("api://fuck/")) {
+ let curUrl = request.url
+ const isScriteText = curUrl.endsWith("?script")
+ if (isScriteText) {
+ curUrl = curUrl.replace("?script", "")
+ }
+ const isPost = request.method.toLowerCase() === "post"
+ const file = curUrl.replace("api://fuck/", "")
+ const array = file.split("/")
+ const routePath = array.slice(0, -1).join("/")
+ const fnName = array[array.length - 1]
+ // https://vitejs.cn/vite5-cn/guide/features.html#dynamic-import
+ const module = await this._IOC.getAsync(routePath)
+ // const module = await import(`main/controller/${routePath}.ts`)
+ const opts = { body: {}, query: {} }
+ if (isPost) {
+ opts.body = await request.json()
+ }
+ const headers: HeadersInit = {}
+ if (isScriteText) {
+ headers["content-type"] = "text/javascript"
+ }
+ if (isPost) {
+ headers["content-type"] = "application/json"
+ }
+ if (module && module[fnName]) {
+ if (typeof module[fnName] === "string") {
+ const result = module[fnName]
+ return new Response(result, {
+ status: 200,
+ headers: Object.keys(headers).length ? headers : undefined,
+ })
+ }
+ if (typeof module[fnName] === "function") {
+ let result = await module[fnName](opts)
+ if (typeof result === "object") {
+ result = JSON.stringify(result)
+ }
+ return new Response(result, {
+ status: 200,
+ headers: Object.keys(headers).length ? headers : undefined,
+ })
+ }
+ if (typeof module[fnName] === "object") {
+ let result = module[fnName]
+ if (typeof result === "object") {
+ result = JSON.stringify(result)
+ }
+ return new Response(result, {
+ status: 200,
+ headers: Object.keys(headers).length ? headers : undefined,
+ })
}
- return net.fetch(request.url, request)
+ }
+ return new Response("", {
+ status: 500,
+ headers: Object.keys(headers).length ? headers : undefined,
+ })
+ } else if (request.url.startsWith("api://")) {
+ return new Response("error", {
+ status: 500,
+ })
}
+ return net.fetch(request.url, request)
+ }
}
export default Api
diff --git a/src/main/modules/api/readme.md b/src/main/modules/api/readme.md
index 2fac3e0..fa6a5b7 100644
--- a/src/main/modules/api/readme.md
+++ b/src/main/modules/api/readme.md
@@ -1,4 +1,3 @@
-
## 资源
- https://juejin.cn/post/7311619723317657611#heading-6
diff --git a/src/main/modules/api/test.ts b/src/main/modules/api/test.ts
index 4ce835e..3ab696f 100644
--- a/src/main/modules/api/test.ts
+++ b/src/main/modules/api/test.ts
@@ -69,4 +69,3 @@
// };
// ses.protocol.interceptBufferProtocol("https", interceptHandler);
-
diff --git a/src/main/modules/commands/index.ts b/src/main/modules/commands/index.ts
index 410934f..45474a7 100644
--- a/src/main/modules/commands/index.ts
+++ b/src/main/modules/commands/index.ts
@@ -7,99 +7,99 @@ import { isPromise } from "main/utils"
import WindowManager from "../window-manager"
export default class Commands extends BaseClass {
- destroy() {
- // TODO
- }
+ destroy() {
+ // TODO
+ }
- constructor(
- @inject(IOC) private _IOC: IOC,
- @inject(WindowManager) private _WindowManager: WindowManager,
- ) {
- super()
- }
+ constructor(
+ @inject(IOC) private _IOC: IOC,
+ @inject(WindowManager) private _WindowManager: WindowManager,
+ ) {
+ super()
+ }
- private async handleCommand(command: string, ...argus) {
- const splitClass = command.split(".")
- const run = await this._IOC.getAsync(splitClass[0])
- if (run) {
- const result: Promise | any = run[splitClass[1]](...argus)
- return [true, result]
- }
- return [false]
+ private async handleCommand(command: string, ...argus) {
+ const splitClass = command.split(".")
+ const run = await this._IOC.getAsync(splitClass[0])
+ if (run) {
+ const result: Promise | any = run[splitClass[1]](...argus)
+ return [true, result]
}
+ return [false]
+ }
- public async invoke(command, ...argus) {
- const result = await this.handleCommand(command, ...argus)
- return result
- }
+ public async invoke(command, ...argus) {
+ const result = await this.handleCommand(command, ...argus)
+ return result
+ }
- init() {
- ipcMain.addListener("command", async (event, key, command: string, ...argus) => {
- // console.log(event.sender);
- try {
- const [isExist, result] = await this.handleCommand(command, ...argus)
- if (isExist) {
- if (isPromise(result)) {
- result
- .then((res: any) => {
- event.reply(key, null, res ?? null)
- event.returnValue = res ?? null
- })
- .catch((err: Error) => {
- event.reply(key, err)
- event.returnValue = null
- })
- } else {
- event.reply(key, null, result ?? null)
- event.returnValue = result ?? null
- }
- } else {
- event.reply(key, new Error(`不存在该命令:${command}`))
- event.returnValue = null
- }
- } catch (error) {
- event.reply(key, error)
+ init() {
+ ipcMain.addListener("command", async (event, key, command: string, ...argus) => {
+ // console.log(event.sender);
+ try {
+ const [isExist, result] = await this.handleCommand(command, ...argus)
+ if (isExist) {
+ if (isPromise(result)) {
+ result
+ .then((res: any) => {
+ event.reply(key, null, res ?? null)
+ event.returnValue = res ?? null
+ })
+ .catch((err: Error) => {
+ event.reply(key, err)
event.returnValue = null
- }
- })
-
- ipcMain.on("x_popup_menu", (_, name: string, options: IPopupMenuOption) => {
- const menu = new Menu()
- const readMenu = (items: IMenuItemOption[]) => {
- return items.map(opt => {
- if (typeof opt._click_evt === "string") {
- const evt: string = opt._click_evt
- opt.click = () => {
- // broadcast(evt)
- this.sendMessage(name, evt)
- }
- }
- if (opt.submenu && Array.isArray(opt.submenu)) {
- opt.submenu = readMenu(opt.submenu)
- }
+ })
+ } else {
+ event.reply(key, null, result ?? null)
+ event.returnValue = result ?? null
+ }
+ } else {
+ event.reply(key, new Error(`不存在该命令:${command}`))
+ event.returnValue = null
+ }
+ } catch (error) {
+ event.reply(key, error)
+ event.returnValue = null
+ }
+ })
- return opt
- })
+ ipcMain.on("x_popup_menu", (_, name: string, options: IPopupMenuOption) => {
+ const menu = new Menu()
+ const readMenu = (items: IMenuItemOption[]) => {
+ return items.map(opt => {
+ if (typeof opt._click_evt === "string") {
+ const evt: string = opt._click_evt
+ opt.click = () => {
+ // broadcast(evt)
+ this.sendMessage(name, evt)
}
- const arrays = readMenu(options.items)
-
- arrays.forEach(v => {
- const item = new MenuItem(v)
- menu.append(item)
- })
+ }
+ if (opt.submenu && Array.isArray(opt.submenu)) {
+ opt.submenu = readMenu(opt.submenu)
+ }
- menu.on("menu-will-close", () => {
- this.sendMessage(name, `popup_menu_close:${options.menu_id}`)
- // broadcast(`popup_menu_close:${options.menu_id}`)
- })
- menu.popup(options.popupOptions)
+ return opt
})
- }
+ }
+ const arrays = readMenu(options.items)
- sendMessage(name: string, evt: string, ...argu: any[]) {
- const win = this._WindowManager.get(name)
- if (win) {
- win.webContents.send(evt, ...argu)
- }
+ arrays.forEach(v => {
+ const item = new MenuItem(v)
+ menu.append(item)
+ })
+
+ menu.on("menu-will-close", () => {
+ this.sendMessage(name, `popup_menu_close:${options.menu_id}`)
+ // broadcast(`popup_menu_close:${options.menu_id}`)
+ })
+ menu.popup(options.popupOptions)
+ })
+ }
+
+ sendMessage(name: string, evt: string, ...argu: any[]) {
+ const win = this._WindowManager.get(name)
+ if (win) {
+ win.webContents.send(evt, ...argu)
}
+ }
}
diff --git a/src/main/modules/db/custom.ts b/src/main/modules/db/custom.ts
index 14c5f23..a932712 100644
--- a/src/main/modules/db/custom.ts
+++ b/src/main/modules/db/custom.ts
@@ -3,31 +3,31 @@ import { Low } from "lowdb"
import fs from "fs-extra"
export class CustomAdapter extends JSONFile {
- constructor(filepath: string) {
- super(filepath)
- this.filepath = filepath
+ constructor(filepath: string) {
+ super(filepath)
+ this.filepath = filepath
+ }
+ filepath: string = ""
+ async read() {
+ if (!fs.existsSync(this.filepath)) {
+ return null
}
- filepath: string = ""
- async read() {
- if (!fs.existsSync(this.filepath)) {
- return null
- }
- const data = fs.readJSONSync(this.filepath, { throws: false })
- if (!data) {
- return null
- }
- return data
+ const data = fs.readJSONSync(this.filepath, { throws: false })
+ if (!data) {
+ return null
}
+ return data
+ }
- async write(data: T) {
- fs.ensureFileSync(this.filepath)
- await super.write(data)
- }
+ async write(data: T) {
+ fs.ensureFileSync(this.filepath)
+ await super.write(data)
+ }
}
export class CustomLow extends Low {
- constructor(adapter: CustomAdapter, defaultData: T) {
- super(adapter, defaultData)
- this.filepath = adapter.filepath
- }
- filepath: string = ""
+ constructor(adapter: CustomAdapter, defaultData: T) {
+ super(adapter, defaultData)
+ this.filepath = adapter.filepath
+ }
+ filepath: string = ""
}
diff --git a/src/main/modules/db/index.ts b/src/main/modules/db/index.ts
index 1f13419..78fd619 100644
--- a/src/main/modules/db/index.ts
+++ b/src/main/modules/db/index.ts
@@ -9,73 +9,73 @@ const debug = _debug("app:db")
@injectable()
class DB extends BaseClass {
- destroy() {
- debug(`DB destroy`)
- }
- Modules: Record> = {}
+ destroy() {
+ debug(`DB destroy`)
+ }
+ Modules: Record> = {}
- constructor(@inject(Setting) private _setting: Setting) {
- super()
- }
+ constructor(@inject(Setting) private _setting: Setting) {
+ super()
+ }
- init() {
- console.log("DB Init")
- }
+ init() {
+ console.log("DB Init")
+ }
- create(filepath) {
- const adapter = new CustomAdapter(filepath)
- const db = new CustomLow