Skip to content

Commit 7fa0fa5

Browse files
committed
feat: 添加 macOS 下点击 Dock 图标激活主窗口的功能
1 parent 95af222 commit 7fa0fa5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/modules/window.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ let mainWindowState = {
1414
isMaximized: false
1515
};
1616

17+
// 保存主窗口引用,以便在 activate 事件中使用
18+
let mainWindowInstance: BrowserWindow | null = null;
19+
1720
/**
1821
* 初始化代理设置
1922
*/
@@ -183,6 +186,17 @@ export function initializeWindowManager() {
183186
}
184187
}
185188
});
189+
190+
// 监听 macOS 下点击 Dock 图标的事件
191+
app.on('activate', () => {
192+
// 当应用被激活时,检查主窗口是否存在
193+
if (mainWindowInstance && !mainWindowInstance.isDestroyed()) {
194+
// 如果窗口存在但被隐藏,则显示窗口
195+
if (!mainWindowInstance.isVisible()) {
196+
mainWindowInstance.show();
197+
}
198+
}
199+
});
186200
}
187201

188202
/**
@@ -205,6 +219,7 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
205219
});
206220

207221
mainWindow.setMinimumSize(1200, 780);
222+
mainWindow.removeMenu();
208223

209224
mainWindow.on('ready-to-show', () => {
210225
mainWindow.show();
@@ -229,5 +244,8 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
229244
mainWindow.loadFile(join(__dirname, '../renderer/index.html'));
230245
}
231246

247+
// 保存主窗口引用
248+
mainWindowInstance = mainWindow;
249+
232250
return mainWindow;
233251
}

0 commit comments

Comments
 (0)