@ -17,11 +17,13 @@ See the License for the specific language governing permissions and
limitations under the License .
* /
const electron = require ( 'electron' ) ;
// Squirrel on windows starts the app with various flags
// as hooks to tell us when we've been installed/uninstalled
// etc.
const check _squirrel _hooks = require ( './squirrelhooks' ) ;
if ( check _squirrel _hooks ( ) ) return ;
// Auto updater from the 'electron-auto-updater' package for NSIS
// auto-update support (not the one that comes with electron).
const autoUpdater = require ( 'electron-auto-updater' ) . autoUpdater ;
const electron = require ( 'electron' ) ;
const url = require ( 'url' ) ;
const VectorMenu = require ( './vectormenu' ) ;
@ -43,7 +45,7 @@ const PERMITTED_URL_SCHEMES = [
] ;
const UPDATE _POLL _INTERVAL _MS = 60 * 60 * 1000 ;
const INITIAL _UPDATE _DELAY _MS = 5 * 1000 ;
const INITIAL _UPDATE _DELAY _MS = 30 * 1000 ;
let mainWindow = null ;
let appQuitting = false ;
@ -88,47 +90,44 @@ function installUpdate() {
// for some reason, quitAndInstall does not fire the
// before-quit event, so we need to set the flag here.
appQuitting = true ;
autoUpdater . quitAndInstall ( ) ;
electron . autoUpdater . quitAndInstall ( ) ;
}
function pollForUpdates ( ) {
try {
autoUpdater . checkForUpdates ( ) ;
electron . autoUpdater . checkForUpdates ( ) ;
} catch ( e ) {
console . log ( "Couldn't check for update" , e ) ;
}
}
function startAutoUpdate ( ) {
if ( process . platform != 'darwin' && process . platform != 'win32 ') {
return ;
function startAutoUpdate ( update _base _url ) {
if ( update _base _url . slice ( - 1 ) !== '/ ') {
update _base _url = update _base _url + '/' ;
}
try {
// Since writing, the electron auto update process has changed from being
// completely different between platforms to being differently completely
// different. On Mac, we set the feed URL here. On Windows, it uses a
// yaml file bundled at build time from the 'publish' entry in the
// package.json. There is no autoupdate for Linux: it's expected that
// the distro will provide it.
// For reasons best known to Squirrel, the way it checks for updates
// is completely different between macOS and windows. On macOS, it
// hits a URL that either gives it a 200 with some json or
// 204 No Content. On windows it takes a base path and looks for
// files under that path.
if ( process . platform == 'darwin' ) {
const update _base _url = vectorConfig . update _base _url ;
if ( ! update _base _url ) {
console . log ( "No update_base_url: disabling auto-update" ) ;
return ;
}
if ( update _base _url . slice ( - 1 ) !== '/' ) {
update _base _url = update _url + '/' ;
}
const update _url = update _base _url + 'update/macos/tmp/' ;
console . log ( "Starting auto update with URL: " + update _url ) ;
autoUpdater . setFeedURL ( update _url ) ;
electron . autoUpdater . setFeedURL ( update _base _url + 'macos/' ) ;
} else if ( process . platform == 'win32' ) {
electron . autoUpdater . setFeedURL ( update _base _url + 'win32/' + process . arch + '/' ) ;
} else {
console . log ( "Starting auto update with baked-in URL" ) ;
// Squirrel / electron only supports auto-update on these two platforms.
// I'm not even going to try to guess which feed style they'd use if they
// implemented it on Linux, or if it would be different again.
console . log ( "Auto update not supported on this platform" ) ;
}
// We check for updates ourselves rather than using 'updater' because we need to
// do it in the main process (and we don't really need to check every 10 minutes:
// every hour should be just fine for a desktop app)
// However, we still let the main window listen for the update events.
// We also wait a short time before checking for updates the first time because
// of squirrel on windows and it taking a small amount of time to release a
// lock file.
setTimeout ( pollForUpdates , INITIAL _UPDATE _DELAY _MS ) ;
setInterval ( pollForUpdates , UPDATE _POLL _INTERVAL _MS ) ;
} catch ( err ) {
@ -150,7 +149,12 @@ process.on('uncaughtException', function (error) {
electron . ipcMain . on ( 'install_update' , installUpdate ) ;
electron . app . on ( 'ready' , ( ) => {
startAutoUpdate ( ) ;
if ( vectorConfig . update _base _url ) {
console . log ( "Starting auto update with base URL: " + vectorConfig . update _base _url ) ;
startAutoUpdate ( vectorConfig . update _base _url ) ;
} else {
console . log ( "No update_base_url is defined: auto update is disabled" ) ;
}
mainWindow = new electron . BrowserWindow ( {
icon : ` ${ _ _dirname } /../img/riot.ico ` ,