Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(auto-updater): ask user before updating alva
Browse files Browse the repository at this point in the history
fix #168
  • Loading branch information
Lasse Küchler authored and lkuechler committed Jan 13, 2018
1 parent 7f8ce94 commit 38c7766
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
64 changes: 48 additions & 16 deletions src/electron/auto-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,60 @@ import { BrowserWindow, dialog } from 'electron';
import { autoUpdater } from 'electron-updater';

// autoUpdater.logger = log;
let showUpdateNotAvailable = false;
let window: BrowserWindow;

export function checkForUpdates(win: BrowserWindow): void {
export function checkForUpdates(win: BrowserWindow, updateNotAvailable?: boolean): void {
autoUpdater.autoDownload = false;
showUpdateNotAvailable = updateNotAvailable || false;
window = win;
autoUpdater.checkForUpdatesAndNotify().catch(() => {
dialog.showErrorBox('Check for Updates', 'Error while checking for updates');
});
}

autoUpdater.on('update-available', info => {
dialog.showMessageBox({ message: `There is a new Alva version: ${info.version}` });
});
autoUpdater.on('update-available', info => {
dialog.showMessageBox(
{
type: 'info',
message: `There is a new version available: ${
info.version
} \nShould Alva download the update?`,
buttons: ['yes', 'no']
},
buttonIndex => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate().catch(() => {
dialog.showErrorBox(
'Check for Updates',
'An error occured while updating. Please try again manually'
);
});
}
}
);
});

autoUpdater.on('error', () => {
dialog.showErrorBox('Check for Updates', 'Error on receiving update. Please try manually');
});
autoUpdater.on('update-not-available', info => {
if (showUpdateNotAvailable) {
dialog.showMessageBox({ message: 'Alva is up-to-date.' });
}
});

autoUpdater.on('download-progress', progressObj => {
win.setProgressBar(progressObj.percent / 100);
});
autoUpdater.on('error', () => {
dialog.showErrorBox(
'Check for Updates',
'An error occured while updating. Please try again manually'
);
});

autoUpdater.on('update-downloaded', info => {
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart' });
autoUpdater.on('download-progress', progressObj => {
window.setProgressBar(progressObj.percent / 100);
});

// remove progress bar
win.setProgressBar(-1);
});
}
autoUpdater.on('update-downloaded', info => {
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart' });

// remove progress bar
window.setProgressBar(-1);
});
4 changes: 2 additions & 2 deletions src/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function createWindow(): void {
console.warn('An error occurred: ', err);
});
}
checkForUpdates(win);
checkForUpdates(win, false);
}

const log = require('electron-log');
Expand Down Expand Up @@ -88,6 +88,6 @@ app.on('activate', () => {

ipcMain.on('request-check-for-updates', () => {
if (win) {
checkForUpdates(win);
checkForUpdates(win, true);
}
});

0 comments on commit 38c7766

Please sign in to comment.