This commit is contained in:
Liang Ding 2022-12-17 19:13:19 +08:00
parent c30b85d01f
commit 6bc63d35d2
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D

View File

@ -421,39 +421,54 @@ const boot = () => {
tray.setContextMenu(contextMenu)
}
const showWndMenu = {
const buildShowWndMenu = () => {
const ret = {
label: trayMenu.hideWindow,
click: () => {
showHideWnd()
},
}
if (mainWindow.isVisible()) {
ret.label = trayMenu.hideWindow
} else {
ret.label = trayMenu.showWindow
}
return ret
}
const showHideWnd = () => {
if (!mainWindow.isVisible()) {
if (mainWindow.isMinimized()) {
mainWindow.restore()
}
mainWindow.show()
showWndMenu.label = trayMenu.hideWindow
} else {
mainWindow.hide()
showWndMenu.label = trayMenu.showWindow
}
resetTrayMenu()
}
const setWndTopMenu = {
const buildSetWndTopMenu = () => {
const ret = {
label: trayMenu.setWindowTop,
click: () => {
setCancelWndTop()
},
}
if (mainWindow.isAlwaysOnTop()) {
ret.label = trayMenu.cancelWindowTop
} else {
ret.label = trayMenu.setWindowTop
}
return ret;
}
const setCancelWndTop = () => {
if (!mainWindow.isAlwaysOnTop()) {
mainWindow.setAlwaysOnTop(true)
setWndTopMenu.label = trayMenu.cancelWindowTop
} else {
mainWindow.setAlwaysOnTop(false)
setWndTopMenu.label = trayMenu.setWindowTop
}
resetTrayMenu()
@ -461,7 +476,7 @@ const boot = () => {
const buildTrayMenuTemplate = () => {
let ret = [
showWndMenu,
buildShowWndMenu(),
{
label: trayMenu.officialWebsite,
click: () => {
@ -491,7 +506,7 @@ const boot = () => {
if ('win32' === process.platform) {
// Windows 端支持窗口置顶 https://github.com/siyuan-note/siyuan/issues/6860
ret.splice(1, 0, setWndTopMenu)
ret.splice(1, 0, buildSetWndTopMenu())
}
return ret;
}
@ -502,7 +517,24 @@ const boot = () => {
return
}
globalShortcut.register(hotkey, () => {
showHideWnd()
if (mainWindow.isMinimized()) {
mainWindow.restore()
if (!mainWindow.isVisible()) {
mainWindow.show()
}
} else {
if (mainWindow.isVisible()) {
if (!mainWindow.isFocused()) {
mainWindow.show()
} else {
mainWindow.hide()
}
} else {
mainWindow.show()
}
}
resetTrayMenu()
})
})