diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..67c4342 --- /dev/null +++ b/.npmrc @@ -0,0 +1,7 @@ +; Use Sinopia server + + registry=http://localhost:4873 + +; Empty certificate for use with private NPM repo + + ca= \ No newline at end of file diff --git a/main.js b/main.js index 5a8db2a..90633b4 100644 --- a/main.js +++ b/main.js @@ -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; @@ -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(); + }); \ No newline at end of file diff --git a/package.json b/package.json index 83f6195..c1e2d7c 100644 --- a/package.json +++ b/package.json @@ -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" } }