Skip to content

Commit b2ff2ff

Browse files
🚀 feat: enhance auto-updater with forced updates and error handling
Refined the auto-update feature in the Electron app to support forced updates and improved error logging, ensuring users have the latest, most secure version. - Introduced a check for required updates using a regex match on the release name, enabling forced updates for critical releases. - Implemented enhanced error logging with Sentry, including specific tags and extra context for better troubleshooting. - Modified update download and installation flow to prompt the user for installation, with a special case for forced updates leading to immediate application restart and update installation.
1 parent e575df1 commit b2ff2ff

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

‎apps/desktop/electron/main.ts‎

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,29 @@ function createWindow() {
970970
}
971971

972972
// Auto Updater
973-
autoUpdater.on('update-available', () => {
974-
mainWindow?.webContents.send('set-window', 'update', 'Update available.');
973+
let forcedUpdate = false;
974+
975+
autoUpdater.on('update-available', (updateInfo) => {
976+
// If release is required, force the update
977+
const isForcedUpdateRequired = /\[REQUIRED\]/.test(updateInfo.releaseName || "");
978+
if (isForcedUpdateRequired) {
979+
forcedUpdate = true;
980+
mainWindow?.webContents.send('set-window', 'update', 'Update available.');
981+
}
982+
logger.info('Update available. Downloading...');
975983
})
984+
976985
autoUpdater.on('error', (err) => {
977-
mainWindow?.webContents.send('set-window', 'update', 'Error in auto-updater. You may need to reinstall ScreenLink. \n Contact support if this continues. \n' + err);
986+
Sentry.captureException(err, {
987+
tags: { module: "autoUpdater", forcedUpdate },
988+
extra: { error: err }
989+
});
990+
if (!forcedUpdate) return;
991+
mainWindow?.webContents.send('set-window', 'update', 'Error in auto-updater. You may need to reinstall ScreenLink. \n Contact support if this continues (support@screenlink.io) \n \n \n' + err);
978992
})
993+
979994
autoUpdater.on('download-progress', (progressObj) => {
995+
if (!forcedUpdate) return;
980996
let downloadSpeedInMBps = (progressObj.bytesPerSecond / (1024 * 1024)).toFixed(2);
981997
let transferredInMB = (progressObj.transferred / (1024 * 1024)).toFixed(2);
982998
let totalInMB = (progressObj.total / (1024 * 1024)).toFixed(2);
@@ -985,10 +1001,32 @@ function createWindow() {
9851001
log_message = log_message + ' (' + transferredInMB + "MB/" + totalInMB + 'MB)';
9861002
mainWindow?.webContents.send('set-window', 'update', log_message);
9871003
})
1004+
9881005
autoUpdater.on('update-downloaded', () => {
989-
mainWindow?.webContents.send('set-window', 'main');
1006+
if (forcedUpdate) {
1007+
autoUpdater.quitAndInstall();
1008+
} else {
1009+
1010+
// Prompt user to install the update
1011+
dialog.showMessageBox({
1012+
type: 'info',
1013+
title: 'Update Ready',
1014+
message: 'New version downloaded. Install now?',
1015+
buttons: ['Yes', 'Later']
1016+
}).then(result => {
1017+
// If user agrees, quit and install the update
1018+
if (result.response === 0) {
1019+
autoUpdater.quitAndInstall();
1020+
}
1021+
}).catch(error => {
1022+
logger.error('Error prompting update installation:', error);
1023+
Sentry.captureException(error);
1024+
});
1025+
}
9901026
});
9911027

1028+
1029+
9921030
const iconPath = path.join(process.env.VITE_PUBLIC, 'tray-icon.png');
9931031
let icon = nativeImage.createFromPath(iconPath);
9941032
icon = icon.resize({

0 commit comments

Comments
 (0)