fix: updater should closes all window first

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-08-02 10:21:19 +08:00
parent 243f532ccc
commit 7cb1a94a15
3 changed files with 19 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
let shouldAppDoHide = process.platform === "darwin"
export const getShouldAppDoHide = () => shouldAppDoHide
export const setShouldAppDoHide = (value: boolean) => {
shouldAppDoHide = value
}
+11 -1
View File
@@ -2,6 +2,7 @@ import { getRendererHandlers } from "@egoist/tipc/main"
import { autoUpdater } from "electron-updater"
import { channel, isDev } from "../env"
import { setShouldAppDoHide } from "../flag"
import { trackEvent } from "../lib/posthog"
import { logger } from "../logger"
import type { RendererHandlers } from "../renderer-handlers"
@@ -12,7 +13,16 @@ import { CustomGitHubProvider } from "./custom-github-provider"
const disabled = isDev
export const quitAndInstall = async () => {
autoUpdater.quitAndInstall()
setShouldAppDoHide(false)
const mainWindow = getMainWindow()
logger.info("Quit and install update, close main window, ", mainWindow?.id)
mainWindow?.close()
setTimeout(() => {
logger.info("Window is closed, quit and install update")
autoUpdater.quitAndInstall()
}, 1000)
}
let downloading = false
+2 -1
View File
@@ -6,6 +6,7 @@ import { callGlobalContextMethod } from "@shared/bridge"
import type { BrowserWindowConstructorOptions } from "electron"
import { BrowserWindow, Menu, shell } from "electron"
import { getShouldAppDoHide } from "./flag"
import { getIconPath } from "./helper"
import { store } from "./lib/store"
import { logger } from "./logger"
@@ -203,7 +204,7 @@ export const createMainWindow = () => {
windows.mainWindow = window
window.on("close", (event) => {
if (process.platform === "darwin") {
if (process.platform === "darwin" && getShouldAppDoHide()) {
event.preventDefault()
window.hide()
} else {