Skip to content

Commit

Permalink
Improve update check dialogs and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjaeon committed Dec 9, 2024
1 parent 7487b1b commit d6c1734
Showing 1 changed file with 79 additions and 19 deletions.
98 changes: 79 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,63 @@
});

autoUpdater.on('error', (error) => {
dialog.showErrorMessage('Error updating the app', error);
dialog.showMessageBox({
type: 'error',
title: 'Update Error',
message: 'An error occurred while checking for updates.',
detail: error ? error.message : 'Unknown error'
});
});

autoUpdater.on('checking-for-update', () => {
// Checking for updates
dialog.showMessageBox({
type: 'info',
title: 'Checking for Updates',
message: 'Checking for new version...',
buttons: ['OK']
});
});

autoUpdater.autoDownload = false;
autoUpdater.on('update-available', () => {
const response = dialog.showMessageBoxSync({
dialog.showMessageBox({
type: 'info',
buttons: ['Update', 'Later'],
title: 'Update Available',
message: 'A new update is available. Do you want to update now?'
message: 'A new version is available. Would you like to update now?'
}).then(({ response }) => {
if (response === 0) {
autoUpdater.downloadUpdate();
}
});
if (response === 0) autoUpdater.downloadUpdate();
});

autoUpdater.on('update-downloaded', () => {
dialog.showMessageBoxSync({
dialog.showMessageBox({
type: 'info',
buttons: ['Restart'],
title: 'Update Ready',
message: 'Update downloaded. Application will restart to apply updates.'
message: 'Update has been downloaded. The application will now restart to install the update.'
}).then(() => {
autoUpdater.quitAndInstall();
});
autoUpdater.quitAndInstall();
});

autoUpdater.on('update-not-available', () => {
dialog.showMessageBoxSync({
dialog.showMessageBox({
type: 'info',
buttons: ['OK'],
title: 'No Updates',
message: 'No updates are available at the moment.'
message: 'You are running the latest version.'
});
});
} catch (error) {
dialog.showErrorMessage('Error setting up autoUpdater', error);
dialog.showMessageBox({
type: 'error',
title: 'Update Error',
message: 'An error occurred while setting up the auto updater.',
detail: error ? error.message : 'Unknown error'
});
}

const exec = code => gemini.webContents.executeJavaScript(code),
Expand Down Expand Up @@ -115,12 +134,22 @@
});

gemini.loadFile('src/index.html').catch(error => {
dialog.showErrorMessage('Error loading index.html', error);
dialog.showMessageBox({
type: 'error',
title: 'Error loading index.html',
message: 'Failed to load index.html.',
detail: error ? error.message : 'Unknown error'
});
});

gemini.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url).catch(error => {
dialog.showErrorMessage('Error opening external URL', error);
dialog.showMessageBox({
type: 'error',
title: 'Error opening external URL',
message: 'Failed to open external URL.',
detail: error ? error.message : 'Unknown error'
});
});
return { action: 'deny' };
});
Expand Down Expand Up @@ -161,14 +190,25 @@
{
label: 'About (GitHub)',
click: () => shell.openExternal('https://github.com/nekupaw/gemini-desktop/').catch(error => {
dialog.showErrorMessage('Error opening GitHub page', error);
dialog.showMessageBox({
type: 'error',
title: 'Error opening GitHub page',
message: 'Failed to open GitHub page.',
detail: error ? error.message : 'Unknown error'
});
})
},
{
label: 'Check for Updates',
click: () => {
autoUpdater.checkForUpdates().catch(error => {
dialog.showErrorMessage('Error checking for updates', error);
dialog.showMessageBox({
type: 'error',
title: 'Update Check Failed',
message: 'Failed to check for updates.',
detail: error ? error.message : 'Unknown error',
buttons: ['OK']
});
});
}
},
Expand All @@ -189,7 +229,12 @@
}
});
dialog.loadFile('components/setKeybindingsOverlay/index.html').catch(error => {
dialog.showErrorMessage('Error loading setKeybindingsOverlay', error);
dialog.showMessageBox({
type: 'error',
title: 'Error loading setKeybindingsOverlay',
message: 'Failed to load setKeybindingsOverlay.',
detail: error ? error.message : 'Unknown error'
});
});
dialog.show();
}
Expand All @@ -216,7 +261,12 @@
tray.setContextMenu(contextMenu);
tray.on('click', () => toggleVisibility(true));
} catch (error) {
dialog.showErrorMessage('Error creating tray', error);
dialog.showMessageBox({
type: 'error',
title: 'Error creating tray',
message: 'Failed to create tray.',
detail: error ? error.message : 'Unknown error'
});
}
};

Expand All @@ -226,9 +276,19 @@
createWindow();
registerKeybindings();
} catch (error) {
dialog.showErrorMessage('Error during app initialization', error);
dialog.showMessageBox({
type: 'error',
title: 'Error during app initialization',
message: 'Failed to initialize the application.',
detail: error ? error.message : 'Unknown error'
});
}
}).catch(error => {
dialog.showErrorMessage('Error during app initialization', error);
dialog.showMessageBox({
type: 'error',
title: 'Error during app initialization',
message: 'Failed to initialize the application.',
detail: error ? error.message : 'Unknown error'
});
});
})();

0 comments on commit d6c1734

Please sign in to comment.