Skip to content

Commit 9c1ee36

Browse files
committed
fix: close button logic
1 parent d118646 commit 9c1ee36

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src-electron/tray.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ const state = {
3030

3131
// --- 核心逻辑 ---
3232

33+
// 切换规则
34+
function switchMode(menuItem: any, mode: string) {
35+
if (!menuItem.checked) {
36+
menuItem.checked = true
37+
return
38+
}
39+
sendMsg(mainWindow, "switchMode", mode)
40+
}
41+
42+
43+
// 切换配置
44+
function switchProfiles(menuItem: any, profile: any) {
45+
if (!menuItem.checked) {
46+
menuItem.checked = true
47+
return
48+
}
49+
sendMsg(mainWindow, "switchProfiles", profile)
50+
}
51+
3352
/**
3453
* 根据当前 state 重新渲染托盘菜单
3554
*/
@@ -43,19 +62,19 @@ function updateTrayMenu() {
4362
label: state.labels.rule,
4463
type: 'checkbox',
4564
checked: state.mode === 'rule',
46-
click: () => sendMsg(mainWindow, "switchMode", 'rule')
65+
click: (menuItem: any) => switchMode(menuItem, 'rule')
4766
},
4867
{
4968
label: state.labels.global,
5069
type: 'checkbox',
5170
checked: state.mode === 'global',
52-
click: () => sendMsg(mainWindow, "switchMode", 'global')
71+
click: (menuItem: any) => switchMode(menuItem, 'global')
5372
},
5473
{
5574
label: state.labels.direct,
5675
type: 'checkbox',
5776
checked: state.mode === 'direct',
58-
click: () => sendMsg(mainWindow, "switchMode", 'direct')
77+
click: (menuItem: any) => switchMode(menuItem, 'direct')
5978
},
6079
{type: 'separator'},
6180
{
@@ -64,7 +83,7 @@ function updateTrayMenu() {
6483
label: p.title,
6584
type: 'checkbox',
6685
checked: !!p.selected,
67-
click: () => sendMsg(mainWindow, "switchProfiles", p)
86+
click: (menuItem: any) => switchProfiles(menuItem, p)
6887
}))
6988
},
7089
{type: 'separator'},
@@ -110,8 +129,8 @@ export function initTray(win: BrowserWindow) {
110129
updateTrayMenu();
111130

112131
// 点击事件
113-
tray.on('click', () => tray?.popUpContextMenu());
114-
tray.on('right-click', () => tray?.popUpContextMenu());
132+
tray.on('click', () => tray.popUpContextMenu());
133+
tray.on('right-click', () => tray.popUpContextMenu());
115134
}
116135

117136
// --- 工具函数 ---
@@ -163,7 +182,12 @@ onMsg("hide", () => {
163182
mainWindow?.hide();
164183
app.dock?.hide();
165184
});
166-
onMsg("max", () => mainWindow?.isMaximized() ? mainWindow.unmaximize() : mainWindow?.maximize());
167-
onMsg("min", () => mainWindow?.minimize());
185+
onMsg("close", () => app.quit());
186+
onMsg("max", () => mainWindow.isMaximized() ? mainWindow.unmaximize() : mainWindow.maximize());
187+
onMsg("min", () => mainWindow.minimize());
168188
onMsg("boot", (val) => val ? enableAutoLaunch() : disableAutoLaunch());
189+
onMsg("tunAuthTip", (val) => {
190+
if (val) storeSet("tunAuthTip", val)
191+
}
192+
)
169193
onMsg("doChangeConfigDir", (val) => doChange(mainWindow!, val));

0 commit comments

Comments
 (0)