-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4176 from vector-im/t3chguy/updating_stuff
improve update polling electron and provide a manual check for updates button
- Loading branch information
Showing
12 changed files
with
308 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const { app, autoUpdater, ipcMain } = require('electron'); | ||
|
||
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000; | ||
const INITIAL_UPDATE_DELAY_MS = 30 * 1000; | ||
|
||
function installUpdate() { | ||
// for some reason, quitAndInstall does not fire the | ||
// before-quit event, so we need to set the flag here. | ||
global.appQuitting = true; | ||
autoUpdater.quitAndInstall(); | ||
} | ||
|
||
function pollForUpdates() { | ||
try { | ||
autoUpdater.checkForUpdates(); | ||
} catch (e) { | ||
console.log('Couldn\'t check for update', e); | ||
} | ||
} | ||
|
||
module.exports = {}; | ||
module.exports.start = function startAutoUpdate(updateBaseUrl) { | ||
if (updateBaseUrl.slice(-1) !== '/') { | ||
updateBaseUrl = updateBaseUrl + '/'; | ||
} | ||
try { | ||
let url; | ||
// 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') { | ||
// include the current version in the URL we hit. Electron doesn't add | ||
// it anywhere (apart from the User-Agent) so it's up to us. We could | ||
// (and previously did) just use the User-Agent, but this doesn't | ||
// rely on NSURLConnection setting the User-Agent to what we expect, | ||
// and also acts as a convenient cache-buster to ensure that when the | ||
// app updates it always gets a fresh value to avoid update-looping. | ||
url = `${updateBaseUrl}macos/?localVersion=${encodeURIComponent(app.getVersion())}`; | ||
|
||
} else if (process.platform === 'win32') { | ||
url = `${updateBaseUrl}win32/${process.arch}/`; | ||
} else { | ||
// 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'); | ||
} | ||
|
||
if (url) { | ||
autoUpdater.setFeedURL(url); | ||
// 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) { | ||
// will fail if running in debug mode | ||
console.log('Couldn\'t enable update checking', err); | ||
} | ||
} | ||
|
||
ipcMain.on('install_update', installUpdate); | ||
ipcMain.on('check_updates', pollForUpdates); | ||
|
||
function ipcChannelSendUpdateStatus(status) { | ||
if (global.mainWindow) { | ||
global.mainWindow.webContents.send('check_updates', status); | ||
} | ||
} | ||
|
||
autoUpdater.on('update-available', function() { | ||
ipcChannelSendUpdateStatus(true); | ||
}).on('update-not-available', function() { | ||
ipcChannelSendUpdateStatus(false); | ||
}).on('error', function(error) { | ||
ipcChannelSendUpdateStatus(error.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2017 Michael Telatynski <[email protected]> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import React from 'react'; | ||
import { _t } from 'matrix-react-sdk/lib/languageHandler'; | ||
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg'; | ||
import {updateCheckStatusEnum} from '../../../vector/platform/VectorBasePlatform'; | ||
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton'; | ||
|
||
const doneStatuses = [ | ||
updateCheckStatusEnum.ERROR, | ||
updateCheckStatusEnum.NOTAVAILABLE, | ||
]; | ||
|
||
export default React.createClass({ | ||
propTypes: { | ||
status: React.PropTypes.oneOf(Object.values(updateCheckStatusEnum)).isRequired, | ||
// Currently for error detail but will be usable for download progress | ||
// once that is a thing that squirrel passes through electron. | ||
detail: React.PropTypes.string, | ||
}, | ||
|
||
getDefaultProps: function() { | ||
return { | ||
detail: '', | ||
} | ||
}, | ||
|
||
getStatusText: function() { | ||
switch(this.props.status) { | ||
case updateCheckStatusEnum.ERROR: | ||
return _t('Error encountered (%(errorDetail)s).', { errorDetail: this.props.detail }); | ||
case updateCheckStatusEnum.CHECKING: | ||
return _t('Checking for an update...'); | ||
case updateCheckStatusEnum.NOTAVAILABLE: | ||
return _t('No update available.'); | ||
case updateCheckStatusEnum.DOWNLOADING: | ||
return _t('Downloading update...'); | ||
} | ||
} | ||
, | ||
|
||
hideToolbar: function() { | ||
PlatformPeg.get().stopUpdateCheck(); | ||
}, | ||
|
||
render: function() { | ||
const message = this.getStatusText(); | ||
const warning = _t('Warning'); | ||
|
||
let image; | ||
if (doneStatuses.includes(this.props.status)) { | ||
image = <img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt={warning}/>; | ||
} else { | ||
image = <img className="mx_MatrixToolbar_warning" src="img/spinner.gif" width="24" height="23" alt={message}/>; | ||
} | ||
|
||
return ( | ||
<div className="mx_MatrixToolbar"> | ||
{image} | ||
<div className="mx_MatrixToolbar_content"> | ||
{message} | ||
</div> | ||
<AccessibleButton className="mx_MatrixToolbar_close" onClick={this.hideToolbar}> | ||
<img src="img/cancel.svg" width="18" height="18" /> | ||
</AccessibleButton> | ||
</div> | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.