Skip to content

Commit

Permalink
#2 automatic update check
Browse files Browse the repository at this point in the history
  • Loading branch information
Almenon committed Aug 29, 2017
1 parent 7d6726c commit e31b2ee
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
owner: Almenon
repo: AREPL
provider: github
10 changes: 10 additions & 0 deletions latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# update version & releaseDate when doing release
# and make sure path and artifact name matches the windows artifact
# for now you can ignore the sha, artifact, and path because i am just checking if update availible, not actually downloading
version: 1.0.0-alpha.3
releaseDate: '2017-08-28T19:52:36.263Z'
githubArtifactName: arepl-win32-x64.zip
path: arepl win32 x64
sha512: >-
BMLPuM/j+OnjrdefvLdvVRpRNla7zrgLFD2810T9zGncCr1zg0wzY82xY1vb6KpERYWJ3sI9VAOicmLqdxohEw==
sha2: 82c0d57aca2a2f175a136f7d5444a9fb8633968ec7df01277677cf5cdf03a191
36 changes: 35 additions & 1 deletion src/electron/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {app, Menu, BrowserWindow} = require('electron')
const { autoUpdater } = require("electron-updater");

const path = require('path')
const url = require('url')
Expand All @@ -7,6 +8,7 @@ const makeMenu = require('./makeMenu')
// 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 menuTemplate

//electron-context-menu necessary for menu upon right-click
require('electron-context-menu')({
Expand All @@ -23,7 +25,35 @@ function isDevMode(){
return isEnvSet ? getFromEnv : (process.defaultApp || /node_modules[\\/]electron[\\/]/.test(process.execPath));
}

/**
* if update-availible event fired handler will append menu item to download latest release
* i reccomend doing calling this after menu creation and before checking for update
*/
function registerAutoUpdateHandlers(){
autoUpdater.on('checking-for-update', () => {
console.log('Checking for update...');
});
autoUpdater.on('update-available', (info) => {
const updateAvailibleMenu = {
label: "New update availible",
submenu: [{
label: "release info",
click: () => { require('electron').shell.openExternal('https://github.com/Almenon/AREPL/releases') }
}]
}
menuTemplate.push(updateAvailibleMenu);
Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate));
});
autoUpdater.on('update-not-available', (info) => {
console.log('Update not available.');
});
autoUpdater.on('error', (err) => {
console.error(err);
});
}

function createWindow () {

// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
Expand All @@ -38,7 +68,11 @@ function createWindow () {
slashes: true
}));

makeMenu.makeMenu(mainWindow);
menuTemplate = makeMenu.makeMenu(mainWindow);

registerAutoUpdateHandlers();
autoUpdater.autoDownload = false;
autoUpdater.checkForUpdates();

if(isDevMode()){
mainWindow.webContents.openDevTools();
Expand Down
9 changes: 5 additions & 4 deletions src/electron/makeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ const helpSubmenu = [
{
label: 'Search or report a issue',
click () { require('electron').shell.openExternal('https://github.com/Almenon/AREPL/issues') }
},
{
label: 'Releases',
click () { require('electron').shell.openExternal('https://github.com/Almenon/AREPL/releases') }
}
];

Expand Down Expand Up @@ -46,6 +42,10 @@ const fileMenu = {
]
}

/**
* sets Application menu to custom AREPL menu
* @returns {object[]} menu template
*/
module.exports.makeMenu = function(mainWindow){
var template = defaultMenu();

Expand All @@ -63,4 +63,5 @@ module.exports.makeMenu = function(mainWindow){

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
return template;
}

0 comments on commit e31b2ee

Please sign in to comment.