From 125a265806aab82c5423003ee22d66132f23b20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 6 Jun 2022 08:31:20 +0200 Subject: [PATCH] Improve Typescript in `BasePlatform` (#8768) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Improve Typescript in `BasePlatform` Signed-off-by: Šimon Brandner * `installUpdate()` should not be abstract Signed-off-by: Šimon Brandner --- src/BasePlatform.ts | 95 ++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index 9de1122430..630d56f06b 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -63,11 +63,11 @@ export default abstract class BasePlatform { this.startUpdateCheck = this.startUpdateCheck.bind(this); } - abstract getConfig(): Promise; + public abstract getConfig(): Promise; - abstract getDefaultDeviceDisplayName(): string; + public abstract getDefaultDeviceDisplayName(): string; - protected onAction = (payload: ActionPayload) => { + protected onAction = (payload: ActionPayload): void => { switch (payload.action) { case 'on_client_not_viable': case Action.OnLoggedOut: @@ -77,24 +77,24 @@ export default abstract class BasePlatform { }; // Used primarily for Analytics - abstract getHumanReadableName(): string; + public abstract getHumanReadableName(): string; - setNotificationCount(count: number) { + public setNotificationCount(count: number): void { this.notificationCount = count; } - setErrorStatus(errorDidOccur: boolean) { + public setErrorStatus(errorDidOccur: boolean): void { this.errorDidOccur = errorDidOccur; } /** * Whether we can call checkForUpdate on this platform build */ - async canSelfUpdate(): Promise { + public async canSelfUpdate(): Promise { return false; } - startUpdateCheck() { + public startUpdateCheck(): void { hideUpdateToast(); localStorage.removeItem(UPDATE_DEFER_KEY); dis.dispatch({ @@ -107,8 +107,7 @@ export default abstract class BasePlatform { * Update the currently running app to the latest available version * and replace this instance of the app with the new version. */ - installUpdate() { - } + public installUpdate(): void {} /** * Check if the version update has been deferred and that deferment is still in effect @@ -130,7 +129,7 @@ export default abstract class BasePlatform { * Ignore the pending update and don't prompt about this version * until the next morning (8am). */ - deferUpdate(newVersion: string) { + public deferUpdate(newVersion: string): void { const date = new Date(Date.now() + 24 * 60 * 60 * 1000); date.setHours(8, 0, 0, 0); // set to next 8am localStorage.setItem(UPDATE_DEFER_KEY, JSON.stringify([newVersion, date.getTime()])); @@ -141,7 +140,7 @@ export default abstract class BasePlatform { * Return true if platform supports multi-language * spell-checking, otherwise false. */ - supportsMultiLanguageSpellCheck(): boolean { + public supportsMultiLanguageSpellCheck(): boolean { return false; } @@ -157,7 +156,7 @@ export default abstract class BasePlatform { * notifications, otherwise false. * @returns {boolean} whether the platform supports displaying notifications */ - supportsNotifications(): boolean { + public supportsNotifications(): boolean { return false; } @@ -166,7 +165,7 @@ export default abstract class BasePlatform { * to display notifications. Otherwise false. * @returns {boolean} whether the application has permission to display notifications */ - maySendNotifications(): boolean { + public maySendNotifications(): boolean { return false; } @@ -177,7 +176,7 @@ export default abstract class BasePlatform { * that is 'granted' if the user allowed the request or * 'denied' otherwise. */ - abstract requestNotificationPermission(): Promise; + public abstract requestNotificationPermission(): Promise; public displayNotification( title: string, @@ -211,10 +210,9 @@ export default abstract class BasePlatform { return notification; } - loudNotification(ev: MatrixEvent, room: Room) { - } + public loudNotification(ev: MatrixEvent, room: Room): void {} - clearNotification(notif: Notification) { + public clearNotification(notif: Notification): void { // Some browsers don't support this, e.g Safari on iOS // https://developer.mozilla.org/en-US/docs/Web/API/Notification/close if (notif.close) { @@ -225,14 +223,14 @@ export default abstract class BasePlatform { /** * Returns a promise that resolves to a string representing the current version of the application. */ - abstract getAppVersion(): Promise; + public abstract getAppVersion(): Promise; /* * If it's not expected that capturing the screen will work * with getUserMedia, return a string explaining why not. * Otherwise, return null. */ - screenCaptureErrorString(): string { + public screenCaptureErrorString(): string { return "Not implemented"; } @@ -240,54 +238,54 @@ export default abstract class BasePlatform { * Restarts the application, without necessarily reloading * any application code */ - abstract reload(); + public abstract reload(): void; - supportsAutoLaunch(): boolean { + public supportsAutoLaunch(): boolean { return false; } // XXX: Surely this should be a setting like any other? - async getAutoLaunchEnabled(): Promise { + public async getAutoLaunchEnabled(): Promise { return false; } - async setAutoLaunchEnabled(enabled: boolean): Promise { + public async setAutoLaunchEnabled(enabled: boolean): Promise { throw new Error("Unimplemented"); } - supportsWarnBeforeExit(): boolean { + public supportsWarnBeforeExit(): boolean { return false; } - async shouldWarnBeforeExit(): Promise { + public async shouldWarnBeforeExit(): Promise { return false; } - async setWarnBeforeExit(enabled: boolean): Promise { + public async setWarnBeforeExit(enabled: boolean): Promise { throw new Error("Unimplemented"); } - supportsAutoHideMenuBar(): boolean { + public supportsAutoHideMenuBar(): boolean { return false; } - async getAutoHideMenuBarEnabled(): Promise { + public async getAutoHideMenuBarEnabled(): Promise { return false; } - async setAutoHideMenuBarEnabled(enabled: boolean): Promise { + public async setAutoHideMenuBarEnabled(enabled: boolean): Promise { throw new Error("Unimplemented"); } - supportsMinimizeToTray(): boolean { + public supportsMinimizeToTray(): boolean { return false; } - async getMinimizeToTrayEnabled(): Promise { + public async getMinimizeToTrayEnabled(): Promise { return false; } - async setMinimizeToTrayEnabled(enabled: boolean): Promise { + public async setMinimizeToTrayEnabled(enabled: boolean): Promise { throw new Error("Unimplemented"); } @@ -309,23 +307,23 @@ export default abstract class BasePlatform { * @return {BaseEventIndexManager} The EventIndex manager for our platform, * can be null if the platform doesn't support event indexing. */ - getEventIndexingManager(): BaseEventIndexManager | null { + public getEventIndexingManager(): BaseEventIndexManager | null { return null; } - async setLanguage(preferredLangs: string[]) {} + public setLanguage(preferredLangs: string[]) {} - setSpellCheckLanguages(preferredLangs: string[]) {} + public setSpellCheckLanguages(preferredLangs: string[]) {} - getSpellCheckLanguages(): Promise | null { + public getSpellCheckLanguages(): Promise | null { return null; } - async getDesktopCapturerSources(options: GetSourcesOptions): Promise> { + public async getDesktopCapturerSources(options: GetSourcesOptions): Promise> { return []; } - supportsDesktopCapturer(): boolean { + public supportsDesktopCapturer(): boolean { return false; } @@ -335,7 +333,7 @@ export default abstract class BasePlatform { public navigateForwardBack(back: boolean): void {} - getAvailableSpellCheckLanguages(): Promise | null { + public getAvailableSpellCheckLanguages(): Promise | null { return null; } @@ -352,7 +350,12 @@ export default abstract class BasePlatform { * @param {string} fragmentAfterLogin the hash to pass to the app during sso callback. * @param {string} idpId The ID of the Identity Provider being targeted, optional. */ - startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string, idpId?: string) { + public startSingleSignOn( + mxClient: MatrixClient, + loginType: "sso" | "cas", + fragmentAfterLogin: string, + idpId?: string, + ): void { // persist hs url and is url for when the user is returned to the app with the login token localStorage.setItem(SSO_HOMESERVER_URL_KEY, mxClient.getHomeserverUrl()); if (mxClient.getIdentityServerUrl()) { @@ -365,10 +368,6 @@ export default abstract class BasePlatform { window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType, idpId); // redirect to SSO } - onKeyDown(ev: KeyboardEvent): boolean { - return false; // no shortcuts implemented - } - /** * Get a previously stored pickle key. The pickle key is used for * encrypting libolm objects. @@ -377,7 +376,7 @@ export default abstract class BasePlatform { * @returns {string|null} the previously stored pickle key, or null if no * pickle key has been stored. */ - async getPickleKey(userId: string, deviceId: string): Promise { + public async getPickleKey(userId: string, deviceId: string): Promise { if (!window.crypto || !window.crypto.subtle) { return null; } @@ -423,7 +422,7 @@ export default abstract class BasePlatform { * @returns {string|null} the pickle key, or null if the platform does not * support storing pickle keys. */ - async createPickleKey(userId: string, deviceId: string): Promise { + public async createPickleKey(userId: string, deviceId: string): Promise { if (!window.crypto || !window.crypto.subtle) { return null; } @@ -462,7 +461,7 @@ export default abstract class BasePlatform { * @param {string} userId the user ID for the user that the pickle key is for. * @param {string} userId the device ID that the pickle key is for. */ - async destroyPickleKey(userId: string, deviceId: string): Promise { + public async destroyPickleKey(userId: string, deviceId: string): Promise { try { await idbDelete("pickleKey", [userId, deviceId]); } catch (e) {