Skip to content

Commit

Permalink
add auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
doviettung96 committed Jun 26, 2017
1 parent 0af3816 commit 26a117c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
52 changes: 52 additions & 0 deletions autoupdater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* updater.js
*
* Please use manual update only when it is really required, otherwise please use recommended non-intrusive auto update.
*
* Import steps:
* 1. create `updater.js` for the code snippet
* 2. require `updater.js` for menu implementation, and set `checkForUpdates` callback from `updater` for the click property of `Check Updates...` MenuItem.
*/
const dialog = require('electron').dialog;
const autoUpdater = require('electron-updater').autoUpdater;

autoUpdater.autoDownload = false

autoUpdater.on('error', (event, error) => {
dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString())
})

autoUpdater.on('update-available', () => {
dialog.showMessageBox({
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate()
}
})
})

autoUpdater.on('update-not-available', () => {
dialog.showMessageBox({
title: 'No Updates',
message: 'Current version is up-to-date.'
})
})

autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox({
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...'
}, () => {
autoUpdater.quitAndInstall()
})
})

// export this to MenuItem click callback
function checkForUpdates () {
autoUpdater.checkForUpdates()
}
module.exports.checkForUpdates = checkForUpdates
16 changes: 5 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
require('./route');
require('./autoupdater');
const electron = require("electron");
const isDev = require("electron-is-dev");
// Module to control application life.

const app = electron.app;
const autoUpdater = require('electron-updater').autoUpdater;
const autoUpdater = require('./autoupdater');

// initialize ejs parser

// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const url = require("url");

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let updaterError = false;
// this part is for autoupdater
const updateFeed = "https://github.com/doviettung96/TungDV_Node_Express_EJS_Mysql/releases";

autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall();
})
autoUpdater.on("error", (ev, err) => {
updaterError = true;
});


// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down Expand Up @@ -73,7 +66,6 @@ let createWindow = function () {
mainWindow.focus();

// Open the DevTools.
if(updaterError)
mainWindow.webContents.openDevTools();

// Emitted when the window is closed.
Expand All @@ -84,3 +76,5 @@ let createWindow = function () {
mainWindow = null;
});
};


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Node-Express-EJS-Mysql",
"version": "1.0.9",
"version": "1.0.10",
"description": "A simple app with Node-Express-EJS-Mysql",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 26a117c

Please sign in to comment.