@@ -17,11 +17,13 @@ See the License for the specific language governing permissions and
1717limitations under the License.
1818*/
1919
20- const electron = require ( 'electron' ) ;
20+ // Squirrel on windows starts the app with various flags
21+ // as hooks to tell us when we've been installed/uninstalled
22+ // etc.
23+ const check_squirrel_hooks = require ( './squirrelhooks' ) ;
24+ if ( check_squirrel_hooks ( ) ) return ;
2125
22- // Auto updater from the 'electron-auto-updater' package for NSIS
23- // auto-update support (not the one that comes with electron).
24- const autoUpdater = require ( 'electron-auto-updater' ) . autoUpdater ;
26+ const electron = require ( 'electron' ) ;
2527const url = require ( 'url' ) ;
2628
2729const VectorMenu = require ( './vectormenu' ) ;
@@ -43,7 +45,7 @@ const PERMITTED_URL_SCHEMES = [
4345] ;
4446
4547const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000 ;
46- const INITIAL_UPDATE_DELAY_MS = 5 * 1000 ;
48+ const INITIAL_UPDATE_DELAY_MS = 30 * 1000 ;
4749
4850let mainWindow = null ;
4951let appQuitting = false ;
@@ -88,47 +90,44 @@ function installUpdate() {
8890 // for some reason, quitAndInstall does not fire the
8991 // before-quit event, so we need to set the flag here.
9092 appQuitting = true ;
91- autoUpdater . quitAndInstall ( ) ;
93+ electron . autoUpdater . quitAndInstall ( ) ;
9294}
9395
9496function pollForUpdates ( ) {
9597 try {
96- autoUpdater . checkForUpdates ( ) ;
98+ electron . autoUpdater . checkForUpdates ( ) ;
9799 } catch ( e ) {
98100 console . log ( "Couldn't check for update" , e ) ;
99101 }
100102}
101103
102- function startAutoUpdate ( ) {
103- if ( process . platform != 'darwin' && process . platform ! = 'win32 ' ) {
104- return ;
104+ function startAutoUpdate ( update_base_url ) {
105+ if ( update_base_url . slice ( - 1 ) !== '/ ' ) {
106+ update_base_url = update_base_url + '/' ;
105107 }
106108 try {
107- // Since writing, the electron auto update process has changed from being
108- // completely different between platforms to being differently completely
109- // different. On Mac, we set the feed URL here. On Windows, it uses a
110- // yaml file bundled at build time from the 'publish' entry in the
111- // package.json. There is no autoupdate for Linux: it's expected that
112- // the distro will provide it.
109+ // For reasons best known to Squirrel, the way it checks for updates
110+ // is completely different between macOS and windows. On macOS, it
111+ // hits a URL that either gives it a 200 with some json or
112+ // 204 No Content. On windows it takes a base path and looks for
113+ // files under that path.
113114 if ( process . platform == 'darwin' ) {
114- const update_base_url = vectorConfig . update_base_url ;
115- if ( ! update_base_url ) {
116- console . log ( "No update_base_url: disabling auto-update" ) ;
117- return ;
118- }
119- if ( update_base_url . slice ( - 1 ) !== '/' ) {
120- update_base_url = update_url + '/' ;
121- }
122- const update_url = update_base_url + 'update/macos/tmp/' ;
123- console . log ( "Starting auto update with URL: " + update_url ) ;
124- autoUpdater . setFeedURL ( update_url ) ;
115+ electron . autoUpdater . setFeedURL ( update_base_url + 'macos/' ) ;
116+ } else if ( process . platform == 'win32' ) {
117+ electron . autoUpdater . setFeedURL ( update_base_url + 'win32/' + process . arch + '/' ) ;
125118 } else {
126- console . log ( "Starting auto update with baked-in URL" ) ;
119+ // Squirrel / electron only supports auto-update on these two platforms.
120+ // I'm not even going to try to guess which feed style they'd use if they
121+ // implemented it on Linux, or if it would be different again.
122+ console . log ( "Auto update not supported on this platform" ) ;
127123 }
128124 // We check for updates ourselves rather than using 'updater' because we need to
129125 // do it in the main process (and we don't really need to check every 10 minutes:
130126 // every hour should be just fine for a desktop app)
131127 // However, we still let the main window listen for the update events.
128+ // We also wait a short time before checking for updates the first time because
129+ // of squirrel on windows and it taking a small amount of time to release a
130+ // lock file.
132131 setTimeout ( pollForUpdates , INITIAL_UPDATE_DELAY_MS ) ;
133132 setInterval ( pollForUpdates , UPDATE_POLL_INTERVAL_MS ) ;
134133 } catch ( err ) {
@@ -150,7 +149,12 @@ process.on('uncaughtException', function (error) {
150149electron . ipcMain . on ( 'install_update' , installUpdate ) ;
151150
152151electron . app . on ( 'ready' , ( ) => {
153- startAutoUpdate ( ) ;
152+ if ( vectorConfig . update_base_url ) {
153+ console . log ( "Starting auto update with base URL: " + vectorConfig . update_base_url ) ;
154+ startAutoUpdate ( vectorConfig . update_base_url ) ;
155+ } else {
156+ console . log ( "No update_base_url is defined: auto update is disabled" ) ;
157+ }
154158
155159 mainWindow = new electron . BrowserWindow ( {
156160 icon : `${ __dirname } /../img/riot.ico` ,
0 commit comments