Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ec9117d

Browse files
SimonBrandnert3chguy
authored andcommitted
Improve Typescript in BasePlatform (#8768)
* Improve Typescript in `BasePlatform` Signed-off-by: Šimon Brandner <[email protected]> * `installUpdate()` should not be abstract Signed-off-by: Šimon Brandner <[email protected]> (cherry picked from commit 125a265)
1 parent 0841aca commit ec9117d

File tree

1 file changed

+47
-48
lines changed

1 file changed

+47
-48
lines changed

src/BasePlatform.ts

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ export default abstract class BasePlatform {
6363
this.startUpdateCheck = this.startUpdateCheck.bind(this);
6464
}
6565

66-
abstract getConfig(): Promise<IConfigOptions>;
66+
public abstract getConfig(): Promise<IConfigOptions>;
6767

68-
abstract getDefaultDeviceDisplayName(): string;
68+
public abstract getDefaultDeviceDisplayName(): string;
6969

70-
protected onAction = (payload: ActionPayload) => {
70+
protected onAction = (payload: ActionPayload): void => {
7171
switch (payload.action) {
7272
case 'on_client_not_viable':
7373
case Action.OnLoggedOut:
@@ -77,24 +77,24 @@ export default abstract class BasePlatform {
7777
};
7878

7979
// Used primarily for Analytics
80-
abstract getHumanReadableName(): string;
80+
public abstract getHumanReadableName(): string;
8181

82-
setNotificationCount(count: number) {
82+
public setNotificationCount(count: number): void {
8383
this.notificationCount = count;
8484
}
8585

86-
setErrorStatus(errorDidOccur: boolean) {
86+
public setErrorStatus(errorDidOccur: boolean): void {
8787
this.errorDidOccur = errorDidOccur;
8888
}
8989

9090
/**
9191
* Whether we can call checkForUpdate on this platform build
9292
*/
93-
async canSelfUpdate(): Promise<boolean> {
93+
public async canSelfUpdate(): Promise<boolean> {
9494
return false;
9595
}
9696

97-
startUpdateCheck() {
97+
public startUpdateCheck(): void {
9898
hideUpdateToast();
9999
localStorage.removeItem(UPDATE_DEFER_KEY);
100100
dis.dispatch<CheckUpdatesPayload>({
@@ -107,8 +107,7 @@ export default abstract class BasePlatform {
107107
* Update the currently running app to the latest available version
108108
* and replace this instance of the app with the new version.
109109
*/
110-
installUpdate() {
111-
}
110+
public installUpdate(): void {}
112111

113112
/**
114113
* Check if the version update has been deferred and that deferment is still in effect
@@ -130,7 +129,7 @@ export default abstract class BasePlatform {
130129
* Ignore the pending update and don't prompt about this version
131130
* until the next morning (8am).
132131
*/
133-
deferUpdate(newVersion: string) {
132+
public deferUpdate(newVersion: string): void {
134133
const date = new Date(Date.now() + 24 * 60 * 60 * 1000);
135134
date.setHours(8, 0, 0, 0); // set to next 8am
136135
localStorage.setItem(UPDATE_DEFER_KEY, JSON.stringify([newVersion, date.getTime()]));
@@ -141,7 +140,7 @@ export default abstract class BasePlatform {
141140
* Return true if platform supports multi-language
142141
* spell-checking, otherwise false.
143142
*/
144-
supportsMultiLanguageSpellCheck(): boolean {
143+
public supportsMultiLanguageSpellCheck(): boolean {
145144
return false;
146145
}
147146

@@ -157,7 +156,7 @@ export default abstract class BasePlatform {
157156
* notifications, otherwise false.
158157
* @returns {boolean} whether the platform supports displaying notifications
159158
*/
160-
supportsNotifications(): boolean {
159+
public supportsNotifications(): boolean {
161160
return false;
162161
}
163162

@@ -166,7 +165,7 @@ export default abstract class BasePlatform {
166165
* to display notifications. Otherwise false.
167166
* @returns {boolean} whether the application has permission to display notifications
168167
*/
169-
maySendNotifications(): boolean {
168+
public maySendNotifications(): boolean {
170169
return false;
171170
}
172171

@@ -177,7 +176,7 @@ export default abstract class BasePlatform {
177176
* that is 'granted' if the user allowed the request or
178177
* 'denied' otherwise.
179178
*/
180-
abstract requestNotificationPermission(): Promise<string>;
179+
public abstract requestNotificationPermission(): Promise<string>;
181180

182181
public displayNotification(
183182
title: string,
@@ -211,10 +210,9 @@ export default abstract class BasePlatform {
211210
return notification;
212211
}
213212

214-
loudNotification(ev: MatrixEvent, room: Room) {
215-
}
213+
public loudNotification(ev: MatrixEvent, room: Room): void {}
216214

217-
clearNotification(notif: Notification) {
215+
public clearNotification(notif: Notification): void {
218216
// Some browsers don't support this, e.g Safari on iOS
219217
// https://developer.mozilla.org/en-US/docs/Web/API/Notification/close
220218
if (notif.close) {
@@ -225,69 +223,69 @@ export default abstract class BasePlatform {
225223
/**
226224
* Returns a promise that resolves to a string representing the current version of the application.
227225
*/
228-
abstract getAppVersion(): Promise<string>;
226+
public abstract getAppVersion(): Promise<string>;
229227

230228
/*
231229
* If it's not expected that capturing the screen will work
232230
* with getUserMedia, return a string explaining why not.
233231
* Otherwise, return null.
234232
*/
235-
screenCaptureErrorString(): string {
233+
public screenCaptureErrorString(): string {
236234
return "Not implemented";
237235
}
238236

239237
/**
240238
* Restarts the application, without necessarily reloading
241239
* any application code
242240
*/
243-
abstract reload();
241+
public abstract reload(): void;
244242

245-
supportsAutoLaunch(): boolean {
243+
public supportsAutoLaunch(): boolean {
246244
return false;
247245
}
248246

249247
// XXX: Surely this should be a setting like any other?
250-
async getAutoLaunchEnabled(): Promise<boolean> {
248+
public async getAutoLaunchEnabled(): Promise<boolean> {
251249
return false;
252250
}
253251

254-
async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
252+
public async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
255253
throw new Error("Unimplemented");
256254
}
257255

258-
supportsWarnBeforeExit(): boolean {
256+
public supportsWarnBeforeExit(): boolean {
259257
return false;
260258
}
261259

262-
async shouldWarnBeforeExit(): Promise<boolean> {
260+
public async shouldWarnBeforeExit(): Promise<boolean> {
263261
return false;
264262
}
265263

266-
async setWarnBeforeExit(enabled: boolean): Promise<void> {
264+
public async setWarnBeforeExit(enabled: boolean): Promise<void> {
267265
throw new Error("Unimplemented");
268266
}
269267

270-
supportsAutoHideMenuBar(): boolean {
268+
public supportsAutoHideMenuBar(): boolean {
271269
return false;
272270
}
273271

274-
async getAutoHideMenuBarEnabled(): Promise<boolean> {
272+
public async getAutoHideMenuBarEnabled(): Promise<boolean> {
275273
return false;
276274
}
277275

278-
async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
276+
public async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
279277
throw new Error("Unimplemented");
280278
}
281279

282-
supportsMinimizeToTray(): boolean {
280+
public supportsMinimizeToTray(): boolean {
283281
return false;
284282
}
285283

286-
async getMinimizeToTrayEnabled(): Promise<boolean> {
284+
public async getMinimizeToTrayEnabled(): Promise<boolean> {
287285
return false;
288286
}
289287

290-
async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
288+
public async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
291289
throw new Error("Unimplemented");
292290
}
293291

@@ -309,23 +307,23 @@ export default abstract class BasePlatform {
309307
* @return {BaseEventIndexManager} The EventIndex manager for our platform,
310308
* can be null if the platform doesn't support event indexing.
311309
*/
312-
getEventIndexingManager(): BaseEventIndexManager | null {
310+
public getEventIndexingManager(): BaseEventIndexManager | null {
313311
return null;
314312
}
315313

316-
async setLanguage(preferredLangs: string[]) {}
314+
public setLanguage(preferredLangs: string[]) {}
317315

318-
setSpellCheckLanguages(preferredLangs: string[]) {}
316+
public setSpellCheckLanguages(preferredLangs: string[]) {}
319317

320-
getSpellCheckLanguages(): Promise<string[]> | null {
318+
public getSpellCheckLanguages(): Promise<string[]> | null {
321319
return null;
322320
}
323321

324-
async getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>> {
322+
public async getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>> {
325323
return [];
326324
}
327325

328-
supportsDesktopCapturer(): boolean {
326+
public supportsDesktopCapturer(): boolean {
329327
return false;
330328
}
331329

@@ -335,7 +333,7 @@ export default abstract class BasePlatform {
335333

336334
public navigateForwardBack(back: boolean): void {}
337335

338-
getAvailableSpellCheckLanguages(): Promise<string[]> | null {
336+
public getAvailableSpellCheckLanguages(): Promise<string[]> | null {
339337
return null;
340338
}
341339

@@ -352,7 +350,12 @@ export default abstract class BasePlatform {
352350
* @param {string} fragmentAfterLogin the hash to pass to the app during sso callback.
353351
* @param {string} idpId The ID of the Identity Provider being targeted, optional.
354352
*/
355-
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string, idpId?: string) {
353+
public startSingleSignOn(
354+
mxClient: MatrixClient,
355+
loginType: "sso" | "cas",
356+
fragmentAfterLogin: string,
357+
idpId?: string,
358+
): void {
356359
// persist hs url and is url for when the user is returned to the app with the login token
357360
localStorage.setItem(SSO_HOMESERVER_URL_KEY, mxClient.getHomeserverUrl());
358361
if (mxClient.getIdentityServerUrl()) {
@@ -365,10 +368,6 @@ export default abstract class BasePlatform {
365368
window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType, idpId); // redirect to SSO
366369
}
367370

368-
onKeyDown(ev: KeyboardEvent): boolean {
369-
return false; // no shortcuts implemented
370-
}
371-
372371
/**
373372
* Get a previously stored pickle key. The pickle key is used for
374373
* encrypting libolm objects.
@@ -377,7 +376,7 @@ export default abstract class BasePlatform {
377376
* @returns {string|null} the previously stored pickle key, or null if no
378377
* pickle key has been stored.
379378
*/
380-
async getPickleKey(userId: string, deviceId: string): Promise<string | null> {
379+
public async getPickleKey(userId: string, deviceId: string): Promise<string | null> {
381380
if (!window.crypto || !window.crypto.subtle) {
382381
return null;
383382
}
@@ -423,7 +422,7 @@ export default abstract class BasePlatform {
423422
* @returns {string|null} the pickle key, or null if the platform does not
424423
* support storing pickle keys.
425424
*/
426-
async createPickleKey(userId: string, deviceId: string): Promise<string | null> {
425+
public async createPickleKey(userId: string, deviceId: string): Promise<string | null> {
427426
if (!window.crypto || !window.crypto.subtle) {
428427
return null;
429428
}
@@ -462,7 +461,7 @@ export default abstract class BasePlatform {
462461
* @param {string} userId the user ID for the user that the pickle key is for.
463462
* @param {string} userId the device ID that the pickle key is for.
464463
*/
465-
async destroyPickleKey(userId: string, deviceId: string): Promise<void> {
464+
public async destroyPickleKey(userId: string, deviceId: string): Promise<void> {
466465
try {
467466
await idbDelete("pickleKey", [userId, deviceId]);
468467
} catch (e) {

0 commit comments

Comments
 (0)