Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Electron Auto Updater on Windows #287

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions src/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
*/
Expand Down