mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
move all logic, make bar more generic
pass through actual errors and tidy needs testing Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
c4fd139586
commit
a520f0bfed
@ -67,4 +67,24 @@ module.exports.start = function startAutoUpdate(updateBaseUrl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('install_update', installUpdate);
|
ipcMain.on('install_update', installUpdate);
|
||||||
ipcMain.on('checkForUpdates', pollForUpdates);
|
|
||||||
|
let ipcChannel;
|
||||||
|
ipcMain.on('check_updates', function(event) {
|
||||||
|
ipcChannel = event.sender;
|
||||||
|
pollForUpdates();
|
||||||
|
// event.sender.send('check_updates') // true/false/error = available(downloading)/notAvailable/error
|
||||||
|
});
|
||||||
|
|
||||||
|
function ipcChannelSendUpdateStatus(status) {
|
||||||
|
if (ipcChannel) {
|
||||||
|
ipcChannel.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);
|
||||||
|
});
|
||||||
|
@ -17,76 +17,50 @@ limitations under the License.
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import dis from 'matrix-react-sdk/lib/dispatcher';
|
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
|
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
|
||||||
import {updateStateEnum} from '../../../vector/platform/VectorBasePlatform';
|
import {updateCheckStatusEnum} from '../../../vector/platform/VectorBasePlatform';
|
||||||
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton';
|
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton';
|
||||||
|
|
||||||
export default React.createClass({
|
const statusText = {
|
||||||
|
CHECKING: 'Checking for an update...',
|
||||||
getInitialState: function() {
|
ERROR: 'Error encountered (%(errorDetail)s).',
|
||||||
return {
|
NOTAVAILABLE: 'No update available.',
|
||||||
message: _t('Checking for an update...'),
|
DOWNLOADING: 'Downloading update...',
|
||||||
done: false,
|
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
componentWillMount: function() {
|
const doneStatuses = [
|
||||||
PlatformPeg.get().checkForUpdate().done((state) => {
|
updateCheckStatusEnum.ERROR,
|
||||||
if (this._unmounted) return;
|
updateCheckStatusEnum.NOTAVAILABLE,
|
||||||
|
];
|
||||||
|
|
||||||
console.log('checkForUpdate done, ', state);
|
export default React.createClass({
|
||||||
|
propTypes: {
|
||||||
// We will be replaced by NewVersionBar
|
status: React.PropTypes.oneOf(Object.values(updateCheckStatusEnum)).isRequired,
|
||||||
if (state === updateStateEnum.READY) return;
|
// Currently for error detail but will be usable for download progress
|
||||||
|
// once that is a thing that squirrel passes through electron.
|
||||||
let done = true;
|
detail: React.PropTypes.string,
|
||||||
let message;
|
|
||||||
switch (state) {
|
|
||||||
case updateStateEnum.ERROR:
|
|
||||||
message = _t('Error encountered when checking for an update.');
|
|
||||||
break;
|
|
||||||
case updateStateEnum.TIMEOUT:
|
|
||||||
message = _t('Update Check timed out, try again later.');
|
|
||||||
break;
|
|
||||||
case updateStateEnum.NOTAVAILABLE:
|
|
||||||
message = _t('No update found.');
|
|
||||||
break;
|
|
||||||
case updateStateEnum.DOWNLOADING:
|
|
||||||
message = _t('Update is being downloaded.');
|
|
||||||
done = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({message, done});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
this._unmounted = true;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hideToolbar: function() {
|
hideToolbar: function() {
|
||||||
dis.dispatch({
|
PlatformPeg.get().stopUpdateCheck();
|
||||||
action: 'check_updates',
|
|
||||||
value: false,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
const message = _t(statusText[this.props.status], { errorDetail: this.props.detail });
|
||||||
|
|
||||||
let image;
|
let image;
|
||||||
if (this.state.done) {
|
if (doneStatuses.includes(this.props.status)) {
|
||||||
image = <img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt="Warning"/>;
|
image = <img className="mx_MatrixToolbar_warning" src="img/warning.svg" width="24" height="23" alt="Warning"/>;
|
||||||
} else {
|
} else {
|
||||||
image = <img className="mx_MatrixToolbar_warning" src="'img/spinner.gif'" width="24" height="23" alt={this.state.message}/>;
|
image = <img className="mx_MatrixToolbar_warning" src="img/spinner.gif" width="24" height="23" alt={message}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx_MatrixToolbar">
|
<div className="mx_MatrixToolbar">
|
||||||
{image}
|
{image}
|
||||||
<div className="mx_MatrixToolbar_content">
|
<div className="mx_MatrixToolbar_content">
|
||||||
{this.state.message}
|
{message}
|
||||||
</div>
|
</div>
|
||||||
<AccessibleButton className="mx_MatrixToolbar_close" onClick={this.hideToolbar}>
|
<AccessibleButton className="mx_MatrixToolbar_close" onClick={this.hideToolbar}>
|
||||||
<img src="img/cancel.svg" width="18" height="18" />
|
<img src="img/cancel.svg" width="18" height="18" />
|
||||||
|
@ -159,8 +159,9 @@
|
|||||||
"Yesterday": "Yesterday",
|
"Yesterday": "Yesterday",
|
||||||
"OK": "OK",
|
"OK": "OK",
|
||||||
"Checking for an update...": "Checking for an update...",
|
"Checking for an update...": "Checking for an update...",
|
||||||
"Error encountered when checking for an update.": "Error encountered when checking for an update.",
|
"Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).",
|
||||||
"Update Check timed out, try again later.": "Update Check timed out, try again later.",
|
"No update available.": "No update available.",
|
||||||
|
"Downloading update...": "Downloading update...",
|
||||||
"No update found.": "No update found.",
|
"No update found.": "No update found.",
|
||||||
"Update is being downloaded.": "Update is being downloaded.",
|
"Update is being downloaded.": "Update is being downloaded.",
|
||||||
"You need to be using HTTPS to place a screen-sharing call.": "You need to be using HTTPS to place a screen-sharing call.",
|
"You need to be using HTTPS to place a screen-sharing call.": "You need to be using HTTPS to place a screen-sharing call.",
|
||||||
|
@ -17,11 +17,11 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import VectorBasePlatform, {updateStateEnum} from './VectorBasePlatform';
|
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
|
||||||
import dis from 'matrix-react-sdk/lib/dispatcher';
|
import dis from 'matrix-react-sdk/lib/dispatcher';
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import q from 'q';
|
import q from 'q';
|
||||||
import electron, {remote, ipcRenderer} from 'electron';
|
import {remote, ipcRenderer} from 'electron';
|
||||||
|
|
||||||
remote.autoUpdater.on('update-downloaded', onUpdateDownloaded);
|
remote.autoUpdater.on('update-downloaded', onUpdateDownloaded);
|
||||||
|
|
||||||
@ -62,11 +62,42 @@ function _onAction(payload: Object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUpdateCheckStatus(status) {
|
||||||
|
if (status === true) {
|
||||||
|
return { status: updateCheckStatusEnum.DOWNLOADING };
|
||||||
|
} else if (status === false) {
|
||||||
|
return { status: updateCheckStatusEnum.NOTAVAILABLE };
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: updateCheckStatusEnum.ERROR,
|
||||||
|
detail: status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class ElectronPlatform extends VectorBasePlatform {
|
export default class ElectronPlatform extends VectorBasePlatform {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
dis.register(_onAction);
|
dis.register(_onAction);
|
||||||
this.updatable = Boolean(remote.autoUpdater.getFeedURL());
|
this.updatable = Boolean(remote.autoUpdater.getFeedURL());
|
||||||
|
|
||||||
|
/*
|
||||||
|
IPC Call `check_updates` returns:
|
||||||
|
true if there is an update available
|
||||||
|
false if there is not
|
||||||
|
or the error if one is encountered
|
||||||
|
*/
|
||||||
|
ipcRenderer.on('check_updates', (event, status) => {
|
||||||
|
if (!this.showUpdateCheck) return;
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'check_updates',
|
||||||
|
value: getUpdateCheckStatus(status),
|
||||||
|
});
|
||||||
|
this.showUpdateCheck = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
||||||
|
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getHumanReadableName(): string {
|
getHumanReadableName(): string {
|
||||||
@ -138,43 +169,18 @@ export default class ElectronPlatform extends VectorBasePlatform {
|
|||||||
return q(remote.app.getVersion());
|
return q(remote.app.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForUpdate() { // manual update check for this platform
|
startUpdateCheck() {
|
||||||
const deferred = q.defer();
|
if (this.showUpdateCheck) return;
|
||||||
|
super.startUpdateCheck();
|
||||||
|
|
||||||
const _onUpdateAvailable = function() {
|
ipcRenderer.send('check_updates');
|
||||||
remote.autoUpdater.removeListener('update-not-available', _onUpdateNotAvailable);
|
|
||||||
remote.autoUpdater.removeListener('error', _onError);
|
|
||||||
deferred.resolve(updateStateEnum.DOWNLOADING);
|
|
||||||
}
|
|
||||||
const _onUpdateNotAvailable = function() {
|
|
||||||
remote.autoUpdater.removeListener('update-available', _onUpdateAvailable);
|
|
||||||
remote.autoUpdater.removeListener('error', _onError);
|
|
||||||
deferred.resolve(updateStateEnum.NOTAVAILABLE);
|
|
||||||
}
|
|
||||||
const _onError = function() {
|
|
||||||
remote.autoUpdater.removeListener('update-not-available', _onUpdateNotAvailable);
|
|
||||||
remote.autoUpdater.removeListener('update-available', _onUpdateAvailable);
|
|
||||||
deferred.resolve(updateStateEnum.ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
remote.autoUpdater.once('update-available', _onUpdateAvailable);
|
|
||||||
remote.autoUpdater.once('update-not-available', _onUpdateNotAvailable);
|
|
||||||
remote.autoUpdater.once('error', _onError);
|
|
||||||
|
|
||||||
remote.ipcRenderer.send('checkForUpdates');
|
|
||||||
return deferred.promise.timeout(10000).catch(() => {
|
|
||||||
remote.autoUpdater.removeListener('update-not-available', _onUpdateNotAvailable);
|
|
||||||
remote.autoUpdater.removeListener('update-available', _onUpdateAvailable);
|
|
||||||
remote.autoUpdater.removeListener('error', _onError);
|
|
||||||
return updateStateEnum.TIMEOUT;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
installUpdate() {
|
installUpdate() {
|
||||||
// IPC to the main process to install the update, since quitAndInstall
|
// IPC to the main process to install the update, since quitAndInstall
|
||||||
// doesn't fire the before-quit event so the main process needs to know
|
// doesn't fire the before-quit event so the main process needs to know
|
||||||
// it should exit.
|
// it should exit.
|
||||||
electron.ipcRenderer.send('install_update');
|
ipcRenderer.send('install_update');
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultDeviceDisplayName(): string {
|
getDefaultDeviceDisplayName(): string {
|
||||||
|
@ -19,12 +19,13 @@ limitations under the License.
|
|||||||
|
|
||||||
import BasePlatform from 'matrix-react-sdk/lib/BasePlatform';
|
import BasePlatform from 'matrix-react-sdk/lib/BasePlatform';
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||||
|
import dis from 'matrix-react-sdk/lib/dispatcher';
|
||||||
|
|
||||||
import Favico from 'favico.js';
|
import Favico from 'favico.js';
|
||||||
|
|
||||||
export const updateStateEnum = {
|
export const updateCheckStatusEnum = {
|
||||||
|
CHECKING: 'CHECKING',
|
||||||
ERROR: 'ERROR',
|
ERROR: 'ERROR',
|
||||||
TIMEOUT: 'TIMEOUT',
|
|
||||||
NOTAVAILABLE: 'NOTAVAILABLE',
|
NOTAVAILABLE: 'NOTAVAILABLE',
|
||||||
DOWNLOADING: 'DOWNLOADING',
|
DOWNLOADING: 'DOWNLOADING',
|
||||||
READY: 'READY',
|
READY: 'READY',
|
||||||
@ -42,8 +43,12 @@ export default class VectorBasePlatform extends BasePlatform {
|
|||||||
// and we set the state each time, even if the value hasn't changed,
|
// and we set the state each time, even if the value hasn't changed,
|
||||||
// so we'd need to fix that if enabling the animation.
|
// so we'd need to fix that if enabling the animation.
|
||||||
this.favicon = new Favico({animation: 'none'});
|
this.favicon = new Favico({animation: 'none'});
|
||||||
|
this.showUpdateCheck = false;
|
||||||
this._updateFavicon();
|
this._updateFavicon();
|
||||||
this.updatable = true;
|
this.updatable = true;
|
||||||
|
|
||||||
|
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
||||||
|
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getHumanReadableName(): string {
|
getHumanReadableName(): string {
|
||||||
@ -96,14 +101,30 @@ export default class VectorBasePlatform extends BasePlatform {
|
|||||||
return this.updatable;
|
return this.updatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startUpdateCheck() {
|
||||||
|
this.showUpdateCheck = true;
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'check_updates',
|
||||||
|
value: { status: updateCheckStatusEnum.CHECKING },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
stopUpdateCheck() {
|
||||||
|
this.showUpdateCheck = false;
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'check_updates',
|
||||||
|
value: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for the availability of an update to the version of the
|
* Check for the availability of an update to the version of the
|
||||||
* app that's currently running.
|
* app that's currently running.
|
||||||
* If an update is available, this function should dispatch the
|
* If an update is available, this function should dispatch the
|
||||||
* 'new_version' action.
|
* 'new_version' action.
|
||||||
* @returns Promise<updateStateEnum>
|
* @returns Promise<updateCheckStatusEnum>
|
||||||
*/
|
*/
|
||||||
checkForUpdate(): Promise<number> {
|
pollForUpdate(): Promise<number> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import VectorBasePlatform, {updateStateEnum} from './VectorBasePlatform';
|
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
|
||||||
import request from 'browser-request';
|
import request from 'browser-request';
|
||||||
import dis from 'matrix-react-sdk/lib/dispatcher.js';
|
import dis from 'matrix-react-sdk/lib/dispatcher.js';
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||||
@ -32,6 +32,9 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.runningVersion = null;
|
this.runningVersion = null;
|
||||||
|
|
||||||
|
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
||||||
|
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getHumanReadableName(): string {
|
getHumanReadableName(): string {
|
||||||
@ -135,11 +138,11 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startUpdater() {
|
startUpdater() {
|
||||||
this.checkForUpdate();
|
this.pollForUpdate();
|
||||||
setInterval(this.checkForUpdate, POKE_RATE_MS);
|
setInterval(this.pollForUpdate.bind(this), POKE_RATE_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForUpdate() {
|
pollForUpdate() {
|
||||||
return this._getVersion().then((ver) => {
|
return this._getVersion().then((ver) => {
|
||||||
if (this.runningVersion === null) {
|
if (this.runningVersion === null) {
|
||||||
this.runningVersion = ver;
|
this.runningVersion = ver;
|
||||||
@ -149,12 +152,29 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||||||
currentVersion: this.runningVersion,
|
currentVersion: this.runningVersion,
|
||||||
newVersion: ver,
|
newVersion: ver,
|
||||||
});
|
});
|
||||||
return updateStateEnum.READY;
|
// Return to skip a MatrixChat state update
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return updateStateEnum.NOTAVAILABLE;
|
return { status: updateCheckStatusEnum.NOTAVAILABLE };
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.error("Failed to poll for update", err);
|
console.error("Failed to poll for update", err);
|
||||||
return updateStateEnum.ERROR;
|
return {
|
||||||
|
status: updateCheckStatusEnum.ERROR,
|
||||||
|
detail: err.message || err.status ? err.status.toString() : 'Unknown Error',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
startUpdateCheck() {
|
||||||
|
if (this.showUpdateCheck) return;
|
||||||
|
super.startUpdateCheck();
|
||||||
|
this.pollForUpdate().then((updateState) => {
|
||||||
|
if (!this.showUpdateCheck) return;
|
||||||
|
if (!updateState) return;
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'check_updates',
|
||||||
|
value: updateState,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user