From 2c39b6b5a632d28c3a88473dd0231dec70a8e06b Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Sun, 25 Jan 2026 23:06:11 +0100 Subject: [PATCH] Add auto updater code --- src/main/index.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 06e06b4..9f55806 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,11 +1,16 @@ -import { app, shell, BrowserWindow, ipcMain } from 'electron' +import { app, shell, BrowserWindow, ipcMain, Notification } from 'electron' import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import icon from '../../resources/icon.png?asset' +import { autoUpdater } from 'electron-updater' +autoUpdater.autoDownload = false; +autoUpdater.autoInstallOnAppQuit = true; + +let mainWindow; function createWindow(): void { // Create the browser window. - const mainWindow = new BrowserWindow({ + mainWindow = new BrowserWindow({ width: 900, height: 670, show: false, @@ -59,6 +64,8 @@ app.whenReady().then(() => { // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) + + checkForUpdates(); }) // Quit when all windows are closed, except on macOS. There, it's common @@ -72,3 +79,39 @@ app.on('window-all-closed', () => { // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. +function showNotification(value: any) { + new Notification({ + title: value, + }).show() +} + +function checkForUpdates() { + autoUpdater.checkForUpdates(); + console.log(`Checking for updates. Current version ${app.getVersion()}`); + showNotification(`Checking for updates. Current version ${app.getVersion()}`); +} + +/*New Update Available*/ +autoUpdater.on("update-available", () => { + console.log(`Update available. Current version ${app.getVersion()}`); + showNotification(`Update available. Current version ${app.getVersion()}`); + let pth = autoUpdater.downloadUpdate(); + console.log(pth); + showNotification(pth); +}); + +autoUpdater.on("update-not-available", () => { + console.log(`No update available. Current version ${app.getVersion()}`); + showNotification(`No update available. Current version ${app.getVersion()}`); +}); + +/*Download Completion Message*/ +autoUpdater.on("update-downloaded", () => { + console.log(`Update downloaded. Current version ${app.getVersion()}`); + showNotification(`Update downloaded. Current version ${app.getVersion()}`); +}); + +autoUpdater.on("error", (info) => { + console.log(info); + showNotification(info); +}); \ No newline at end of file