Skip to content

Commit 1fd74f2

Browse files
committed
Give contextual feedback for manual update check instead of banner
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent c68f350 commit 1fd74f2

3 files changed

Lines changed: 31 additions & 67 deletions

File tree

‎src/vector/platform/ElectronPlatform.tsx‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ See the License for the specific language governing permissions and
1818
limitations under the License.
1919
*/
2020

21-
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
21+
import VectorBasePlatform from './VectorBasePlatform';
22+
import {UpdateCheckStatus} from "matrix-react-sdk/src/BasePlatform";
2223
import BaseEventIndexManager, {
23-
MatrixEvent,
24-
MatrixProfile,
25-
SearchResult,
2624
CrawlerCheckpoint,
2725
EventAndProfile,
26+
IndexStats,
27+
MatrixEvent,
28+
MatrixProfile,
2829
SearchArgs,
29-
IndexStats
30+
SearchResult
3031
} from 'matrix-react-sdk/src/indexing/BaseEventIndexManager';
3132
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
32-
import { _t, _td } from 'matrix-react-sdk/src/languageHandler';
33+
import {_t, _td} from 'matrix-react-sdk/src/languageHandler';
3334
import * as rageshake from 'matrix-react-sdk/src/rageshake/rageshake';
3435
import {MatrixClient} from "matrix-js-sdk/src/client";
3536
import {Room} from "matrix-js-sdk/src/models/room";
@@ -41,8 +42,9 @@ import {Key} from "matrix-react-sdk/src/Keyboard";
4142
import React from "react";
4243
import {randomString} from "matrix-js-sdk/src/randomstring";
4344
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
44-
import { ActionPayload } from "matrix-react-sdk/src/dispatcher/payloads";
45-
import { showToast as showUpdateToast } from "matrix-react-sdk/src/toasts/UpdateToast";
45+
import {ActionPayload} from "matrix-react-sdk/src/dispatcher/payloads";
46+
import {showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateToast";
47+
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
4648

4749
const ipcRenderer = window.ipcRenderer;
4850
const isMac = navigator.platform.toUpperCase().includes('MAC');
@@ -73,14 +75,14 @@ function _onAction(payload: ActionPayload) {
7375
}
7476
}
7577

