This commit is contained in:
Liang Ding 2022-12-13 00:00:49 +08:00
parent 57e65f664c
commit 1e8b027434
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -397,35 +397,8 @@ const boot = () => {
await fetch(getServer() + '/api/system/uiproc?pid=' + process.pid,
{method: 'POST'})
})
ipcMain.on('siyuan-hotkey', (event, hotkey) => {
globalShortcut.unregisterAll()
if (!hotkey) {
return
}
globalShortcut.register(hotkey, () => {
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()
}
}
})
})
if ('win32' === process.platform || 'linux' === process.platform) {
// 系统托盘
tray = new Tray(path.join(appDir, 'stage', 'icon-large.png'))
tray.setToolTip('SiYuan v' + appVer)
// 系统托盘菜单
const trayMenuTemplate = [
{
label: 'Official Website',
@ -466,8 +439,6 @@ const boot = () => {
showHideWnd()
},
}
trayMenuTemplate.splice(0, 0, showWndMenu)
const showHideWnd = () => {
if (!mainWindow.isVisible()) {
if (mainWindow.isMinimized()) {
@ -487,6 +458,25 @@ const boot = () => {
}
}
ipcMain.on('siyuan-hotkey', (event, hotkey) => {
globalShortcut.unregisterAll()
if (!hotkey) {
return
}
globalShortcut.register(hotkey, () => {
showHideWnd()
})
})
if ('win32' === process.platform || 'linux' === process.platform) {
// 系统托盘
tray = new Tray(path.join(appDir, 'stage', 'icon-large.png'))
tray.setToolTip('SiYuan v' + appVer)
// 插入显示/隐藏窗口菜单
trayMenuTemplate.splice(0, 0, showWndMenu)
let changeWndTop = {}
if ('win32' === process.platform) {
// Windows 平台提供窗口置顶功能
@ -496,20 +486,20 @@ const boot = () => {
if (!mainWindow.isAlwaysOnTop()) {
mainWindow.setAlwaysOnTop(true)
changeWndTop.label = 'Cancel Window top'
trayMenuTemplate.splice(trayMenuTemplate.length - 2, 1, changeWndTop)
trayMenuTemplate.splice(1, 1, changeWndTop)
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
tray.setContextMenu(contextMenu)
} else {
mainWindow.setAlwaysOnTop(false)
changeWndTop.label = 'Set Window top'
trayMenuTemplate.splice(trayMenuTemplate.length - 2, 1, changeWndTop)
trayMenuTemplate.splice(1, 1, changeWndTop)
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
tray.setContextMenu(contextMenu)
}
},
};
trayMenuTemplate.splice(trayMenuTemplate.length - 1, 0, changeWndTop)
trayMenuTemplate.splice(1, 0, changeWndTop)
}
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)