Skip to content

Commit

Permalink
feat: Add auto-updater
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-wtt committed Mar 19, 2024
1 parent 73c50fd commit a77c0e4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 22 deletions.
100 changes: 78 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"dependencies": {
"@electron/remote": "^2.1.2",
"@quasar/extras": "^1.16.9",
"electron-log": "^5.1.2",
"electron-updater": "^6.1.8",
"events": "^3.3.0",
"pinia": "^2.1.7",
"quasar": "^2.15.0",
Expand Down
19 changes: 19 additions & 0 deletions src-electron/electron-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import initAppApiHandler from 'app/src-electron/appAPI/main';
import path from 'path';
import os from 'os';
import { fileURLToPath } from 'node:url';
import log from 'electron-log';
import electronUpdater, { type AppUpdater } from 'electron-updater';

// needed in case process is undefined under Linux
const platform = process.platform || os.platform();

const currentDir = fileURLToPath(new URL('.', import.meta.url));

log.initialize();

function getPreloadPath(name: string): string {
return path.resolve(
currentDir,
Expand Down Expand Up @@ -95,10 +99,25 @@ function createWindow() {
});
}

export function getAutoUpdater(): AppUpdater {
// Using destructuring to access autoUpdater due to the CommonJS module of 'electron-updater'.
// It is a workaround for ESM compatibility issues, see https://github.com/electron-userland/electron-builder/issues/7976.
const { autoUpdater } = electronUpdater;
return autoUpdater;
}

const startAutoUpdater = () => {
const autoUpdater = getAutoUpdater();
autoUpdater.logger = log;
autoUpdater.checkForUpdatesAndNotify();
};

app.whenReady().then(() => {
initAppApiHandler();
initWindowApiHandler();
createWindow();

startAutoUpdater();
});

app.on('window-all-closed', () => {
Expand Down

0 comments on commit a77c0e4

Please sign in to comment.