diff --git a/dev-app-update.yml b/dev-app-update.yml new file mode 100644 index 0000000..8d23a0b --- /dev/null +++ b/dev-app-update.yml @@ -0,0 +1,3 @@ +owner: Almenon +repo: AREPL +provider: github \ No newline at end of file diff --git a/latest.yml b/latest.yml new file mode 100644 index 0000000..0731bc1 --- /dev/null +++ b/latest.yml @@ -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 \ No newline at end of file diff --git a/src/electron/main.js b/src/electron/main.js index e7b76f8..e2ff5b8 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -1,4 +1,5 @@ const {app, Menu, BrowserWindow} = require('electron') +const { autoUpdater } = require("electron-updater"); const path = require('path') const url = require('url') @@ -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')({ @@ -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, @@ -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(); diff --git a/src/electron/makeMenu.js b/src/electron/makeMenu.js index b33ef3f..0451643 100644 --- a/src/electron/makeMenu.js +++ b/src/electron/makeMenu.js @@ -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') } } ]; @@ -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(); @@ -63,4 +63,5 @@ module.exports.makeMenu = function(mainWindow){ const menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); + return template; } \ No newline at end of file