Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
iffy committed Feb 3, 2017
1 parent 1fdc75e commit 610a3bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
38 changes: 17 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -45,6 +45,7 @@ if (process.platform === 'darwin') {
let win;
function createDefaultWindow() {
win = new BrowserWindow();
win.webContents.openDevTools();
win.on('closed', () => {
win = null;
});
Expand All @@ -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()
// Wait a second for the window to exist before checking for updates.
setTimeout(function() {
autoUpdater.checkForUpdates()
}, 1000);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 11 additions & 0 deletions version.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
</head>
<body>
Current version: <span id="version">vX.Y.Z</span>
<div id="messages"></div>
<script>
// Display the current version
let version = window.location.hash.substring(1);
document.getElementById('version').innerText = version;

// Listen for messages
const {ipcRenderer} = require('electron');
ipcRenderer.on('message', function(event, text) {
var container = document.getElementById('messages');
var message = document.createElement('div');
message.innerHTML = text;
container.appendChild(message);
})
</script>
</body>
</html>

0 comments on commit 610a3bf

Please sign in to comment.