From dcdc4aa857ec50f58f04355d06db368889723090 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B0=A2=E4=BA=9A=E6=98=95?= <1549469775@qq.com>
Date: Tue, 25 Mar 2025 18:26:01 +0800
Subject: [PATCH] fix bug

---
 package.json                             |  2 +-
 src/main/App.ts                          | 15 ++++++---------
 src/main/commands/BasicCommand.ts        | 18 ++++++++++++------
 src/main/modules/commands/index.ts       | 21 +++++++++++++++++----
 src/main/modules/window-manager/index.ts | 12 +++++++++++-
 5 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/package.json b/package.json
index 1275f79..2e1510c 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
     "name": "zephyr",
     "type": "module",
     "private": true,
-    "version": "1.0.0",
+    "version": "0.0.1",
     "description": "An Electron application with Vue and TypeScript",
     "main": "./out/main/index.js",
     "author": "example.com",
diff --git a/src/main/App.ts b/src/main/App.ts
index 037e164..8dc4b67 100644
--- a/src/main/App.ts
+++ b/src/main/App.ts
@@ -70,15 +70,12 @@ class App extends BaseClass {
             this._Zephyr.init()
             electronApp.setAppUserModelId("top.xieyaxin")
             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._Command.invoke("BasicCommand.setTheme", "light")
+            this._Command.invoke("BasicCommand.setTitlBar", {
+                height: 29,
+                color: "#F8F8F8",
+                symbolColor: "#000000",
+            })
         })
         app.on("will-quit", () => {
             this.destroy()
diff --git a/src/main/commands/BasicCommand.ts b/src/main/commands/BasicCommand.ts
index 053687e..c4c0fe1 100644
--- a/src/main/commands/BasicCommand.ts
+++ b/src/main/commands/BasicCommand.ts
@@ -1,17 +1,23 @@
-import { app, dialog } from "electron"
+import { app, dialog, nativeTheme, TitleBarOverlayOptions } from "electron"
 import { inject } from "inversify"
-import Commands from "main/modules/commands"
 import Tabs from "main/modules/tabs"
 import WindowManager from "main/modules/window-manager"
 
 export default class BasicCommand {
     constructor(
-        @inject(Commands) private _Commands: Commands,
         @inject(WindowManager) private _WindowManager: WindowManager,
         @inject(Tabs) private _Tabs: Tabs,
-    ) {
-        //
-        console.log(this._Commands)
+    ) {}
+
+    setTheme(theme: typeof nativeTheme.themeSource) {
+        nativeTheme.themeSource = theme
+    }
+
+    setTitlBar(options: TitleBarOverlayOptions) {
+        const mainWindow = this._WindowManager.getMainWindow()
+        if (mainWindow) {
+            mainWindow.setTitleBarOverlay(options)
+        }
     }
 
     toggleDevTools() {
diff --git a/src/main/modules/commands/index.ts b/src/main/modules/commands/index.ts
index 91897ff..f0558ef 100644
--- a/src/main/modules/commands/index.ts
+++ b/src/main/modules/commands/index.ts
@@ -18,14 +18,27 @@ export default class Commands extends BaseClass {
         super()
     }
 
+    private async handleCommand(command: string, ...argus) {
+        const splitClass = command.split(".")
+        const run = await this._IOC.getAsync<any>(splitClass[0])
+        if (run) {
+            const result: Promise<any> | any = run[splitClass[1]](...argus)
+            return result
+        }
+        return null
+    }
+
+    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 splitClass = command.split(".")
-                const run = await this._IOC.getAsync<any>(splitClass[0])
-                if (run) {
-                    const result: Promise<any> | any = run[splitClass[1]](...argus)
+                const result = await this.handleCommand(command, ...argus)
+                if (result) {
                     if (isPromise(result)) {
                         result
                             .then((res: any) => {
diff --git a/src/main/modules/window-manager/index.ts b/src/main/modules/window-manager/index.ts
index 944dc1e..da9c350 100644
--- a/src/main/modules/window-manager/index.ts
+++ b/src/main/modules/window-manager/index.ts
@@ -18,6 +18,9 @@ export { WindowManager }
 export default class WindowManager extends BaseClass {
     constructor() {
         super()
+        this.isMainShowReady = new Promise(resolve => {
+            this.isMainShowResolve = resolve
+        })
     }
 
     destroy() {
@@ -51,6 +54,13 @@ export default class WindowManager extends BaseClass {
 
     showMainWindow() {
         this.#showWin(this.mainInfo)
+        this.isMainShowResolve()
+    }
+
+    private isMainShowResolve
+    private isMainShowReady
+    async waitMainShowReady() {
+        await this.isMainShowReady
     }
 
     showWindow(name: string, opts?: Partial<IConfig>) {
@@ -246,7 +256,7 @@ export default class WindowManager extends BaseClass {
     }
 
     showCurrentWindow() {
-        if(this.#windows.length) {
+        if (this.#windows.length) {
             debug(`current open window: ${this.#windows.map(v => v.$$opts!.name).join(",")}`)
         } else {
             debug(`all closed`)