Improve Typescript in `BasePlatform` (#8768)

* Improve Typescript in `BasePlatform`

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

* `installUpdate()` should not be abstract

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/28217/head
Šimon Brandner 2022-06-06 08:31:20 +02:00 committed by GitHub
parent a6da89481c
commit 125a265806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 48 deletions

View File

@ -63,11 +63,11 @@ export default abstract class BasePlatform {
this.startUpdateCheck = this.startUpdateCheck.bind(this);
}
abstract getConfig(): Promise<IConfigOptions>;
public abstract getConfig(): Promise<IConfigOptions>;
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<boolean> {
public async canSelfUpdate(): Promise<boolean> {
return false;
}
startUpdateCheck() {
public startUpdateCheck(): void {
hideUpdateToast();
localStorage.removeItem(UPDATE_DEFER_KEY);
dis.dispatch<CheckUpdatesPayload>({
@ -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<string>;
public abstract requestNotificationPermission(): Promise<string>;
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<string>;
public abstract getAppVersion(): Promise<string>;
/*
* 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<boolean> {
public async getAutoLaunchEnabled(): Promise<boolean> {
return false;
}
async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
public async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
throw new Error("Unimplemented");
}
supportsWarnBeforeExit(): boolean {
public supportsWarnBeforeExit(): boolean {
return false;
}
async shouldWarnBeforeExit(): Promise<boolean> {
public async shouldWarnBeforeExit(): Promise<boolean> {
return false;
}
async setWarnBeforeExit(enabled: boolean): Promise<void> {
public async setWarnBeforeExit(enabled: boolean): Promise<void> {
throw new Error("Unimplemented");
}
supportsAutoHideMenuBar(): boolean {
public supportsAutoHideMenuBar(): boolean {
return false;
}
async getAutoHideMenuBarEnabled(): Promise<boolean> {
public async getAutoHideMenuBarEnabled(): Promise<boolean> {
return false;
}
async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
public async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
throw new Error("Unimplemented");
}
supportsMinimizeToTray(): boolean {
public supportsMinimizeToTray(): boolean {
return false;
}
async getMinimizeToTrayEnabled(): Promise<boolean> {
public async getMinimizeToTrayEnabled(): Promise<boolean> {
return false;
}
async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
public async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
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<string[]> | null {
public getSpellCheckLanguages(): Promise<string[]> | null {
return null;
}
async getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>> {
public async getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>> {
return [];
}
supportsDesktopCapturer(): boolean {
public supportsDesktopCapturer(): boolean {
return false;
}
@ -335,7 +333,7 @@ export default abstract class BasePlatform {
public navigateForwardBack(back: boolean): void {}
getAvailableSpellCheckLanguages(): Promise<string[]> | null {
public getAvailableSpellCheckLanguages(): Promise<string[]> | 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<string | null> {
public async getPickleKey(userId: string, deviceId: string): Promise<string | null> {
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<string | null> {
public async createPickleKey(userId: string, deviceId: string): Promise<string | null> {
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<void> {
public async destroyPickleKey(userId: string, deviceId: string): Promise<void> {
try {
await idbDelete("pickleKey", [userId, deviceId]);
} catch (e) {