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

Commit

Permalink
feat(update): add notification when there is a new version and try to…
Browse files Browse the repository at this point in the history
… auto update
  • Loading branch information
Lasse Küchler authored and lkuechler committed Dec 18, 2017
1 parent 236a5f4 commit 32c259c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/electron/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<html>

<body>
<script>
const { ipcRenderer } = require('electron');

ipcRenderer.on('message', function (event, text) {
console.log('auto-updater message:', text);
})
</script>
<div id="app"></div>
<script>require('../../build/component/app.js')</script>
</body>

</html>
</html>
52 changes: 46 additions & 6 deletions src/electron/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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);
});
}
});
Binary file modified src/resources/icon.icns
Binary file not shown.

0 comments on commit 32c259c

Please sign in to comment.