diff --git a/package.json b/package.json index af63e8c..ab91860 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "simplebar-vue": "^2.4.0", "typescript": "^5.7.3", "unocss": "^0.64.1", + "utils": "workspace:*", "unplugin-auto-import": "^19.1.0", "unplugin-icons": "^22.1.0", "unplugin-vue-components": "^28.4.0", diff --git a/packages/helper/updater/common.ts b/packages/helper/updater/common.ts index 14f45df..b512f5f 100644 --- a/packages/helper/updater/common.ts +++ b/packages/helper/updater/common.ts @@ -1,7 +1,3 @@ -export const enum EventEnum { - UPDATE_PROGRESS = "update-progress", -} - export type EventMaps = { - [EventEnum.UPDATE_PROGRESS]: () => void + "update-progress": (data: { percent: number; all: number; now: number }) => void } diff --git a/packages/helper/updater/main/handler.ts b/packages/helper/updater/main/handler.ts index b01b5ed..8e5c3f9 100644 --- a/packages/helper/updater/main/handler.ts +++ b/packages/helper/updater/main/handler.ts @@ -1,8 +1,6 @@ -import { broadcast } from "main/utils" -import { EventEnum } from "../common" +import { broadcast } from "utils/main" +import { EventMaps } from "../common" -export { EventEnum } - -export function emit(key: EventEnum, ...args: any[]) { +export function emit(key: keyof EventMaps, ...args: Parameters) { broadcast(key, ...args) } diff --git a/packages/helper/updater/main/hot/index.ts b/packages/helper/updater/main/hot/index.ts index fcf2e89..4f8b9b3 100644 --- a/packages/helper/updater/main/hot/index.ts +++ b/packages/helper/updater/main/hot/index.ts @@ -7,7 +7,7 @@ import download from "./download" import extract from "extract-zip" import _logger from "logger/main" -import { emit, EventEnum } from "../handler" +import { emit } from "../handler" const logger = _logger.createNamespace("hot-updater") @@ -92,7 +92,7 @@ export async function fetchHotUpdatePackage(updatePackageUrl: string) { url: updatePackageUrl, onprocess(now, all) { logger.debug(`下载进度: ${((now / all) * 100).toFixed(2)}%`) - emit(EventEnum.UPDATE_PROGRESS, { percent: (now / all) * 100, now, all }) + emit("update-progress", { percent: (now / all) * 100, now, all }) }, }) fs.writeFileSync(downloadPath, Buffer.from(arrayBuffer)) diff --git a/packages/utils/index.ts b/packages/utils/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/utils/main/index.ts b/packages/utils/main/index.ts new file mode 100644 index 0000000..d78e8cd --- /dev/null +++ b/packages/utils/main/index.ts @@ -0,0 +1,5 @@ +import { webContents } from "electron" + +export const broadcast = void>>(event: keyof T, ...args: Parameters) => { + webContents.getAllWebContents().forEach(browser => browser.send(event as any, ...args)) +} diff --git a/packages/utils/package.json b/packages/utils/package.json new file mode 100644 index 0000000..bb0cced --- /dev/null +++ b/packages/utils/package.json @@ -0,0 +1,7 @@ +{ + "name": "utils", + "version": "1.0.0", + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e0607d0..6605c89 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -162,6 +162,9 @@ importers: unplugin-vue-router: specifier: ^0.11.2 version: 0.11.2(rollup@4.26.0)(vue-router@4.5.0(vue@3.5.13(typescript@5.7.3)))(vue@3.5.13(typescript@5.7.3)) + utils: + specifier: workspace:* + version: link:packages/utils vite: specifier: ^5.4.14 version: 5.4.14(@types/node@20.17.19)(sass@1.85.0) @@ -194,6 +197,8 @@ importers: packages/setting: {} + packages/utils: {} + packages: 7zip-bin@5.2.0: @@ -776,8 +781,8 @@ packages: resolution: {integrity: sha512-2kGiWoXaeV8HZlhU/Nml12oTbhv7j2ufsJ5vQaa0VTjzUmZVdd/nmKFRAOJ/FtjO90Qba5AnZDwsrY7ZND5udA==} engines: {node: '>= 16'} - '@intlify/shared@11.1.3': - resolution: {integrity: sha512-pTFBgqa/99JRA2H1qfyqv97MKWJrYngXBA/I0elZcYxvJgcCw3mApAoPW3mJ7vx3j+Ti0FyKUFZ4hWxdjKaxvA==} + '@intlify/shared@11.1.5': + resolution: {integrity: sha512-+I4vRzHm38VjLr/CAciEPJhGYFzWWW4HMTm+6H3WqknXLh0ozNX9oC8ogMUwTSXYR/wGUb1/lTpNziiCH5MybQ==} engines: {node: '>= 16'} '@intlify/shared@12.0.0-alpha.2': @@ -4355,7 +4360,7 @@ snapshots: '@intlify/shared@11.1.1': {} - '@intlify/shared@11.1.3': {} + '@intlify/shared@11.1.5': {} '@intlify/shared@12.0.0-alpha.2': {} @@ -4363,8 +4368,8 @@ snapshots: dependencies: '@eslint-community/eslint-utils': 4.4.1(eslint@8.57.1) '@intlify/bundle-utils': 10.0.0(vue-i18n@11.1.1(vue@3.5.13(typescript@5.7.3))) - '@intlify/shared': 11.1.3 - '@intlify/vue-i18n-extensions': 8.0.0(@intlify/shared@11.1.3)(@vue/compiler-dom@3.5.13)(vue-i18n@11.1.1(vue@3.5.13(typescript@5.7.3)))(vue@3.5.13(typescript@5.7.3)) + '@intlify/shared': 11.1.5 + '@intlify/vue-i18n-extensions': 8.0.0(@intlify/shared@11.1.5)(@vue/compiler-dom@3.5.13)(vue-i18n@11.1.1(vue@3.5.13(typescript@5.7.3)))(vue@3.5.13(typescript@5.7.3)) '@rollup/pluginutils': 5.1.4(rollup@4.26.0) '@typescript-eslint/scope-manager': 8.25.0 '@typescript-eslint/typescript-estree': 8.25.0(typescript@5.7.3) @@ -4386,11 +4391,11 @@ snapshots: - supports-color - typescript - '@intlify/vue-i18n-extensions@8.0.0(@intlify/shared@11.1.3)(@vue/compiler-dom@3.5.13)(vue-i18n@11.1.1(vue@3.5.13(typescript@5.7.3)))(vue@3.5.13(typescript@5.7.3))': + '@intlify/vue-i18n-extensions@8.0.0(@intlify/shared@11.1.5)(@vue/compiler-dom@3.5.13)(vue-i18n@11.1.1(vue@3.5.13(typescript@5.7.3)))(vue@3.5.13(typescript@5.7.3))': dependencies: '@babel/parser': 7.26.9 optionalDependencies: - '@intlify/shared': 11.1.3 + '@intlify/shared': 11.1.5 '@vue/compiler-dom': 3.5.13 vue: 3.5.13(typescript@5.7.3) vue-i18n: 11.1.1(vue@3.5.13(typescript@5.7.3)) diff --git a/src/common/event/Tabs/main/command.ts b/src/common/event/Tabs/main/command.ts index 0962cca..a9984d3 100644 --- a/src/common/event/Tabs/main/command.ts +++ b/src/common/event/Tabs/main/command.ts @@ -1,7 +1,7 @@ import { inject } from "inversify" import Tabs from "main/modules/tabs" import WindowManager from "main/modules/window-manager" -import { broadcast } from "main/utils" +import { broadcast } from "utils/main" class TabsCommand { constructor( diff --git a/src/common/event/Updater/index.ts b/src/common/event/Updater/index.ts index a819641..6a829d0 100644 --- a/src/common/event/Updater/index.ts +++ b/src/common/event/Updater/index.ts @@ -1,10 +1,10 @@ -// import { EventEnum } from "helper/updater/common" +import { EventMaps } from "helper/updater/common" const curProgress = ref(0) -// .on(EventEnum.UPDATE_PROGRESS, ({ percent, now, all }) => { -// curProgress.value = percent -// }) +getApi().on("update-progress", (_, data) => { + console.log(data) +}) function useUpdate() { return { diff --git a/src/main/App.ts b/src/main/App.ts index 8976300..87a47ca 100644 --- a/src/main/App.ts +++ b/src/main/App.ts @@ -11,6 +11,7 @@ import IOC from "./_ioc" import DB from "./modules/db" import Zephyr from "./modules/zephyr" import { crashHandler } from "logger/crash-handler" +import logger from "logger/main" protocol.registerSchemesAsPrivileged([ // { @@ -60,6 +61,7 @@ class App extends BaseClass { } async init() { + logger.debug("初始化App") // 新开窗口的时候,会有个窗口闪烁的问题,也可以理解为渐入效果 // 主进程中添加如下代码即可 app.commandLine.appendSwitch("wm-window-animations-disabled") diff --git a/src/main/utils/index.ts b/src/main/utils/index.ts index 11aa880..3d7d89d 100644 --- a/src/main/utils/index.ts +++ b/src/main/utils/index.ts @@ -1,6 +1,5 @@ import { is } from "@electron-toolkit/utils" import { join } from "node:path" -import { webContents } from "electron" export function getFileUrl(app: string) { let winURL = "" @@ -20,10 +19,6 @@ export function isPromise(value: () => any) { return value && Object.prototype.toString.call(value) === "[object Promise]" } -export const broadcast = (event: T, ...args: any[]) => { - webContents.getAllWebContents().forEach(browser => browser.send(event, ...args)) -} - export function slash(path: string) { const isExtendedLengthPath = path.startsWith("\\\\?\\") if (isExtendedLengthPath) { diff --git a/src/renderer/src/pages/index/index copy.vue b/src/renderer/src/pages/index/index copy.vue new file mode 100644 index 0000000..af32e5f --- /dev/null +++ b/src/renderer/src/pages/index/index copy.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/src/renderer/src/pages/index/index.vue b/src/renderer/src/pages/index/index.vue index af32e5f..798684c 100644 --- a/src/renderer/src/pages/index/index.vue +++ b/src/renderer/src/pages/index/index.vue @@ -1,83 +1,9 @@ - + - + diff --git a/src/renderer/typed-router.d.ts b/src/renderer/typed-router.d.ts index a4b8de8..856211d 100644 --- a/src/renderer/typed-router.d.ts +++ b/src/renderer/typed-router.d.ts @@ -19,6 +19,7 @@ declare module 'vue-router/auto-routes' { */ export interface RouteNamedMap { '//': RouteRecordInfo<'//', '/', Record, Record>, + '//index copy': RouteRecordInfo<'//index copy', '/index copy', Record, Record>, '/[...all]': RouteRecordInfo<'/[...all]', '/:all(.*)', { all: ParamValue }, { all: ParamValue }>, 'about': RouteRecordInfo<'about', '/about', Record, Record>, '/browser': RouteRecordInfo<'/browser', '/browser', Record, Record>, diff --git a/src/types/errorHandler.d.ts b/src/types/errorHandler.d.ts index 6f9cdbd..b7a2034 100644 --- a/src/types/errorHandler.d.ts +++ b/src/types/errorHandler.d.ts @@ -2,4 +2,4 @@ declare const errorHandler: import("logger/preload-error").IRendererErrorHandler interface Window { errorHandler: import("logger/preload-error").IRendererErrorHandler -} \ No newline at end of file +} diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 89f0969..49cab64 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -1,12 +1,12 @@ type FireFN = (...argu: any[]) => void type Api> = { - call: (command: S, ...args: Parameters) => ReturnType - callLong: (command: S, ...args: Parameters) => ReturnType - callSync: (command: S, ...args: Parameters) => ReturnType - send: (command: S, ...argu: Parameters) => ReturnType - sendSync: (command: S, ...argu: Parameters) => ReturnType - on: (command: S, cb: (event: IpcRendererEvent, ...args: Parameters) => void) => () => void + call: (command: string, ...args: any[]) => any + callLong: (command: string, ...args: any[]) => any + callSync: (command: string, ...args: any[]) => any + send: (command: string, ...argu: any[]) => any + sendSync: (command: string, ...argu: any[]) => any + on: (command: S, cb: (event: IpcRendererEventIpcRendererEvent, ...args: Parameters) => void) => () => void once: (command: S, cb: (event: IpcRendererEvent, ...args: Parameters) => void) => () => void off: (command: S, cb: (event: IpcRendererEvent, ...args: Parameters) => void) => void offAll: (command: S) => void diff --git a/src/types/popup-menu.ts b/src/types/popup-menu.d.ts similarity index 100% rename from src/types/popup-menu.ts rename to src/types/popup-menu.d.ts diff --git a/tsconfig.node.json b/tsconfig.node.json index b85c63b..c94e699 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -3,6 +3,7 @@ "include": [ "electron.vite.config.*", "src/main/**/*", + "src/types/popup-menu.d.ts", "src/preload/**/*", "config/**/*", "packages/locales/main.ts", @@ -67,6 +68,9 @@ "base/*": [ "packages/base/*" ], + "utils/*": [ + "packages/utils/*" + ], } } } diff --git a/tsconfig.web.json b/tsconfig.web.json index 54f273e..040310d 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -67,6 +67,9 @@ "base/*": [ "packages/base/*" ], + "utils/*": [ + "packages/utils/*" + ], } } }