Give contextual feedback for manual update check instead of banner

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-05-29 18:24:45 +01:00
parent c68f35060a
commit 1fd74f22c8
3 changed files with 31 additions and 67 deletions

View File

@ -18,18 +18,19 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform'; import VectorBasePlatform from './VectorBasePlatform';
import {UpdateCheckStatus} from "matrix-react-sdk/src/BasePlatform";
import BaseEventIndexManager, { import BaseEventIndexManager, {
MatrixEvent,
MatrixProfile,
SearchResult,
CrawlerCheckpoint, CrawlerCheckpoint,
EventAndProfile, EventAndProfile,
IndexStats,
MatrixEvent,
MatrixProfile,
SearchArgs, SearchArgs,
IndexStats SearchResult
} from 'matrix-react-sdk/src/indexing/BaseEventIndexManager'; } from 'matrix-react-sdk/src/indexing/BaseEventIndexManager';
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher'; import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
import { _t, _td } from 'matrix-react-sdk/src/languageHandler'; import {_t, _td} from 'matrix-react-sdk/src/languageHandler';
import * as rageshake from 'matrix-react-sdk/src/rageshake/rageshake'; import * as rageshake from 'matrix-react-sdk/src/rageshake/rageshake';
import {MatrixClient} from "matrix-js-sdk/src/client"; import {MatrixClient} from "matrix-js-sdk/src/client";
import {Room} from "matrix-js-sdk/src/models/room"; import {Room} from "matrix-js-sdk/src/models/room";
@ -41,8 +42,9 @@ import {Key} from "matrix-react-sdk/src/Keyboard";
import React from "react"; import React from "react";
import {randomString} from "matrix-js-sdk/src/randomstring"; import {randomString} from "matrix-js-sdk/src/randomstring";
import {Action} from "matrix-react-sdk/src/dispatcher/actions"; import {Action} from "matrix-react-sdk/src/dispatcher/actions";
import { ActionPayload } from "matrix-react-sdk/src/dispatcher/payloads"; import {ActionPayload} from "matrix-react-sdk/src/dispatcher/payloads";
import { showToast as showUpdateToast } from "matrix-react-sdk/src/toasts/UpdateToast"; import {showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateToast";
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
const ipcRenderer = window.ipcRenderer; const ipcRenderer = window.ipcRenderer;
const isMac = navigator.platform.toUpperCase().includes('MAC'); const isMac = navigator.platform.toUpperCase().includes('MAC');
@ -73,14 +75,14 @@ function _onAction(payload: ActionPayload) {
} }
} }
function getUpdateCheckStatus(status) { function getUpdateCheckStatus(status: boolean | string) {
if (status === true) { if (status === true) {
return { status: updateCheckStatusEnum.DOWNLOADING }; return { status: UpdateCheckStatus.Downloading };
} else if (status === false) { } else if (status === false) {
return { status: updateCheckStatusEnum.NOTAVAILABLE }; return { status: UpdateCheckStatus.NotAvailable };
} else { } else {
return { return {
status: updateCheckStatusEnum.ERROR, status: UpdateCheckStatus.Error,
detail: status, detail: status,
}; };
} }
@ -214,12 +216,10 @@ export default class ElectronPlatform extends VectorBasePlatform {
or the error if one is encountered or the error if one is encountered
*/ */
ipcRenderer.on('check_updates', (event, status) => { ipcRenderer.on('check_updates', (event, status) => {
if (!this.showUpdateCheck) return; dis.dispatch<CheckUpdatesPayload>({
dis.dispatch({ action: Action.CheckUpdates,
action: 'check_updates', ...getUpdateCheckStatus(status),
value: getUpdateCheckStatus(status),
}); });
this.showUpdateCheck = false;
}); });
// try to flush the rageshake logs to indexeddb before quit. // try to flush the rageshake logs to indexeddb before quit.
@ -385,9 +385,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
} }
startUpdateCheck() { startUpdateCheck() {
if (this.showUpdateCheck) return;
super.startUpdateCheck(); super.startUpdateCheck();
ipcRenderer.send('check_updates'); ipcRenderer.send('check_updates');
} }

View File

@ -18,8 +18,7 @@ limitations under the License.
*/ */
import BasePlatform from 'matrix-react-sdk/src/BasePlatform'; import BasePlatform from 'matrix-react-sdk/src/BasePlatform';
import { _t } from 'matrix-react-sdk/src/languageHandler'; import {_t} from 'matrix-react-sdk/src/languageHandler';
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
import {getVectorConfig} from "../getconfig"; import {getVectorConfig} from "../getconfig";
import Favicon from "../../favicon"; import Favicon from "../../favicon";
@ -36,14 +35,12 @@ export const updateCheckStatusEnum = {
* Vector-specific extensions to the BasePlatform template * Vector-specific extensions to the BasePlatform template
*/ */
export default abstract class VectorBasePlatform extends BasePlatform { export default abstract class VectorBasePlatform extends BasePlatform {
protected showUpdateCheck: boolean = false;
protected _favicon: Favicon; protected _favicon: Favicon;
constructor() { constructor() {
super(); super();
this.startUpdateCheck = this.startUpdateCheck.bind(this); this.startUpdateCheck = this.startUpdateCheck.bind(this);
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
} }
async getConfig(): Promise<{}> { async getConfig(): Promise<{}> {
@ -96,33 +93,6 @@ export default abstract class VectorBasePlatform extends BasePlatform {
startUpdater() { startUpdater() {
} }
/**
* Whether we can call checkForUpdate on this platform build
*/
async canSelfUpdate(): Promise<boolean> {
return false;
}
startUpdateCheck() {
this.showUpdateCheck = true;
dis.dispatch({
action: 'check_updates',
value: { status: updateCheckStatusEnum.CHECKING },
});
}
stopUpdateCheck() {
this.showUpdateCheck = false;
dis.dispatch({
action: 'check_updates',
value: false,
});
}
getUpdateCheckStatusEnum() {
return updateCheckStatusEnum;
}
/** /**
* Update the currently running app to the latest available * Update the currently running app to the latest available
* version and replace this instance of the app with the * version and replace this instance of the app with the

View File

@ -16,12 +16,15 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform'; import VectorBasePlatform from './VectorBasePlatform';
import {UpdateCheckStatus} from "matrix-react-sdk/src/BasePlatform";
import request from 'browser-request'; import request from 'browser-request';
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher'; import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
import { _t } from 'matrix-react-sdk/src/languageHandler'; import {_t} from 'matrix-react-sdk/src/languageHandler';
import {Room} from "matrix-js-sdk/src/models/room"; import {Room} from "matrix-js-sdk/src/models/room";
import { showToast as showUpdateToast, hideToast as hideUpdateToast } from "matrix-react-sdk/src/toasts/UpdateToast"; import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateToast";
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
import url from 'url'; import url from 'url';
import UAParser from 'ua-parser-js'; import UAParser from 'ua-parser-js';
@ -136,36 +139,29 @@ export default class WebPlatform extends VectorBasePlatform {
return this._getVersion().then((ver) => { return this._getVersion().then((ver) => {
if (this.runningVersion === null) { if (this.runningVersion === null) {
this.runningVersion = ver; this.runningVersion = ver;
return; } else if (this.runningVersion !== ver) {
}
if (this.runningVersion !== ver) {
showUpdateToast(this.runningVersion, ver); showUpdateToast(this.runningVersion, ver);
// Return to skip a MatrixChat state update return { status: UpdateCheckStatus.Ready };
return;
} else { } else {
hideUpdateToast(); hideUpdateToast();
} }
return { status: updateCheckStatusEnum.NOTAVAILABLE }; return { status: UpdateCheckStatus.NotAvailable };
}, (err) => { }, (err) => {
console.error("Failed to poll for update", err); console.error("Failed to poll for update", err);
return { return {
status: updateCheckStatusEnum.ERROR, status: UpdateCheckStatus.Error,
detail: err.message || err.status ? err.status.toString() : 'Unknown Error', detail: err.message || err.status ? err.status.toString() : 'Unknown Error',
}; };
}); });
}; };
startUpdateCheck() { startUpdateCheck() {
if (this.showUpdateCheck) return;
super.startUpdateCheck(); super.startUpdateCheck();
this.pollForUpdate().then((updateState) => { this.pollForUpdate().then((updateState) => {
if (!this.showUpdateCheck) return; dis.dispatch<CheckUpdatesPayload>({
if (!updateState) return; action: Action.CheckUpdates,
dis.dispatch({ ...updateState,
action: 'check_updates',
value: updateState,
}); });
}); });
} }