Skip to content

Commit

Permalink
feat: add logging messages to update lifecycle checks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwinter committed Oct 26, 2020
1 parent 1247f1f commit c3fbad9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ class ElectronAutoUpdate {
checkFrequency: 1000 * 60 * 60,
electronUpdater,
dialog,
logger: {
info: () => {}
},
...options
};

if (this.options.logger) {
if (options.logger) {
this.options.electronUpdater.autoUpdater.logger = this.options.logger;
}
}
Expand All @@ -27,10 +30,19 @@ class ElectronAutoUpdate {
return this.options.dialog;
}

get logger() {
return this.options.logger;
}

async checkForUpdates() {
this.logger.info('Checking for updates');

this.autoUpdater.on('update-downloaded', async () => this.updateDownloaded());

this.autoUpdater.on('update-not-available', () => {
this.logger.info('Update not currently available');
this.logger.info(`Will check again in ${this.checkFrequency} milliseconds`);

setTimeout(() => {
this.autoUpdater.checkForUpdatesAndNotify();
}, this.checkFrequency);
Expand All @@ -40,13 +52,21 @@ class ElectronAutoUpdate {
}

async updateDownloaded() {
this.logger.info('An update has been downloaded and is ready to install');

const {response, checkboxChecked} = await this.showDownloadReadyDialog();

if (response === 0) {
this.logger.info('Quitting the app and installing update now');

this.autoUpdater.quitAndInstall();

return;
}

if (checkboxChecked) {
this.logger.info('Will remind later to install update');

setTimeout(() => {
this.autoUpdater.checkForUpdatesAndNotify();
}, this.checkFrequency);
Expand Down
5 changes: 5 additions & 0 deletions showcase-dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ app.whenReady().then(() => {
onQuit: app.quit,
downloadAvailableIn: 5000
})
},
logger: {
info: message => {
console.log(`electron-auto-update: ${message}`);
}
}
});

Expand Down

0 comments on commit c3fbad9

Please sign in to comment.