From 72c83984a9930987989e66f84bd76cf3c4ef2850 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Sun, 31 Jul 2016 16:55:25 -0300 Subject: [PATCH] Auto Updater Fixed #127 --- app.js | 3 ++ app/Application.js | 89 ++++++++++++++++++++++++++-------------------- app/package.json | 2 +- electron/main.js | 2 +- electron/menu.js | 18 ++++++++-- package.json | 17 +++++---- 6 files changed, 80 insertions(+), 51 deletions(-) diff --git a/app.js b/app.js index 66de4636..6533a8d0 100644 --- a/app.js +++ b/app.js @@ -32,6 +32,9 @@ ipc.on('showAbout', function(event, message) { ipc.on('autoUpdater:checking-for-update:', function() { Ext.Msg.wait('Please wait...', 'Checking for update'); }); +ipc.on('autoUpdater:check-update', function() { + Rambox.app.checkUpdate(); +}); ipc.on('autoUpdater:update-not-available', function() { Ext.Msg.show({ title: 'You are up to date!' diff --git a/app/Application.js b/app/Application.js index f2844511..f2a126b4 100644 --- a/app/Application.js +++ b/app/Application.js @@ -126,45 +126,8 @@ Ext.define('Rambox.Application', { ] }); - if ( process.platform !== 'win32' && process.platform !== 'darwin' ) { - fireRef.database().ref('config').on('value', function(snapshot) { - var appVersion = new Ext.Version(require('electron').remote.app.getVersion()); - if ( appVersion.isLessThan(snapshot.val().latestVersion) ) { - console.info('New version is available', snapshot.val().latestVersion); - Ext.cq1('app-main').addDocked({ - xtype: 'toolbar' - ,dock: 'top' - ,ui: 'newversion' - ,items: [ - '->' - ,{ - xtype: 'label' - ,html: 'New version is available! ('+snapshot.val().latestVersion+')' - } - ,{ - xtype: 'button' - ,text: 'Download' - ,href: 'https://getrambox.herokuapp.com/download/'+process.platform+'_'+process.arch - } - ,{ - xtype: 'button' - ,text: 'Changelog' - ,href: 'https://github.com/saenzramiro/rambox/releases/tag/'+snapshot.val().latestVersion - } - ,'->' - ,{ - glyph: 'xf00d@FontAwesome' - ,baseCls: '' - ,style: 'cursor:pointer;' - ,handler: function(btn) { Ext.cq1('app-main').removeDocked(btn.up('toolbar'), true); } - } - ] - }); - return; - } - - console.info('Your version is the latest. No need to update.') - }); + if ( process.platform !== 'win32' ) { + this.checkUpdate(true); } if ( localStorage.getItem('locked') ) { @@ -184,4 +147,52 @@ Ext.define('Rambox.Application', { document.title = 'Rambox'; } } + + ,checkUpdate: function(silence) { + fireRef.database().ref('config').once('value', function(snapshot) { + var appVersion = new Ext.Version(require('electron').remote.app.getVersion()); + if ( appVersion.isLessThan(snapshot.val().latestVersion) ) { + console.info('New version is available', snapshot.val().latestVersion); + Ext.cq1('app-main').addDocked({ + xtype: 'toolbar' + ,dock: 'top' + ,ui: 'newversion' + ,items: [ + '->' + ,{ + xtype: 'label' + ,html: 'New version is available! ('+snapshot.val().latestVersion+')' + } + ,{ + xtype: 'button' + ,text: 'Download' + ,href: 'https://getrambox.herokuapp.com/download/'+process.platform+'_'+process.arch + } + ,{ + xtype: 'button' + ,text: 'Changelog' + ,href: 'https://github.com/saenzramiro/rambox/releases/tag/'+snapshot.val().latestVersion + } + ,'->' + ,{ + glyph: 'xf00d@FontAwesome' + ,baseCls: '' + ,style: 'cursor:pointer;' + ,handler: function(btn) { Ext.cq1('app-main').removeDocked(btn.up('toolbar'), true); } + } + ] + }); + return; + } else if ( !silence ) { + Ext.Msg.show({ + title: 'You are up to date!' + ,message: 'You have the latest version of Rambox.' + ,icon: Ext.Msg.INFO + ,buttons: Ext.Msg.OK + }); + } + + console.info('Your version is the latest. No need to update.'); + }); + } }); diff --git a/app/package.json b/app/package.json index 9ed1ec13..715fbbc2 100644 --- a/app/package.json +++ b/app/package.json @@ -1,7 +1,7 @@ { "name": "rambox", "productName": "Rambox", - "version": "0.4.1", + "version": "0.3.0", "description": "Free and Open Source messaging and emailing app that combines common web applications into one.", "main": "electron/main.js", "private": true, diff --git a/electron/main.js b/electron/main.js index ffb6c00a..e2a28c2a 100644 --- a/electron/main.js +++ b/electron/main.js @@ -132,7 +132,7 @@ function createWindow () { tray.create(mainWindow, mainWindowState); - if ( !isDev ) updater.initialize(mainWindow); + if ( !isDev && process.platform === 'win32' ) updater.initialize(mainWindow); mainWindow.on('page-title-updated', (e, title) => updateBadge(title)); diff --git a/electron/menu.js b/electron/menu.js index a73b6df7..75d7f0a1 100644 --- a/electron/menu.js +++ b/electron/menu.js @@ -309,6 +309,14 @@ if (process.platform === 'darwin') { tpl.unshift({ label: appName, submenu: [ + { + label: `Check for updates...`, + click(item, win) { + const webContents = win.webContents; + const send = webContents.send.bind(win.webContents); + send('autoUpdater:check-update'); + } + }, { label: `About ${appName}`, click() { @@ -387,9 +395,13 @@ if (process.platform === 'darwin') { click(item, win) { const webContents = win.webContents; const send = webContents.send.bind(win.webContents); - electron.autoUpdater.checkForUpdates(); - electron.autoUpdater.once('update-available', (event) => send('autoUpdater:update-available')); - electron.autoUpdater.once('update-not-available', (event) => send('autoUpdater:update-not-available')); + if ( process.platform === 'win32' ) { + electron.autoUpdater.checkForUpdates(); + electron.autoUpdater.once('update-available', (event) => send('autoUpdater:update-available')); + electron.autoUpdater.once('update-not-available', (event) => send('autoUpdater:update-not-available')); + } else { + send('autoUpdater:check-update'); + } } }); helpSubmenu.push({ diff --git a/package.json b/package.json index fe6af25b..8887212a 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "pack:linux32": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=linux --arch=ia32 --version=1.3.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=64-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite", "pack:linux64": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=linux --arch=x64 --version=1.3.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=64-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite", "build": "npm run build:linux && npm run build:osx && npm run build:win", - "build:osx": "build \"dist/Rambox-darwin-x64/Rambox.app\" --platform=osx", + "build:osx": "build --osx", "build:linux": "npm run build:linux32 && npm run build:linux64", "build:linux32": "build --linux --ia32", "build:linux64": "build --linux --x64", @@ -52,8 +52,15 @@ "schemes": ["rambox"] } ], + "mac": { + "target": [ + "default" + ], + "icon": "./resources/installer/Icon.icns" + }, "dmg": { "title": "Rambox", + "icon": "./resources/installer/Icon.icns", "icon-size": 128, "contents": [ { @@ -102,13 +109,9 @@ "devDependencies": { "asar": "^0.12.1", "bestzip": "^1.1.3", - "electron-builder": "5.17.0", - "electron-installer-windows": "^0.2.0", - "electron-packager": "7.3.0", + "electron-builder": "5.19.1", "electron-prebuilt": "1.3.1", - "electron-squirrel-startup": "^1.0.0", - "electron-winstaller": "^2.3.0", - "spectron": "^3.2.3" + "electron-squirrel-startup": "^1.0.0" }, "config": { "pre-git": {