diff --git a/package.json b/package.json index 0e8b8a5e4..5b86d62bd 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ }, "dependencies": { "cli": "^1.0.1", + "electron-log": "^2.2.12", "electron-updater": "^2.17.6", "fs-extra": "^5.0.0", "js-yaml": "^3.10.0", diff --git a/src/electron/index.html b/src/electron/index.html index 13ead5288..dd617bc67 100644 --- a/src/electron/index.html +++ b/src/electron/index.html @@ -1,8 +1,15 @@ +
- \ No newline at end of file + diff --git a/src/electron/index.ts b/src/electron/index.ts index b912bf77b..7f2bdb28c 100644 --- a/src/electron/index.ts +++ b/src/electron/index.ts @@ -1,4 +1,4 @@ -import { app, BrowserWindow } from 'electron'; +import { app, BrowserWindow, dialog } from 'electron'; import { autoUpdater } from 'electron-updater'; import * as PathUtils from 'path'; import * as url from 'url'; @@ -51,12 +51,56 @@ function createWindow(): void { console.warn('An error occurred: ', err); }); } + + autoUpdater.checkForUpdatesAndNotify().catch(() => { + sendStatusToWindow('Error in auto-updater.'); + }); } +function sendStatusToWindow(text: string): void { + if (win) { + win.webContents.send('message', text); + } +} + +const log = require('electron-log'); +log.transports.file.level = 'info'; +autoUpdater.logger = log; +log.info('App starting...'); + +autoUpdater.on('checking-for-update', info => { + sendStatusToWindow('Checking for update...'); +}); + +autoUpdater.on('update-available', info => { + sendStatusToWindow('Update available.'); + dialog.showMessageBox({ message: `There is a new Alva version: ${info.version}` }); +}); + +autoUpdater.on('update-not-available', info => { + sendStatusToWindow('Update not available.'); +}); + +autoUpdater.on('error', err => { + sendStatusToWindow(`Error in auto-updater. ${err}`); +}); + +autoUpdater.on('download-progress', progressObj => { + let log_message = `Download speed: ${progressObj.bytesPerSecond}`; + log_message = `${log_message} - Downloaded ${progressObj.percent}%`; + log_message = `${log_message} (${progressObj.transferred}/${progressObj.total})`; + sendStatusToWindow(log_message); +}); + +autoUpdater.on('update-downloaded', info => { + sendStatusToWindow('Update downloaded'); +}); // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on('ready', createWindow); +app.on('ready', () => { + createWindow(); +}); // Quit when all windows are closed. app.on('window-all-closed', () => { @@ -72,9 +116,5 @@ app.on('activate', () => { // dock icon is clicked and there are no other windows open. if (!win) { createWindow(); - // tslint:disable-next-line:no-any - autoUpdater.checkForUpdatesAndNotify().catch((e: any) => { - console.log('There was a error:', e); - }); } }); diff --git a/src/resources/icon.icns b/src/resources/icon.icns index 89888cb6a..a57e6c43c 100644 Binary files a/src/resources/icon.icns and b/src/resources/icon.icns differ