diff --git a/ElectronClient/app/ElectronAppWrapper.js b/ElectronClient/app/ElectronAppWrapper.js index 295c575f2..f61b49045 100644 --- a/ElectronClient/app/ElectronAppWrapper.js +++ b/ElectronClient/app/ElectronAppWrapper.js @@ -5,6 +5,7 @@ const url = require('url') const path = require('path') const urlUtils = require('lib/urlUtils.js'); const { dirname, basename } = require('lib/path-utils'); +const fs = require('fs-extra'); class ElectronAppWrapper { @@ -14,6 +15,7 @@ class ElectronAppWrapper { this.win_ = null; this.willQuitApp_ = false; this.tray_ = null; + this.buildDir_ = null; } electronApp() { @@ -116,20 +118,30 @@ class ElectronAppWrapper { } buildDir() { - let dir = __dirname; - if (dir.indexOf('.asar') >= 0 || basename(dir) === 'app') dir = dirname(dir); - return dir + '/build'; + if (this.buildDir_) return this.buildDir_; + let dir = __dirname + '/build'; + if (!fs.pathExistsSync(dir)) { + dir = dirname(__dirname) + '/build'; + if (!fs.pathExistsSync(dir)) throw new Error('Cannot find build dir'); + } + + this.buildDir_ = dir; + return dir; } // Note: this must be called only after the "ready" event of the app has been dispatched createTray(contextMenu) { - this.tray_ = new Tray(this.buildDir() + '/icons/16x16.png') - this.tray_.setToolTip(this.electronApp_.getName()) - this.tray_.setContextMenu(contextMenu) + try { + this.tray_ = new Tray(this.buildDir() + '/icons/16x16.png') + this.tray_.setToolTip(this.electronApp_.getName()) + this.tray_.setContextMenu(contextMenu) - this.tray_.on('click', () => { - this.window().show(); - }); + this.tray_.on('click', () => { + this.window().show(); + }); + } catch (error) { + console.error("Cannot create tray", error); + } } destroyTray() { diff --git a/ElectronClient/app/checkForUpdates.js b/ElectronClient/app/checkForUpdates.js index b72cfeb8d..742323a17 100644 --- a/ElectronClient/app/checkForUpdates.js +++ b/ElectronClient/app/checkForUpdates.js @@ -6,6 +6,9 @@ const { _ } = require('lib/locale.js'); let autoUpdateLogger_ = new Logger(); let checkInBackground_ = false; +// Note: Electron Builder's autoUpdater is incredibly buggy so currently it's only used +// to detect if a new version is present. If it is, the download link is simply opened +// in a new browser window. autoUpdater.autoDownload = false; autoUpdater.on('error', (error) => { @@ -14,19 +17,36 @@ autoUpdater.on('error', (error) => { dialog.showErrorBox(_('Error'), error == null ? "unknown" : (error.stack || error).toString()) }) -autoUpdater.on('update-available', () => { +function htmlToText_(html) { + let output = html.replace(/\n/g, ''); + output = output.replace(/