76-
function getUpdateCheckStatus(status) {
78+
function getUpdateCheckStatus(status: boolean | string) {
7779
if (status === true) {
78-
return { status: updateCheckStatusEnum.DOWNLOADING };
80+
return { status: UpdateCheckStatus.Downloading };
7981
} else if (status === false) {
80-
return { status: updateCheckStatusEnum.NOTAVAILABLE };
82+
return { status: UpdateCheckStatus.NotAvailable };
8183
} else {
8284
return {
83-
status: updateCheckStatusEnum.ERROR,
85+
status: UpdateCheckStatus.Error,
8486
detail: status,
8587
};
8688
}
@@ -214,12 +216,10 @@ export default class ElectronPlatform extends VectorBasePlatform {
214216
or the error if one is encountered
215217
*/
216218
ipcRenderer.on('check_updates', (event, status) => {
217-
if (!this.showUpdateCheck) return;
218-
dis.dispatch({
219-
action: 'check_updates',
220-
value: getUpdateCheckStatus(status),
219+
dis.dispatch<CheckUpdatesPayload>({
220+
action: Action.CheckUpdates,
221+
...getUpdateCheckStatus(status),
221222
});
222-
this.showUpdateCheck = false;
223223
});
224224

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

387387
startUpdateCheck() {
388-
if (this.showUpdateCheck) return;
389388
super.startUpdateCheck();
390-
391389
ipcRenderer.send('check_updates');
392390
}
393391

‎src/vector/platform/VectorBasePlatform.ts‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ limitations under the License.
1818
*/
1919

2020
import BasePlatform from 'matrix-react-sdk/src/BasePlatform';
21-
import { _t } from 'matrix-react-sdk/src/languageHandler';
22-
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
21+
import {_t} from 'matrix-react-sdk/src/languageHandler';
2322
import {getVectorConfig} from "../getconfig";
2423

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

4240
constructor() {
4341
super();
4442

4543
this.startUpdateCheck = this.startUpdateCheck.bind(this);
46-
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
4744
}
4845

4946
async getConfig(): Promise<{}> {
@@ -96,33 +93,6 @@ export default abstract class VectorBasePlatform extends BasePlatform {
9693
startUpdater() {
9794
}
9895

99-
/**
100-
* Whether we can call checkForUpdate on this platform build
101-
*/
102-
async canSelfUpdate(): Promise<boolean> {
103-
return false;
104-
}
105-
106-
startUpdateCheck() {
107-
this.showUpdateCheck = true;
108-
dis.dispatch({
109-
action: 'check_updates',
110-
value: { status: updateCheckStatusEnum.CHECKING },
111-
});
112-
}
113-
114-
stopUpdateCheck() {
115-
this.showUpdateCheck = false;
116-
dis.dispatch({
117-
action: 'check_updates',
118-
value: false,
119-
});
120-
}
121-
122-
getUpdateCheckStatusEnum() {
123-
return updateCheckStatusEnum;
124-
}
125-
12696
/**
12797
* Update the currently running app to the latest available
12898
* version and replace this instance of the app with the

‎src/vector/platform/WebPlatform.ts‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
1818

19-
import VectorBasePlatform, {updateCheckStatusEnum} from './VectorBasePlatform';
19+
import VectorBasePlatform from './VectorBasePlatform';
20+
import {UpdateCheckStatus} from "matrix-react-sdk/src/BasePlatform";
2021
import request from 'browser-request';
2122
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
22-
import { _t } from 'matrix-react-sdk/src/languageHandler';
23+
import {_t} from 'matrix-react-sdk/src/languageHandler';
2324
import {Room} from "matrix-js-sdk/src/models/room";
24-
import { showToast as showUpdateToast, hideToast as hideUpdateToast } from "matrix-react-sdk/src/toasts/UpdateToast";
25+
import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateToast";
26+
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
27+
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
2528

2629
import url from 'url';
2730
import UAParser from 'ua-parser-js';
@@ -136,36 +139,29 @@ export default class WebPlatform extends VectorBasePlatform {
136139
return this._getVersion().then((ver) => {
137140
if (this.runningVersion === null) {
138141
this.runningVersion = ver;
139-
return;
140-
}
141-
142-
if (this.runningVersion !== ver) {
142+
} else if (this.runningVersion !== ver) {
143143
showUpdateToast(this.runningVersion, ver);
144-
// Return to skip a MatrixChat state update
145-
return;
144+
return { status: UpdateCheckStatus.Ready };
146145
} else {
147146
hideUpdateToast();
148147
}
149148

150-
return { status: updateCheckStatusEnum.NOTAVAILABLE };
149+
return { status: UpdateCheckStatus.NotAvailable };
151150
}, (err) => {
152151
console.error("Failed to poll for update", err);
153152
return {
154-
status: updateCheckStatusEnum.ERROR,
153+
status: UpdateCheckStatus.Error,
155154
detail: err.message || err.status ? err.status.toString() : 'Unknown Error',
156155
};
157156
});
158157
};
159158

160159
startUpdateCheck() {
161-
if (this.showUpdateCheck) return;
162160
super.startUpdateCheck();
163161
this.pollForUpdate().then((updateState) => {
164-
if (!this.showUpdateCheck) return;
165-
if (!updateState) return;
166-
dis.dispatch({
167-
action: 'check_updates',
168-
value: updateState,
162+
dis.dispatch<CheckUpdatesPayload>({
163+
action: Action.CheckUpdates,
164+
...updateState,
169165
});
170166
});
171167
}

0 commit comments

Comments
 (0)