Added auto update

This commit is contained in:
2022-06-13 22:38:35 +02:00
parent 999b90e54d
commit 7c9ed18252
3 changed files with 48 additions and 14 deletions

View File

@@ -1,6 +1,51 @@
import {app, BrowserWindow} from 'electron';
import {app, BrowserWindow, dialog} from 'electron';
import {initialize as remoteInitialize, enable as remoteEnable} from '@electron/remote/main';
import path from 'path';
import { autoUpdater } from "electron-updater";
import logger from 'electron-log';
logger.transports.console.format = "{h}:{i}:{s} {text}";
logger.transports.file.getFile();
logger.transports.file.resolvePath = () => path.join(app.getPath('userData'), "logs", "start.log");
autoUpdater.autoDownload = false;
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('update-available', async () => {
const response = await dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'Found updates, do you want update now?',
buttons: ['Yes', 'Later'],
});
if (response.response === 0) {
logger.log('Downloading Update');
autoUpdater.downloadUpdate();
await dialog.showMessageBox({
type: 'info',
title: 'Update Downloading',
message:
'Update is being downloaded, you will be notified when it is ready to install',
buttons: [],
});
}
});
autoUpdater.on('update-downloaded', async () => {
const response = await dialog.showMessageBox({
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: 'Update',
detail:
'A new version has been downloaded. Restart the application to apply the updates.',
});
if (response.response === 0) {
setImmediate(() => autoUpdater.quitAndInstall());
}
});
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {