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
6 changed files with 138 additions and 96 deletions
|
@ -17,11 +17,11 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import VectorBasePlatform, {updateStateEnum} from './VectorBasePlatform';
|
||||
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
|
||||
import dis from 'matrix-react-sdk/lib/dispatcher';
|
||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||
import q from 'q';
|
||||
import electron, {remote, ipcRenderer} from 'electron';
|
||||
import {remote, ipcRenderer} from 'electron';
|
||||
|
||||
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 {
|
||||
constructor() {
|
||||
super();
|
||||
dis.register(_onAction);
|
||||
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 {
|
||||
|
@ -138,43 +169,18 @@ export default class ElectronPlatform extends VectorBasePlatform {
|
|||
return q(remote.app.getVersion());
|
||||
}
|
||||
|
||||
checkForUpdate() { // manual update check for this platform
|
||||
const deferred = q.defer();
|
||||
startUpdateCheck() {
|
||||
if (this.showUpdateCheck) return;
|
||||
super.startUpdateCheck();
|
||||
|
||||
const _onUpdateAvailable = function() {
|
||||
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;
|
||||
});
|
||||
ipcRenderer.send('check_updates');
|
||||
}
|
||||
|
||||
installUpdate() {
|
||||
// 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
|
||||
// it should exit.
|
||||
electron.ipcRenderer.send('install_update');
|
||||
ipcRenderer.send('install_update');
|
||||
}
|
||||
|
||||
getDefaultDeviceDisplayName(): string {
|
||||
|
|
|
@ -19,12 +19,13 @@ limitations under the License.
|
|||
|
||||
import BasePlatform from 'matrix-react-sdk/lib/BasePlatform';
|
||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||
import dis from 'matrix-react-sdk/lib/dispatcher';
|
||||
|
||||
import Favico from 'favico.js';
|
||||
|
||||
export const updateStateEnum = {
|
||||
export const updateCheckStatusEnum = {
|
||||
CHECKING: 'CHECKING',
|
||||
ERROR: 'ERROR',
|
||||
TIMEOUT: 'TIMEOUT',
|
||||
NOTAVAILABLE: 'NOTAVAILABLE',
|
||||
DOWNLOADING: 'DOWNLOADING',
|
||||
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,
|
||||
// so we'd need to fix that if enabling the animation.
|
||||
this.favicon = new Favico({animation: 'none'});
|
||||
this.showUpdateCheck = false;
|
||||
this._updateFavicon();
|
||||
this.updatable = true;
|
||||
|
||||
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
||||
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||
}
|
||||
|
||||
getHumanReadableName(): string {
|
||||
|
@ -96,14 +101,30 @@ export default class VectorBasePlatform extends BasePlatform {
|
|||
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
|
||||
* app that's currently running.
|
||||
* If an update is available, this function should dispatch the
|
||||
* '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.
|
||||
*/
|
||||
|
||||
import VectorBasePlatform, {updateStateEnum} from './VectorBasePlatform';
|
||||
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
|
||||
import request from 'browser-request';
|
||||
import dis from 'matrix-react-sdk/lib/dispatcher.js';
|
||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||
|
@ -32,6 +32,9 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||
constructor() {
|
||||
super();
|
||||
this.runningVersion = null;
|
||||
|
||||
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
||||
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||
}
|
||||
|
||||
getHumanReadableName(): string {
|
||||
|
@ -135,11 +138,11 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||
}
|
||||
|
||||
startUpdater() {
|
||||
this.checkForUpdate();
|
||||
setInterval(this.checkForUpdate, POKE_RATE_MS);
|
||||
this.pollForUpdate();
|
||||
setInterval(this.pollForUpdate.bind(this), POKE_RATE_MS);
|
||||
}
|
||||
|
||||
checkForUpdate() {
|
||||
pollForUpdate() {
|
||||
return this._getVersion().then((ver) => {
|
||||
if (this.runningVersion === null) {
|
||||
this.runningVersion = ver;
|
||||
|
@ -149,12 +152,29 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||
currentVersion: this.runningVersion,
|
||||
newVersion: ver,
|
||||
});
|
||||
return updateStateEnum.READY;
|
||||
// Return to skip a MatrixChat state update
|
||||
return;
|
||||
}
|
||||
return updateStateEnum.NOTAVAILABLE;
|
||||
return { status: updateCheckStatusEnum.NOTAVAILABLE };
|
||||
}, (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…
Add table
Add a link
Reference in a new issue