Skip to content

Commit

Permalink
Added automatic updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vj3k0 committed Jan 4, 2016
1 parent 21ca42a commit 67ec178
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Use Sinopia server

registry=http://localhost:4873

; Empty certificate for use with private NPM repo

ca=
67 changes: 52 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const updater = require('electron-updater');

// Keep reference of main window because of GC
var mainWindow = null;
Expand All @@ -13,25 +14,61 @@ app.on('window-all-closed', function() {
// When application is ready, create application window
app.on('ready', function() {

// Create main window
// Other options available at:
// http://electron.atom.io/docs/latest/api/browser-window/#new-browserwindow-options
mainWindow = new BrowserWindow({
name: "ea-todo",
width: 400,
height: 600,
toolbar: false
// Updater has checked dependencies and plugins and is ready to start
updater.on('ready', function() {

// Create main window
// Other options available at:
// http://electron.atom.io/docs/latest/api/browser-window/#new-browserwindow-options
mainWindow = new BrowserWindow({
name: "ea-todo",
width: 400,
height: 600,
toolbar: false
});

// Target HTML file which will be opened in window
mainWindow.loadURL('file://' + __dirname + "/app/index.html");

// Uncomment to use Chrome developer tools
// mainWindow.webContents.openDevTools({detach:true});

// Cleanup when window is closed
mainWindow.on('closed', function() {
mainWindow = null;
});

});

// Target HTML file which will be opened in window
mainWindow.loadURL('file://' + __dirname + "/app/index.html");
// This event is fired if your app is not currently valid at startup.
// The app must be exited immediately and the auto-updater will be run instead.
// After the auto-update runs the app will be re-run.
updater.on('update-required', function() {

// Uncomment to use Chrome developer tools
// mainWindow.webContents.openDevTools({detach:true});
app.quit();

// Cleanup when window is closed
mainWindow.on('closed', function() {
mainWindow = null;
});

// This event is fired after new versions of plugins have been downloaded and
// before the app and dependencies are downloaded. Plugins are installed side-by-side
// so they can be downloaded while the app is running.

// After the app is restarted it will watch for updates and fire the updated required
// event when newer versions are available.
updater.on('update-available', function() {

if(mainWindow) {
// Send a message to your view(s)
mainWindow.webContents.send('update-available');
}

});

// Instead of launching your window right away, start the updater
// to check to see if the app is valid or not.
// An app is invalid if any of its dependencies or plugins are missing.
// In this case the updater will begin a 'full' update. Once updated
// your app will be re-launched.
updater.start();

});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
},
"homepage": "https://github.com/Vj3k0/ea-todo#readme",
"dependencies": {
"electron-prebuilt": "^0.36.2"
"electron-plugins": "0.0.4",
"electron-prebuilt": "^0.36.2",
"electron-updater": "^0.3.0"
}
}

0 comments on commit 67ec178

Please sign in to comment.