Skip to content

Commit

Permalink
fix: updater should closes all window first
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Aug 2, 2024
1 parent 243f532 commit 7cb1a94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/flag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let shouldAppDoHide = process.platform === "darwin"

export const getShouldAppDoHide = () => shouldAppDoHide
export const setShouldAppDoHide = (value: boolean) => {
shouldAppDoHide = value
}
12 changes: 11 additions & 1 deletion src/main/updater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7cb1a94

Please sign in to comment.