Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'new-auto-updater'
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Nov 2, 2017
2 parents 47bd534 + 0193970 commit ac2a3cb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 105 deletions.
96 changes: 32 additions & 64 deletions 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'
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -165,7 +166,7 @@ export function getInfo () {
nodeVersion: process.versions.node,
platform: os.platform(),
updater: {
isBrowserUpdatesSupported,
isBrowserUpdatesSupported: true,
error: updaterError,
state: updaterState
},
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion app/builtin-pages/views/settings.js
Expand Up @@ -114,6 +114,9 @@ function renderAutoUpdater () {
}
${renderAutoUpdateCheckbox()}
</span>
<span class="prereleases">
[ Advanced: <a href="#" onclick=${onClickCheckPrereleases}>Check for prereleases</a> ]
</span>
</div>`

case 'checking':
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions app/stylesheets/builtin-pages/settings.less
Expand Up @@ -40,6 +40,10 @@
}
}

.prereleases {
margin-left: 1rem;
}

&.start-page {

label {
Expand Down
42 changes: 2 additions & 40 deletions package.json
Expand Up @@ -30,7 +30,6 @@
"appId": "com.pfrazee.beaker-browser",
"copyright": "© 2017, Blue Link Labs",
"npmRebuild": false,
"asar": false,
"protocols": [
{
"name": "URL",
Expand All @@ -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": {
Expand Down

0 comments on commit ac2a3cb

Please sign in to comment.