Browse Source

feat: 优化

feat/icon
npmrun 1 month ago
parent
commit
ca363ceac9
  1. 3
      src/main/commands/TabsCommand.ts
  2. 2
      src/renderer/auto-imports.d.ts
  3. 30
      src/renderer/src/components/NavBar.vue
  4. 7
      src/renderer/src/composables/usePlatform.ts
  5. 9
      src/renderer/src/platform/PlatForm.ts
  6. 54
      src/renderer/src/platform/Tabs.ts
  7. 12
      src/renderer/src/platform/_Base.ts

3
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())
}

2
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<typeof import('@vueuse/core')['useParentElement']>
readonly usePerformanceObserver: UnwrapRef<typeof import('@vueuse/core')['usePerformanceObserver']>
readonly usePermission: UnwrapRef<typeof import('@vueuse/core')['usePermission']>
readonly usePlatForm: UnwrapRef<typeof import('./src/composables/usePlatform')['usePlatForm']>
readonly usePointer: UnwrapRef<typeof import('@vueuse/core')['usePointer']>
readonly usePointerLock: UnwrapRef<typeof import('@vueuse/core')['usePointerLock']>
readonly usePointerSwipe: UnwrapRef<typeof import('@vueuse/core')['usePointerSwipe']>

30
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) })

7
src/renderer/src/composables/usePlatform.ts

@ -0,0 +1,7 @@
import { Tabs } from "@/platform/Tabs"
export function usePlatForm() {
return {
Tabs: Tabs.getInstance<Tabs>(),
}
}

9
src/renderer/src/platform/PlatForm.ts

@ -0,0 +1,9 @@
import { _Base } from "./_Base"
class PlatForm extends _Base {
constructor() {
super()
}
}
export { PlatForm }

54
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
}
}

12
src/renderer/src/platform/_Base.ts

@ -0,0 +1,12 @@
export abstract class _Base {
static instance
static getInstance<T>(): T {
if (!this.instance) {
// 如果实例不存在,则创建一个新的实例
// @ts-ignore ...
this.instance = new this()
}
return this.instance
}
}
Loading…
Cancel
Save