diff --git a/app/background-process/browser.js b/app/background-process/browser.js index 7e1b38a8d9..11ae7dbb12 100644 --- a/app/background-process/browser.js +++ b/app/background-process/browser.js @@ -1,4 +1,5 @@ -import {app, dialog, autoUpdater, BrowserWindow, webContents, ipcMain, shell} from 'electron' +import {app, dialog, BrowserWindow, webContents, ipcMain, shell} from 'electron' +import {autoUpdater} from 'electron-updater' import os from 'os' import path from 'path' import fs from 'fs' @@ -29,13 +30,13 @@ const UPDATER_STATUS_DOWNLOADED = 'downloaded' // globals // = +// dont automatically check for updates (need to respect user preference) +autoUpdater.autoDownload = false + // what's the updater doing? var updaterState = UPDATER_STATUS_IDLE var updaterError = false // has there been an error? -// is the updater available? must be on certain platform, and may be disabled if there's an error -var isBrowserUpdatesSupported = (os.platform() == 'darwin' || os.platform() == 'win32') - // where is the user in the setup flow? var userSetupStatus = false var userSetupStatusLookupPromise @@ -49,13 +50,13 @@ var browserEvents = new EventEmitter() export function setup () { // setup auto-updater try { - if (!isBrowserUpdatesSupported) { throw new Error('Disabled. Only available on macOS and Windows.') } - autoUpdater.setFeedURL(getAutoUpdaterFeedURL()) - autoUpdater.once('update-available', onUpdateAvailable) + autoUpdater.setFeedURL(getAutoUpdaterFeedSettings()) + autoUpdater.on('update-available', onUpdateAvailable) + autoUpdater.on('update-not-available', onUpdateNotAvailable) + autoUpdater.on('update-downloaded', onUpdateDownloaded) autoUpdater.on('error', onUpdateError) } catch (e) { debug('[AUTO-UPDATE] error', e.toString()) - isBrowserUpdatesSupported = false } setTimeout(scheduledAutoUpdate, 15e3) // wait 15s for first run @@ -165,7 +166,7 @@ export function getInfo () { nodeVersion: process.versions.node, platform: os.platform(), updater: { - isBrowserUpdatesSupported, + isBrowserUpdatesSupported: true, error: updaterError, state: updaterState }, @@ -175,62 +176,19 @@ export function getInfo () { }) } -// this method was written, as it is, when there was an in-app plugins installer -// since it works well enough, and the in-app installer may return, Im leaving it this way -// ... but, that would explain the somewhat odd design -// -prf -export function checkForUpdates () { +export function checkForUpdates (opts = {}) { // dont overlap if (updaterState != UPDATER_STATUS_IDLE) { return } - // track result states for this run - var isBrowserChecking = false // still checking? - var isBrowserUpdated = false // got an update? - // update global state debug('[AUTO-UPDATE] Checking for a new version.') updaterError = false setUpdaterState(UPDATER_STATUS_CHECKING) - - if (isBrowserUpdatesSupported) { - // check the browser auto-updater - // - because we need to merge the electron auto-updater, and the npm plugin flow... - // ... it's best to set the result events here - // (see note above -- back when there WAS a plugin updater, this made since -prf) - isBrowserChecking = true - autoUpdater.checkForUpdates() - autoUpdater.once('update-not-available', () => { - debug('[AUTO-UPDATE] No browser update available.') - isBrowserChecking = false - checkDone() - }) - autoUpdater.once('update-downloaded', () => { - debug('[AUTO-UPDATE] New browser version downloaded. Ready to install.') - isBrowserChecking = false - isBrowserUpdated = true - checkDone() - }) - - // cleanup - autoUpdater.once('update-not-available', removeAutoUpdaterListeners) - autoUpdater.once('update-downloaded', removeAutoUpdaterListeners) - function removeAutoUpdaterListeners () { - autoUpdater.removeAllListeners('update-not-available') - autoUpdater.removeAllListeners('update-downloaded') - } - } - - // check the result states and emit accordingly - function checkDone () { - if (isBrowserChecking) { return } // still checking - - // done, emit based on result - if (isBrowserUpdated) { - setUpdaterState(UPDATER_STATUS_DOWNLOADED) - } else { - setUpdaterState(UPDATER_STATUS_IDLE) - } + if (opts.prerelease) { + debug('[AUTO-UPDATE] Jumping to pre-releases.') + autoUpdater.allowPrerelease = true } + autoUpdater.checkForUpdates() // just return a resolve; results will be emitted return Promise.resolve() @@ -413,12 +371,12 @@ function setUpdaterState (state) { browserEvents.emit('updater-state-changed', state) } -function getAutoUpdaterFeedURL () { - if (os.platform() == 'darwin') { - return 'https://download.beakerbrowser.net/update/osx/' + app.getVersion() - } else if (os.platform() == 'win32') { - let bits = (os.arch().indexOf('64') === -1) ? 32 : 64 - return 'https://download.beakerbrowser.net/update/win' + bits + '/' + app.getVersion() +function getAutoUpdaterFeedSettings () { + return { + provider: 'github', + repo: 'beaker', + owner: 'beakerbrowser', + vPrefixedTagName: false } } @@ -437,11 +395,21 @@ function scheduledAutoUpdate () { // = function onUpdateAvailable () { - // update status and emit, so the frontend can update debug('[AUTO-UPDATE] New version available. Downloading...') + autoUpdater.downloadUpdate() setUpdaterState(UPDATER_STATUS_DOWNLOADING) } +function onUpdateNotAvailable () { + debug('[AUTO-UPDATE] No browser update available.') + setUpdaterState(UPDATER_STATUS_IDLE) +} + +function onUpdateDownloaded () { + debug('[AUTO-UPDATE] New browser version downloaded. Ready to install.') + setUpdaterState(UPDATER_STATUS_DOWNLOADED) +} + function onUpdateError (e) { debug('[AUTO-UPDATE] error', e.toString()) setUpdaterState(UPDATER_STATUS_IDLE) diff --git a/app/builtin-pages/views/settings.js b/app/builtin-pages/views/settings.js index a5a945b8b5..31e7a285e3 100644 --- a/app/builtin-pages/views/settings.js +++ b/app/builtin-pages/views/settings.js @@ -114,6 +114,9 @@ function renderAutoUpdater () { } ${renderAutoUpdateCheckbox()} + + [ Advanced: Check for prereleases ] + ` case 'checking': @@ -195,10 +198,14 @@ function renderHelp () { // = function onClickCheckUpdates () { - // trigger check beakerBrowser.checkForUpdates() } +function onClickCheckPrereleases (e) { + e.preventDefault() + beakerBrowser.checkForUpdates({prerelease: true}) +} + function onToggleAutoUpdate () { settings.auto_update_enabled = isAutoUpdateEnabled() ? 0 : 1 render() diff --git a/app/package.json b/app/package.json index e7e1c62ebc..91bfb700fb 100644 --- a/app/package.json +++ b/app/package.json @@ -24,6 +24,7 @@ "dns-discovery": "^5.6.1", "du": "git://github.com/beakerbrowser/node-du.git#8db9ed862712a964289d2d07e58f2d7ec543a56e", "electron-localshortcut": "^0.6.0", + "electron-updater": "^2.15.0", "emit-stream": "^0.1.2", "from2": "^2.3.0", "from2-encoding": "^1.0.0", diff --git a/app/stylesheets/builtin-pages/settings.less b/app/stylesheets/builtin-pages/settings.less index 8fd79d4d13..3b4e23dda2 100644 --- a/app/stylesheets/builtin-pages/settings.less +++ b/app/stylesheets/builtin-pages/settings.less @@ -40,6 +40,10 @@ } } + .prereleases { + margin-left: 1rem; + } + &.start-page { label { diff --git a/package.json b/package.json index c909628d83..f5e9ed5f79 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "appId": "com.pfrazee.beaker-browser", "copyright": "© 2017, Blue Link Labs", "npmRebuild": false, - "asar": false, "protocols": [ { "name": "URL", @@ -49,45 +48,8 @@ "linux": { "category": "Network" }, - "dmg": { - "contents": [ - { - "x": 410, - "y": 220, - "type": "link", - "path": "/Applications" - }, - { - "x": 130, - "y": 220, - "type": "file", - "path": "dist/mac/Beaker Browser.app" - }, - { - "x": 50, - "y": 400, - "type": "file", - "path": ".background" - }, - { - "x": 150, - "y": 400, - "type": "file", - "path": ".DS_Store" - }, - { - "x": 250, - "y": 400, - "type": "file", - "path": ".Trashes" - }, - { - "x": 350, - "y": 400, - "type": "file", - "path": ".VolumeIcon.icns" - } - ] + "mac": { + "category": "public.app-category.productivity" } }, "scripts": {