mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 改进系统托盘单击交互 Fix https://github.com/siyuan-note/siyuan/issues/6861
This commit is contained in:
parent
57e65f664c
commit
1e8b027434
1 changed files with 67 additions and 77 deletions
|
|
@ -397,96 +397,86 @@ const boot = () => {
|
||||||
await fetch(getServer() + '/api/system/uiproc?pid=' + process.pid,
|
await fetch(getServer() + '/api/system/uiproc?pid=' + process.pid,
|
||||||
{method: 'POST'})
|
{method: 'POST'})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 系统托盘菜单
|
||||||
|
const trayMenuTemplate = [
|
||||||
|
{
|
||||||
|
label: 'Official Website',
|
||||||
|
click: () => {
|
||||||
|
shell.openExternal('https://b3log.org/siyuan/')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Open Source',
|
||||||
|
click: () => {
|
||||||
|
shell.openExternal('https://github.com/siyuan-note/siyuan')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '中文反馈',
|
||||||
|
click: () => {
|
||||||
|
shell.openExternal('https://ld246.com/article/1649901726096')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Reset Window on restart',
|
||||||
|
type: 'checkbox',
|
||||||
|
click: v => {
|
||||||
|
resetWindowStateOnRestart = v.checked
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Quit',
|
||||||
|
click: () => {
|
||||||
|
mainWindow.webContents.send('siyuan-save-close', true)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const showWndMenu = {
|
||||||
|
label: 'Hide Window',
|
||||||
|
click: () => {
|
||||||
|
showHideWnd()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const showHideWnd = () => {
|
||||||
|
if (!mainWindow.isVisible()) {
|
||||||
|
if (mainWindow.isMinimized()) {
|
||||||
|
mainWindow.restore()
|
||||||
|
}
|
||||||
|
showWndMenu.label = "Hide Window"
|
||||||
|
trayMenuTemplate.splice(0, 1, showWndMenu)
|
||||||
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
||||||
|
tray.setContextMenu(contextMenu)
|
||||||
|
mainWindow.show()
|
||||||
|
} else {
|
||||||
|
mainWindow.hide()
|
||||||
|
showWndMenu.label = "Show Window"
|
||||||
|
trayMenuTemplate.splice(0, 1, showWndMenu)
|
||||||
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
||||||
|
tray.setContextMenu(contextMenu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ipcMain.on('siyuan-hotkey', (event, hotkey) => {
|
ipcMain.on('siyuan-hotkey', (event, hotkey) => {
|
||||||
globalShortcut.unregisterAll()
|
globalShortcut.unregisterAll()
|
||||||
if (!hotkey) {
|
if (!hotkey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
globalShortcut.register(hotkey, () => {
|
globalShortcut.register(hotkey, () => {
|
||||||
if (mainWindow.isMinimized()) {
|
showHideWnd()
|
||||||
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) {
|
if ('win32' === process.platform || 'linux' === process.platform) {
|
||||||
// 系统托盘
|
// 系统托盘
|
||||||
|
|
||||||
tray = new Tray(path.join(appDir, 'stage', 'icon-large.png'))
|
tray = new Tray(path.join(appDir, 'stage', 'icon-large.png'))
|
||||||
tray.setToolTip('SiYuan v' + appVer)
|
tray.setToolTip('SiYuan v' + appVer)
|
||||||
const trayMenuTemplate = [
|
|
||||||
{
|
|
||||||
label: 'Official Website',
|
|
||||||
click: () => {
|
|
||||||
shell.openExternal('https://b3log.org/siyuan/')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Open Source',
|
|
||||||
click: () => {
|
|
||||||
shell.openExternal('https://github.com/siyuan-note/siyuan')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '中文反馈',
|
|
||||||
click: () => {
|
|
||||||
shell.openExternal('https://ld246.com/article/1649901726096')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Reset Window on restart',
|
|
||||||
type: 'checkbox',
|
|
||||||
click: v => {
|
|
||||||
resetWindowStateOnRestart = v.checked
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Quit',
|
|
||||||
click: () => {
|
|
||||||
mainWindow.webContents.send('siyuan-save-close', true)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const showWndMenu = {
|
// 插入显示/隐藏窗口菜单
|
||||||
label: 'Hide Window',
|
|
||||||
click: () => {
|
|
||||||
showHideWnd()
|
|
||||||
},
|
|
||||||
}
|
|
||||||
trayMenuTemplate.splice(0, 0, showWndMenu)
|
trayMenuTemplate.splice(0, 0, showWndMenu)
|
||||||
|
|
||||||
const showHideWnd = () => {
|
|
||||||
if (!mainWindow.isVisible()) {
|
|
||||||
if (mainWindow.isMinimized()) {
|
|
||||||
mainWindow.restore()
|
|
||||||
}
|
|
||||||
showWndMenu.label = "Hide Window"
|
|
||||||
trayMenuTemplate.splice(0, 1, showWndMenu)
|
|
||||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
|
||||||
tray.setContextMenu(contextMenu)
|
|
||||||
mainWindow.show()
|
|
||||||
} else {
|
|
||||||
mainWindow.hide()
|
|
||||||
showWndMenu.label = "Show Window"
|
|
||||||
trayMenuTemplate.splice(0, 1, showWndMenu)
|
|
||||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
|
||||||
tray.setContextMenu(contextMenu)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let changeWndTop = {}
|
let changeWndTop = {}
|
||||||
if ('win32' === process.platform) {
|
if ('win32' === process.platform) {
|
||||||
// Windows 平台提供窗口置顶功能
|
// Windows 平台提供窗口置顶功能
|
||||||
|
|
@ -496,20 +486,20 @@ const boot = () => {
|
||||||
if (!mainWindow.isAlwaysOnTop()) {
|
if (!mainWindow.isAlwaysOnTop()) {
|
||||||
mainWindow.setAlwaysOnTop(true)
|
mainWindow.setAlwaysOnTop(true)
|
||||||
changeWndTop.label = 'Cancel Window top'
|
changeWndTop.label = 'Cancel Window top'
|
||||||
trayMenuTemplate.splice(trayMenuTemplate.length - 2, 1, changeWndTop)
|
trayMenuTemplate.splice(1, 1, changeWndTop)
|
||||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
||||||
tray.setContextMenu(contextMenu)
|
tray.setContextMenu(contextMenu)
|
||||||
} else {
|
} else {
|
||||||
mainWindow.setAlwaysOnTop(false)
|
mainWindow.setAlwaysOnTop(false)
|
||||||
changeWndTop.label = 'Set Window top'
|
changeWndTop.label = 'Set Window top'
|
||||||
trayMenuTemplate.splice(trayMenuTemplate.length - 2, 1, changeWndTop)
|
trayMenuTemplate.splice(1, 1, changeWndTop)
|
||||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
||||||
tray.setContextMenu(contextMenu)
|
tray.setContextMenu(contextMenu)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
trayMenuTemplate.splice(trayMenuTemplate.length - 1, 0, changeWndTop)
|
trayMenuTemplate.splice(1, 0, changeWndTop)
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue