Skip to content

Commit

Permalink
Merge pull request #287 from justinlampley/AutoUpdate
Browse files Browse the repository at this point in the history
Enable Electron Auto Updater on Windows
jurgelenas authored Mar 4, 2022
2 parents 6ad1aa7 + 488d6f1 commit d15a1a9
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions src/main.dev.ts
Original file line number Diff line number Diff line change
@@ -146,6 +146,9 @@ const installExtensions = async () => {
});
};

const isWindows = process.platform.startsWith('win');
const isMacOS = process.platform.startsWith('darwin');

const createWindow = async () => {
if (
process.env.NODE_ENV === 'development' ||
@@ -231,8 +234,7 @@ const createWindow = async () => {
}
return item;
};
const isWindows = process.platform.startsWith('win');
const isMacOS = process.platform.startsWith('darwin');

if (isWindows) {
const portablePythonLocation = path.join(
dependenciesPath,
@@ -394,6 +396,58 @@ app.on('activate', () => {
}
});

autoUpdater.autoDownload = false;

autoUpdater.on('error', (error) => {
logger.error(error, error.stack);
});

autoUpdater.on('update-available', async () => {
const response = await dialog.showMessageBox(mainWindow!, {
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'Later'],
});

if (response.response === 0) {
logger.log('Downloading Update');
autoUpdater.downloadUpdate();
await dialog.showMessageBox(mainWindow!, {
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(mainWindow!, {
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());
}
});

app.on('ready', async () => {
// does not work in development and MacOS requires the application to be signed
if (process.env.NODE_ENV !== 'development' && !isMacOS) {
try {
await autoUpdater.checkForUpdates();
} catch (error) {
logger.error(error);
}
}
});

/*
Handle IPC requests from the User Interface
*/

0 comments on commit d15a1a9

Please sign in to comment.