implement barebones auto updater
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
var applicationConfigPath = require('application-config-path')
|
||||
var path = require('path')
|
||||
|
||||
var APP_VERSION = require('./package.json').version
|
||||
|
||||
module.exports = {
|
||||
APP_COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project',
|
||||
APP_FILE_ICON: path.join(__dirname, 'static', 'WebTorrentFile'),
|
||||
APP_ICON: path.join(__dirname, 'static', 'WebTorrent'),
|
||||
APP_NAME: 'WebTorrent',
|
||||
|
||||
AUTO_UPDATE_URL: 'https://webtorrent.io/app/updates?version=' + APP_VERSION,
|
||||
AUTO_UPDATE_CHECK_STARTUP_DELAY: 60 * 1000 /* 1 minute */,
|
||||
AUTO_UPDATE_CHECK_INTERVAL: 6 * 60 * 60 * 1000 /* 6 hours */,
|
||||
|
||||
CONFIG_PATH: applicationConfigPath('WebTorrent'),
|
||||
CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'Posters'),
|
||||
CONFIG_TORRENT_PATH: path.join(applicationConfigPath('WebTorrent'), 'Torrents'),
|
||||
|
||||
41
main/auto-updater.js
Normal file
41
main/auto-updater.js
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = {
|
||||
init
|
||||
}
|
||||
|
||||
var electron = require('electron')
|
||||
|
||||
var config = require('../config')
|
||||
|
||||
// var app = electron.app
|
||||
var autoUpdater = electron.autoUpdater
|
||||
|
||||
function init () {
|
||||
autoUpdater.on('error', function (err) {
|
||||
console.error('error downloading app update', err.message || err)
|
||||
})
|
||||
|
||||
autoUpdater.setFeedURL(config.AUTO_UPDATE_URL)
|
||||
|
||||
// TODO: remove
|
||||
autoUpdater.checkForUpdates()
|
||||
|
||||
/*
|
||||
* We always check for updates on app startup. To keep app startup fast, we delay this
|
||||
* first check so it happens when there is less going on.
|
||||
*/
|
||||
setTimeout(() => autoUpdater.checkForUpdates(), config.AUTO_UPDATE_CHECK_STARTUP_DELAY)
|
||||
|
||||
/*
|
||||
* After the first check for updates, we continually check for updates on a regular
|
||||
* interval. This is to ensure that checks happen even when the app is left open for a
|
||||
* long time.
|
||||
*/
|
||||
setInterval(() => autoUpdater.checkForUpdates(), config.AUTO_UPDATE_CHECK_INTERVAL)
|
||||
|
||||
autoUpdater.on('checking-for-update', () => console.log('checking for app update'))
|
||||
autoUpdater.on('update-available', () => console.log('app update available'))
|
||||
autoUpdater.on('update-not-available', () => console.log('app update not available'))
|
||||
autoUpdater.on('update-downloaded', function (e) {
|
||||
console.log('app update downloaded', e)
|
||||
})
|
||||
}
|
||||
@@ -2,6 +2,7 @@ var electron = require('electron')
|
||||
|
||||
var app = electron.app
|
||||
|
||||
var autoUpdater = require('./auto-updater')
|
||||
var config = require('../config')
|
||||
var ipc = require('./ipc')
|
||||
var menu = require('./menu')
|
||||
@@ -38,7 +39,10 @@ var argv = sliceArgv(process.argv)
|
||||
|
||||
app.on('open-file', onOpen)
|
||||
app.on('open-url', onOpen)
|
||||
app.on('will-finish-launching', setupCrashReporter)
|
||||
app.on('will-finish-launching', function () {
|
||||
autoUpdater.init()
|
||||
setupCrashReporter()
|
||||
})
|
||||
|
||||
app.ipcReady = false // main window has finished loading and IPC is ready
|
||||
app.isQuitting = false
|
||||
|
||||
Reference in New Issue
Block a user