From c3fbad916f6a931e02330743baf183c9cf16cc8f Mon Sep 17 00:00:00 2001 From: David Winter Date: Mon, 26 Oct 2020 22:55:09 +0000 Subject: [PATCH] feat: add logging messages to update lifecycle checks --- index.js | 22 +++++++++++++++++++++- showcase-dialogs.js | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0c5e375..72ff269 100644 --- a/index.js +++ b/index.js @@ -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; } } @@ -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); @@ -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); diff --git a/showcase-dialogs.js b/showcase-dialogs.js index 31d7237..911de2b 100644 --- a/showcase-dialogs.js +++ b/showcase-dialogs.js @@ -18,6 +18,11 @@ app.whenReady().then(() => { onQuit: app.quit, downloadAvailableIn: 5000 }) + }, + logger: { + info: message => { + console.log(`electron-auto-update: ${message}`); + } } });