mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 桌面端托盘加入选项 重启时重置窗口 Fix https://github.com/siyuan-note/siyuan/issues/6043
This commit is contained in:
parent
4493649d0b
commit
6978bf24c1
1 changed files with 25 additions and 13 deletions
|
|
@ -33,12 +33,14 @@ const appDir = path.dirname(app.getAppPath())
|
||||||
const isDevEnv = process.env.NODE_ENV === 'development'
|
const isDevEnv = process.env.NODE_ENV === 'development'
|
||||||
const appVer = app.getVersion()
|
const appVer = app.getVersion()
|
||||||
const confDir = path.join(app.getPath('home'), '.config', 'siyuan')
|
const confDir = path.join(app.getPath('home'), '.config', 'siyuan')
|
||||||
|
const windowStatePath = path.join(confDir, 'windowState.json')
|
||||||
let tray // 托盘必须使用全局变量,以防止被垃圾回收 https://www.electronjs.org/docs/faq#my-apps-windowtray-disappeared-after-a-few-minutes
|
let tray // 托盘必须使用全局变量,以防止被垃圾回收 https://www.electronjs.org/docs/faq#my-apps-windowtray-disappeared-after-a-few-minutes
|
||||||
let mainWindow // 从托盘处激活报错 https://github.com/siyuan-note/siyuan/issues/769
|
let mainWindow // 从托盘处激活报错 https://github.com/siyuan-note/siyuan/issues/769
|
||||||
let firstOpenWindow, bootWindow
|
let firstOpenWindow, bootWindow
|
||||||
let closeButtonBehavior = 0
|
let closeButtonBehavior = 0
|
||||||
let siyuanOpenURL
|
let siyuanOpenURL
|
||||||
let firstOpen = false
|
let firstOpen = false
|
||||||
|
let resetWindowStateOnRestart = false
|
||||||
require('@electron/remote/main').initialize()
|
require('@electron/remote/main').initialize()
|
||||||
|
|
||||||
if (!app.requestSingleInstanceLock()) {
|
if (!app.requestSingleInstanceLock()) {
|
||||||
|
|
@ -112,8 +114,6 @@ const writeLog = (out) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const boot = () => {
|
const boot = () => {
|
||||||
const windowStatePath = path.join(confDir, 'windowState.json')
|
|
||||||
|
|
||||||
// 恢复主窗体状态
|
// 恢复主窗体状态
|
||||||
let oldWindowState = {}
|
let oldWindowState = {}
|
||||||
try {
|
try {
|
||||||
|
|
@ -368,6 +368,9 @@ const boot = () => {
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-quit', () => {
|
ipcMain.on('siyuan-quit', () => {
|
||||||
try {
|
try {
|
||||||
|
if (resetWindowStateOnRestart) {
|
||||||
|
fs.writeFileSync(windowStatePath, '{}')
|
||||||
|
} else {
|
||||||
const bounds = mainWindow.getBounds()
|
const bounds = mainWindow.getBounds()
|
||||||
fs.writeFileSync(windowStatePath, JSON.stringify({
|
fs.writeFileSync(windowStatePath, JSON.stringify({
|
||||||
isMaximized: mainWindow.isMaximized(),
|
isMaximized: mainWindow.isMaximized(),
|
||||||
|
|
@ -378,7 +381,9 @@ const boot = () => {
|
||||||
width: bounds.width,
|
width: bounds.width,
|
||||||
height: bounds.height,
|
height: bounds.height,
|
||||||
}))
|
}))
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
writeLog(e)
|
||||||
}
|
}
|
||||||
app.exit()
|
app.exit()
|
||||||
globalShortcut.unregisterAll()
|
globalShortcut.unregisterAll()
|
||||||
|
|
@ -420,7 +425,7 @@ const boot = () => {
|
||||||
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')
|
tray.setToolTip('SiYuan v' + appVer)
|
||||||
const trayMenuTemplate = [
|
const trayMenuTemplate = [
|
||||||
{
|
{
|
||||||
label: 'Show Window',
|
label: 'Show Window',
|
||||||
|
|
@ -455,6 +460,13 @@ const boot = () => {
|
||||||
shell.openExternal('https://ld246.com/article/1649901726096')
|
shell.openExternal('https://ld246.com/article/1649901726096')
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Reset Window on restart',
|
||||||
|
type: 'checkbox',
|
||||||
|
click: v => {
|
||||||
|
resetWindowStateOnRestart = v.checked;
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
click: () => {
|
click: () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue