Skip to content

Commit

Permalink
fix(electron): show a dialog when update available (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Jul 4, 2021
1 parent 26efc12 commit 16f5aa7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/electron/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app, Menu } from "electron"
import { app, dialog, Menu, shell } from "electron"
import type { UpdateInfo } from "electron-updater"

import { registerIpcHandlers } from "./api-main"
import { buildApplicationMenu } from "./application-menu"
Expand All @@ -9,19 +10,33 @@ import { createWindow, createWindowByOpeningFile, createWindowIfNotExist } from

async function setupAutoUpdate() {
if (env.IS_PROD) {
logger.log("current environment is production")
logger.log("current environment is production, checking update")

await app.whenReady()
await new Promise((resolve) => setTimeout(resolve, 1000))
try {
const { autoUpdater } = await import("electron-updater")
autoUpdater.logger = logger
await autoUpdater.checkForUpdatesAndNotify()
autoUpdater.autoDownload = false

autoUpdater.on("update-available", async ({ version }: UpdateInfo) => {
const result = await dialog.showMessageBox({
type: "question",
title: "New version available",
message: `Rino ${version} is now available. Would you like to download it now?`,
buttons: ["Download", "Remind Me Later"],
})
if (result.response === 0) {
shell.openExternal("https://github.com/ocavue/rino/releases")
}
})

await autoUpdater.checkForUpdates()
} catch (e) {
logger.error("failed to check updates:", e)
}
} else {
logger.log("current environment is not production")
logger.log("current environment is not production, skipping update")
}
}

Expand Down

0 comments on commit 16f5aa7

Please sign in to comment.