mirror of
https://github.com/heyman/heynote.git
synced 2025-02-16 10:19:55 +01: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_CHECK_FOR_UPDATES,
|
||||
} from '../constants'
|
||||
import { setForceQuit } from "./index";
|
||||
|
||||
|
||||
// will reference the main window
|
||||
@ -62,7 +63,11 @@ ipcMain.handle(UPDATE_START_DOWNLOAD, () => {
|
||||
})
|
||||
|
||||
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
|
||||
export function quit() {
|
||||
export function setForceQuit() {
|
||||
forceQuit = true
|
||||
}
|
||||
export function quit() {
|
||||
setForceQuit()
|
||||
app.quit()
|
||||
}
|
||||
|
||||
@ -93,7 +96,6 @@ async function createWindow() {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: true,
|
||||
},
|
||||
skipTaskbar: isWindows && CONFIG.get("settings.showInMenu"),
|
||||
}, windowConfig))
|
||||
|
||||
// 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")
|
||||
|
||||
if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
|
||||
@ -182,15 +196,25 @@ function registerGlobalHotkey() {
|
||||
if (win.isFocused()) {
|
||||
if (!!app.hide) {
|
||||
// app.hide() only available on macOS
|
||||
// We want to use app.hide() so that the menu bar also gets changed
|
||||
app?.hide()
|
||||
} else {
|
||||
win.blur()
|
||||
if (CONFIG.get("settings.showInMenu")) {
|
||||
// if we're using a tray icon we want to completely hide the window
|
||||
win.hide()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
app.focus({steal: true})
|
||||
if (win.isMinimized()) {
|
||||
win.restore()
|
||||
}
|
||||
if (!win.isVisible()) {
|
||||
win.show()
|
||||
}
|
||||
|
||||
win.focus()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
@ -218,9 +242,6 @@ function registerShowInMenu() {
|
||||
} else {
|
||||
tray?.destroy()
|
||||
}
|
||||
if (isWindows) {
|
||||
win.setSkipTaskbar(CONFIG.get("settings.showInMenu"))
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(createWindow).then(async () => {
|
||||
@ -230,6 +251,11 @@ app.whenReady().then(createWindow).then(async () => {
|
||||
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', () => {
|
||||
win = null
|
||||
if (!isMac) app.quit()
|
||||
|
Loading…
Reference in New Issue
Block a user