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

Auto updater end to end #113

Merged
merged 3 commits into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

// UPDATE_HOST should be set to the host name for the auto-updater server
var updateHost = process.env.UPDATE_HOST || 'https://dev.mysite.com'
var updateHost = process.env.UPDATE_HOST || 'https://brave-laptop-updates.global.ssl.fastly.net'

module.exports = {
updates: {
Expand Down
2 changes: 1 addition & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ app.on('ready', function () {
if (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test') {
Updater.init(process.platform)

// this is fired by the menu entry
// this is fired by a menu entry
process.on(messages.CHECK_FOR_UPDATE, () => Updater.checkForUpdate())
} else {
process.on(messages.CHECK_FOR_UPDATE, () => Updater.fakeCheckForUpdate())
Expand Down
45 changes: 36 additions & 9 deletions app/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,82 @@
const electron = require('electron')
const BrowserWindow = electron.BrowserWindow
const path = require('path')
const os = require('os')
const fs = require('fs')
const autoUpdater = require('auto-updater')
const config = require('./appConfig')
const messages = require('../js/constants/messages')

// in built mode console.log output is not emitted to the terminal
// in prod mode we pipe to a file
var debug = function (contents) {
fs.appendFileSync(path.join(os.homedir(), 'output.txt'), contents + '\n')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just comment out this line for now

}

// this maps the result of a call to process.platform to an update API identifier
var platforms = {
'darwin': 'osx'
}

// build the complete update url from the base, platform and version
var buildUpdateUrl = function (baseUrl, platform) {
exports.updateUrl = function (baseUrl, platform) {
var pack = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json')))
var version = pack.version
return `${baseUrl}/${platforms[platform]}/${version}`
}

// set the feed url for the auto-update system
exports.init = (platform) => {
var updateUrl = buildUpdateUrl(config.updates.baseUrl, platform)
var updateUrl = exports.updateUrl(config.updates.baseUrl, platform)
debug('updateUrl = ' + updateUrl)
try {
autoUpdater.setFeedURL(updateUrl)
} catch (err) {
console.log(err)
}
}

// make a network request to check for an available update
exports.checkForUpdate = () => {
autoUpdater.checkForUpdates()
debug('checkForUpdates')
try {
autoUpdater.checkForUpdates()
} catch (err) {
debug(err)
}
}

// development version only
exports.fakeCheckForUpdate = () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.UPDATE_AVAILABLE)
debug('fakeCheckForUpdate')
BrowserWindow.webContents.send(messages.UPDATE_AVAILABLE)
}

// The UI indicates that we should update the software
exports.update = () => {
console.log('update requested in updater')
debug('update requested in updater')
autoUpdater.quitAndInstall()
}

autoUpdater.on(messages.UPDATE_DOWNLOADED, (evt) => {
BrowserWindow.getFocusedWindow().webContents.send(messages.UPDATE_AVAILABLE)
// The download is complete, we send a signal and await UI
autoUpdater.on('update-downloaded', (evt, extra, extra2) => {
debug('update downloaded')
process.emit(messages.UPDATE_AVAILABLE)
})

// Download has started
autoUpdater.on(messages.UPDATE_AVAILABLE, (evt) => {
console.log('update downloading')
// TODO add ui notification
debug('update downloading')
})

// The current version of the software is current
autoUpdater.on(messages.UPDATE_NOT_AVAILABLE, (evt) => {
console.log('update is not available')
// TODO add ui notification
debug('update not available')
})

// Handle autoUpdater errors (Network, permissions etc...)
autoUpdater.on('error', (err) => {
debug(err)
})
2 changes: 1 addition & 1 deletion build-darwin-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ var version = pack.version
console.log(version)
process.chdir(path.join(__dirname, 'Brave-darwin-x64'))

exec('zip -qr Brave-' + version + '.zip Brave.app/')
exec('ditto -c -k --sequesterRsrc --keepParent Brave.app Brave-' + version + '.zip')
28 changes: 27 additions & 1 deletion docs/autoUpdates.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ The built dmg binary requires its components to be digitally signed before the u

7. Install dmg by mounting dmg and moving browser to the Applications folder

8. Browser will check for updates on startup
8. Browser will check for updates via menu entry

# Windows x64

# Deploying Updates

1. Bump version number in package.json (0.0.3 in this example)

2. Run zip file packager `npm run zip-darwin`. This will create a packaged update zip file ./Brave-darwin-x64/Brave-0.0.3.zip

3. Update vault-updater repo /data/osx.json with update meta data

{
"version": "0.0.3",
"notes": "Release notes for v0.0.3",
"name": "Brave 0.0.3",
"pub_date": "2015-12-30T12:29:53+04:00",
"url": "https://brave-download.global.ssl.fastly.net/releases/0.0.3/osx/Brave-0.0.3.zip"
}

Commit to master and push to Heroku

`git push heroku master -f`

4. Create folder in brave-download S3 bucket releases/0.0.3/osx

5. Upload Brave-0.0.3.zip to new folder

6. Navigate to the releases folder, select it and mark it as public
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brave",
"version": "0.0.2",
"version": "0.0.3",
"description": "Brave laptop and desktop browser",
"main": "./app/index.js",
"scripts": {
Expand Down