diff --git a/electron/commands/auto-update.ts b/electron/commands/auto-update.ts new file mode 100644 index 0000000..320b9b7 --- /dev/null +++ b/electron/commands/auto-update.ts @@ -0,0 +1,25 @@ +import { MessageBoxOptions, dialog } from "electron"; +import { autoUpdater } from "electron-updater"; +import logit from "../utils/logit"; + +const autoUpdate = (event) => { + autoUpdater.autoInstallOnAppQuit = false; + const dialogOpts: MessageBoxOptions = { + type: "info", + buttons: ["Install update", "No Thanks"], + title: "New Upscayl Update", + message: event.releaseName as string, + detail: + "A new version has been downloaded. Restart the application to apply the updates.", + }; + logit("✅ Update Downloaded"); + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) { + autoUpdater.quitAndInstall(); + } else { + logit("🚫 Update Installation Cancelled"); + } + }); +}; + +export default autoUpdate; diff --git a/electron/index.ts b/electron/index.ts index a428345..ce0d738 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -1,14 +1,7 @@ import prepareNext from "electron-next"; import { autoUpdater } from "electron-updater"; import log from "electron-log"; -import { - app, - ipcMain, - dialog, - MessageBoxOptions, - protocol, - net, -} from "electron"; +import { app, ipcMain, protocol, net } from "electron"; import COMMAND from "./constants/commands"; import logit from "./utils/logit"; import openFolder from "./commands/open-folder"; @@ -23,6 +16,7 @@ import electronIsDev from "electron-is-dev"; import { execPath, modelsPath } from "./utils/get-resource-paths"; import batchUpscayl from "./commands/batch-upscayl"; import doubleUpscayl from "./commands/double-upscayl"; +import autoUpdate from "./commands/auto-update"; // INITIALIZATION log.initialize({ preload: true }); @@ -70,25 +64,4 @@ ipcMain.on(COMMAND.FOLDER_UPSCAYL, batchUpscayl); ipcMain.on(COMMAND.DOUBLE_UPSCAYL, doubleUpscayl); -//------------------------Auto-Update Code-----------------------------// -autoUpdater.autoInstallOnAppQuit = false; - -autoUpdater.on("update-downloaded", (event) => { - autoUpdater.autoInstallOnAppQuit = false; - const dialogOpts: MessageBoxOptions = { - type: "info", - buttons: ["Install update", "No Thanks"], - title: "New Upscayl Update", - message: event.releaseName as string, - detail: - "A new version has been downloaded. Restart the application to apply the updates.", - }; - logit("✅ Update Downloaded"); - dialog.showMessageBox(dialogOpts).then((returnValue) => { - if (returnValue.response === 0) { - autoUpdater.quitAndInstall(); - } else { - logit("🚫 Update Installation Cancelled"); - } - }); -}); +autoUpdater.on("update-downloaded", autoUpdate); diff --git a/electron/utils/get-resource-paths.ts b/electron/utils/get-resource-paths.ts index 4248de4..dbb6331 100644 --- a/electron/utils/get-resource-paths.ts +++ b/electron/utils/get-resource-paths.ts @@ -1,14 +1,14 @@ -/* - appRootDir is the resources directory inside the unpacked electron app temp directory. - resources contains app.asar file, that contains the main and renderer files. - We're putting resources/{os}/bin from project inside resources/bin of electron. Same for the models directory as well. -*/ - import { join, dirname, resolve } from "path"; import { getPlatform } from "./get-device-specs"; import isDev from "electron-is-dev"; import { app } from "electron"; +/** + * appRootDir is the resources directory inside the unpacked electron app temp directory. + * resources contains app.asar file, that contains the main and renderer files. + * We're putting resources/{os}/bin from project inside resources/bin of electron. + * Same for the models directory as well. + */ const appRootDir = app.getAppPath(); const binariesPath = isDev