diff --git a/src/main/commands/TabsCommand.ts b/src/main/commands/TabsCommand.ts index e97c9f2..0619e17 100644 --- a/src/main/commands/TabsCommand.ts +++ b/src/main/commands/TabsCommand.ts @@ -8,11 +8,10 @@ class TabsCommand { @inject(Tabs) private _Tabs: Tabs, @inject(WindowManager) private _WindowManager: WindowManager, ) { - this.listenerTabActive = this.listenerTabActive.bind(this) this._Tabs.events.on("update", this.listenerTabActive) } - listenerTabActive() { + listenerTabActive = () => { broadcast("main:TabsCommand.update", this.getAllTabs()) } diff --git a/src/renderer/auto-imports.d.ts b/src/renderer/auto-imports.d.ts index 907387e..f3961c9 100644 --- a/src/renderer/auto-imports.d.ts +++ b/src/renderer/auto-imports.d.ts @@ -211,6 +211,7 @@ declare global { const useParentElement: typeof import('@vueuse/core')['useParentElement'] const usePerformanceObserver: typeof import('@vueuse/core')['usePerformanceObserver'] const usePermission: typeof import('@vueuse/core')['usePermission'] + const usePlatForm: typeof import('./src/composables/usePlatform')['usePlatForm'] const usePointer: typeof import('@vueuse/core')['usePointer'] const usePointerLock: typeof import('@vueuse/core')['usePointerLock'] const usePointerSwipe: typeof import('@vueuse/core')['usePointerSwipe'] @@ -511,6 +512,7 @@ declare module 'vue' { readonly useParentElement: UnwrapRef readonly usePerformanceObserver: UnwrapRef readonly usePermission: UnwrapRef + readonly usePlatForm: UnwrapRef readonly usePointer: UnwrapRef readonly usePointerLock: UnwrapRef readonly usePointerSwipe: UnwrapRef diff --git a/src/renderer/src/components/NavBar.vue b/src/renderer/src/components/NavBar.vue index c1d8696..a5f0461 100644 --- a/src/renderer/src/components/NavBar.vue +++ b/src/renderer/src/components/NavBar.vue @@ -55,21 +55,21 @@ const onClickMenu = e => { isFullScreen.value = await api.call("BasicCommand.toggleDevTools") }, }, - { - type: "separator", - }, - { - label: "重载", - click() { - api.call("BasicCommand.reload") - }, - }, - { - label: "重启", - click() { - api.call("BasicCommand.relunch") - }, - }, + // { + // type: "separator", + // }, + // { + // label: "重载", + // click() { + // api.call("BasicCommand.reload") + // }, + // }, + // { + // label: "重启", + // click() { + // api.call("BasicCommand.relunch") + // }, + // }, ]) const obj = e.target.getBoundingClientRect() menu.show({ x: ~~obj.x, y: ~~(obj.y + obj.height) }) diff --git a/src/renderer/src/composables/usePlatform.ts b/src/renderer/src/composables/usePlatform.ts new file mode 100644 index 0000000..592f410 --- /dev/null +++ b/src/renderer/src/composables/usePlatform.ts @@ -0,0 +1,7 @@ +import { Tabs } from "@/platform/Tabs" + +export function usePlatForm() { + return { + Tabs: Tabs.getInstance(), + } +} diff --git a/src/renderer/src/platform/PlatForm.ts b/src/renderer/src/platform/PlatForm.ts new file mode 100644 index 0000000..4d8c332 --- /dev/null +++ b/src/renderer/src/platform/PlatForm.ts @@ -0,0 +1,9 @@ +import { _Base } from "./_Base" + +class PlatForm extends _Base { + constructor() { + super() + } +} + +export { PlatForm } diff --git a/src/renderer/src/platform/Tabs.ts b/src/renderer/src/platform/Tabs.ts new file mode 100644 index 0000000..2e82276 --- /dev/null +++ b/src/renderer/src/platform/Tabs.ts @@ -0,0 +1,54 @@ +import { _Base } from "./_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 + } +} diff --git a/src/renderer/src/platform/_Base.ts b/src/renderer/src/platform/_Base.ts new file mode 100644 index 0000000..91d8f4b --- /dev/null +++ b/src/renderer/src/platform/_Base.ts @@ -0,0 +1,12 @@ +export abstract class _Base { + static instance + + static getInstance(): T { + if (!this.instance) { + // 如果实例不存在,则创建一个新的实例 + // @ts-ignore ... + this.instance = new this() + } + return this.instance + } +}