Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give contextual feedback for manual update check instead of banner #13862

Merged
merged 1 commit into from May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 17 additions & 19 deletions src/vector/platform/ElectronPlatform.tsx
Expand Up @@ -18,18 +18,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
import VectorBasePlatform from './VectorBasePlatform';
import {UpdateCheckStatus} from "matrix-react-sdk/src/BasePlatform";
import BaseEventIndexManager, {
MatrixEvent,
MatrixProfile,
SearchResult,
CrawlerCheckpoint,
EventAndProfile,
IndexStats,
MatrixEvent,
MatrixProfile,
SearchArgs,
IndexStats
SearchResult
} from 'matrix-react-sdk/src/indexing/BaseEventIndexManager';
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 {MatrixClient} from "matrix-js-sdk/src/client";
import {Room} from "matrix-js-sdk/src/models/room";
Expand All @@ -41,8 +42,9 @@ import {Key} from "matrix-react-sdk/src/Keyboard";
import React from "react";
import {randomString} from "matrix-js-sdk/src/randomstring";
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
import { ActionPayload } from "matrix-react-sdk/src/dispatcher/payloads";
import { showToast as showUpdateToast } from "matrix-react-sdk/src/toasts/UpdateToast";
import {ActionPayload} from "matrix-react-sdk/src/dispatcher/payloads";
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 isMac = navigator.platform.toUpperCase().includes('MAC');
Expand Down Expand Up @@ -73,14 +75,14 @@ function _onAction(payload: ActionPayload) {
}
}

function getUpdateCheckStatus(status) {
function getUpdateCheckStatus(status: boolean | string) {
if (status === true) {
return { status: updateCheckStatusEnum.DOWNLOADING };
return { status: UpdateCheckStatus.Downloading };
} else if (status === false) {
return { status: updateCheckStatusEnum.NOTAVAILABLE };
return { status: UpdateCheckStatus.NotAvailable };
} else {
return {
status: updateCheckStatusEnum.ERROR,
status: UpdateCheckStatus.Error,
detail: status,
};
}
Expand Down Expand Up @@ -214,12 +216,10 @@ export default class ElectronPlatform extends VectorBasePlatform {
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),
dis.dispatch<CheckUpdatesPayload>({
action: Action.CheckUpdates,
...getUpdateCheckStatus(status),
});
this.showUpdateCheck = false;
});

// try to flush the rageshake logs to indexeddb before quit.
Expand Down Expand Up @@ -385,9 +385,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
}

startUpdateCheck() {
if (this.showUpdateCheck) return;
super.startUpdateCheck();

ipcRenderer.send('check_updates');
}

Expand Down
32 changes: 1 addition & 31 deletions src/vector/platform/VectorBasePlatform.ts
Expand Up @@ -18,8 +18,7 @@ limitations under the License.
*/

import BasePlatform from 'matrix-react-sdk/src/BasePlatform';
import { _t } from 'matrix-react-sdk/src/languageHandler';
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
import {_t} from 'matrix-react-sdk/src/languageHandler';
import {getVectorConfig} from "../getconfig";

import Favicon from "../../favicon";
Expand All @@ -36,14 +35,12 @@ export const updateCheckStatusEnum = {
* Vector-specific extensions to the BasePlatform template
*/
export default abstract class VectorBasePlatform extends BasePlatform {
protected showUpdateCheck: boolean = false;
protected _favicon: Favicon;

constructor() {
super();

this.startUpdateCheck = this.startUpdateCheck.bind(this);
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
}

async getConfig(): Promise<{}> {
Expand Down Expand Up @@ -96,33 +93,6 @@ export default abstract class VectorBasePlatform extends BasePlatform {
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
* version and replace this instance of the app with the
Expand Down
30 changes: 13 additions & 17 deletions src/vector/platform/WebPlatform.ts
Expand Up @@ -16,12 +16,15 @@ See the License for the specific language governing permissions and
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 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 { 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 UAParser from 'ua-parser-js';
Expand Down Expand Up @@ -136,36 +139,29 @@ export default class WebPlatform extends VectorBasePlatform {
return this._getVersion().then((ver) => {
if (this.runningVersion === null) {
this.runningVersion = ver;
return;
}

if (this.runningVersion !== ver) {
} else if (this.runningVersion !== ver) {
showUpdateToast(this.runningVersion, ver);
// Return to skip a MatrixChat state update
return;
return { status: UpdateCheckStatus.Ready };
} else {
hideUpdateToast();
}

return { status: updateCheckStatusEnum.NOTAVAILABLE };
return { status: UpdateCheckStatus.NotAvailable };
}, (err) => {
console.error("Failed to poll for update", err);
return {
status: updateCheckStatusEnum.ERROR,
status: UpdateCheckStatus.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,
dis.dispatch<CheckUpdatesPayload>({
action: Action.CheckUpdates,
...updateState,
});
});
}
Expand Down