mirror of
https://github.com/heyman/heynote.git
synced 2025-06-24 11:31:25 +02:00
Automatically remove/add window from Taskbar in Windows, when Show in tray is turned on.
Call setForceQuite() before autoUpdater.quitAndInstall() to make sure auto updating works when Tray/Menu Bar setting is turned on.
This commit is contained in:
parent
fcbf1733c4
commit
e887d7e35f
@ -12,6 +12,7 @@ import {
|
|||||||
UPDATE_INSTALL_AND_RESTART,
|
UPDATE_INSTALL_AND_RESTART,
|
||||||
UPDATE_CHECK_FOR_UPDATES,
|
UPDATE_CHECK_FOR_UPDATES,
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
|
import { setForceQuit } from "./index";
|
||||||
|
|
||||||
|
|
||||||
// will reference the main window
|
// will reference the main window
|
||||||
@ -62,7 +63,11 @@ ipcMain.handle(UPDATE_START_DOWNLOAD, () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle(UPDATE_INSTALL_AND_RESTART, () => {
|
ipcMain.handle(UPDATE_INSTALL_AND_RESTART, () => {
|
||||||
setImmediate(() => autoUpdater.quitAndInstall(true, true))
|
setImmediate(() => {
|
||||||
|
// make sure we can quite the app if it's in the Tray/Menu bar
|
||||||
|
setForceQuit()
|
||||||
|
autoUpdater.quitAndInstall(true, true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,8 +64,11 @@ if (isBetaVersion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let forceQuit = false
|
let forceQuit = false
|
||||||
export function quit() {
|
export function setForceQuit() {
|
||||||
forceQuit = true
|
forceQuit = true
|
||||||
|
}
|
||||||
|
export function quit() {
|
||||||
|
setForceQuit()
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +96,6 @@ async function createWindow() {
|
|||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
},
|
},
|
||||||
skipTaskbar: isWindows && CONFIG.get("settings.showInMenu"),
|
|
||||||
}, windowConfig))
|
}, windowConfig))
|
||||||
|
|
||||||
// maximize window if it was maximized last time
|
// maximize window if it was maximized last time
|
||||||
@ -125,6 +127,18 @@ async function createWindow() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
win.on("hide", () => {
|
||||||
|
if (isWindows && CONFIG.get("settings.showInMenu")) {
|
||||||
|
win.setSkipTaskbar(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
win.on("show", () => {
|
||||||
|
if (isWindows && CONFIG.get("settings.showInMenu")) {
|
||||||
|
win.setSkipTaskbar(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
nativeTheme.themeSource = CONFIG.get("theme")
|
nativeTheme.themeSource = CONFIG.get("theme")
|
||||||
|
|
||||||
if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
|
if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
|
||||||
@ -182,15 +196,25 @@ function registerGlobalHotkey() {
|
|||||||
if (win.isFocused()) {
|
if (win.isFocused()) {
|
||||||
if (!!app.hide) {
|
if (!!app.hide) {
|
||||||
// app.hide() only available on macOS
|
// app.hide() only available on macOS
|
||||||
|
// We want to use app.hide() so that the menu bar also gets changed
|
||||||
app?.hide()
|
app?.hide()
|
||||||
} else {
|
} else {
|
||||||
win.blur()
|
win.blur()
|
||||||
|
if (CONFIG.get("settings.showInMenu")) {
|
||||||
|
// if we're using a tray icon we want to completely hide the window
|
||||||
|
win.hide()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.focus({steal: true})
|
app.focus({steal: true})
|
||||||
if (win.isMinimized()) {
|
if (win.isMinimized()) {
|
||||||
win.restore()
|
win.restore()
|
||||||
}
|
}
|
||||||
|
if (!win.isVisible()) {
|
||||||
|
win.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
win.focus()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -218,9 +242,6 @@ function registerShowInMenu() {
|
|||||||
} else {
|
} else {
|
||||||
tray?.destroy()
|
tray?.destroy()
|
||||||
}
|
}
|
||||||
if (isWindows) {
|
|
||||||
win.setSkipTaskbar(CONFIG.get("settings.showInMenu"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(createWindow).then(async () => {
|
app.whenReady().then(createWindow).then(async () => {
|
||||||
@ -230,6 +251,11 @@ app.whenReady().then(createWindow).then(async () => {
|
|||||||
registerShowInMenu()
|
registerShowInMenu()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.on("before-quit", () => {
|
||||||
|
// if CMD+Q is pressed, we want to quit the app even if we're using a Menu/Tray icon
|
||||||
|
setForceQuit()
|
||||||
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
win = null
|
win = null
|
||||||
if (!isMac) app.quit()
|
if (!isMac) app.quit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user