From 610a3bf2b27dde8efbd772ffcec8f66185a626db Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Fri, 3 Feb 2017 11:18:02 -0700 Subject: [PATCH] Improve logging --- main.js | 38 +++++++++++++++++--------------------- package.json | 2 +- version.html | 11 +++++++++++ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/main.js b/main.js index 27ed04b..b254d1a 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ // Copyright (c) The LHTML team // See LICENSE for details. -const {app, BrowserWindow, Menu, protocol} = require('electron'); +const {app, BrowserWindow, Menu, protocol, ipcMain} = require('electron'); const log = require('electron-log'); const {autoUpdater} = require("electron-updater"); @@ -45,6 +45,7 @@ if (process.platform === 'darwin') { let win; function createDefaultWindow() { win = new BrowserWindow(); + win.webContents.openDevTools(); win.on('closed', () => { win = null; }); @@ -61,45 +62,40 @@ app.on('ready', function() { }); app.on('window-all-closed', () => { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit(); - } -}); - -app.on('activate', () => { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) { - createDefaultWindow(); - } + app.quit(); }); +function sendStatus(text) { + log.info(text); + win.webContents.send('message', text); +} //------------------------------------------------------------------- // Auto updates //------------------------------------------------------------------- autoUpdater.on('checking-for-update', (ev) => { - console.log('Checking for update...'); + sendStatus('Checking for update...'); }) autoUpdater.on('update-available', (ev) => { - console.log('Update available.'); + sendStatus('Update available.'); }) autoUpdater.on('update-not-available', (ev) => { - console.log('Update not available.'); + sendStatus('Update not available.'); }) autoUpdater.on('error', (ev) => { - console.log('Error in auto-updater.'); + sendStatus('Error in auto-updater.'); }) autoUpdater.on('download-progress', (ev) => { - console.log('Download progress...'); + sendStatus('Download progress...'); }) autoUpdater.on('update-downloaded', (ev, releaseNotes, releaseName, releaseDate, updateURL) => { - console.log('Update downloaded. Will quit and install in 5 seconds.'); + sendStatus('Update downloaded. Will quit and install in 5 seconds.'); // Wait 5 seconds, then quit and install setTimeout(function() { autoUpdater.quitAndInstall(); }, 5000) }) -autoUpdater.checkForUpdates() \ No newline at end of file +// Wait a second for the window to exist before checking for updates. +setTimeout(function() { + autoUpdater.checkForUpdates() +}, 1000); diff --git a/package.json b/package.json index c1675a5..a7b09c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electron-updater-example", - "version": "0.2.0", + "version": "0.2.1", "main": "main.js", "description": "electron-updater example project", "author": "Matt Haggard", diff --git a/version.html b/version.html index 12c1d60..d104eab 100644 --- a/version.html +++ b/version.html @@ -5,9 +5,20 @@ Current version: vX.Y.Z +
\ No newline at end of file