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>
(cherry picked from commit 125a265806
)
This commit is contained in:
parent
0841aca2a4
commit
ec9117dbd1
1 changed files with 47 additions and 48 deletions
|
@ -63,11 +63,11 @@ export default abstract class BasePlatform {
|
||||||
this.startUpdateCheck = this.startUpdateCheck.bind(this);
|
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) {
|
switch (payload.action) {
|
||||||
case 'on_client_not_viable':
|
case 'on_client_not_viable':
|
||||||
case Action.OnLoggedOut:
|
case Action.OnLoggedOut:
|
||||||
|
@ -77,24 +77,24 @@ export default abstract class BasePlatform {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used primarily for Analytics
|
// Used primarily for Analytics
|
||||||
abstract getHumanReadableName(): string;
|
public abstract getHumanReadableName(): string;
|
||||||
|
|
||||||
setNotificationCount(count: number) {
|
public setNotificationCount(count: number): void {
|
||||||
this.notificationCount = count;
|
this.notificationCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
setErrorStatus(errorDidOccur: boolean) {
|
public setErrorStatus(errorDidOccur: boolean): void {
|
||||||
this.errorDidOccur = errorDidOccur;
|
this.errorDidOccur = errorDidOccur;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether we can call checkForUpdate on this platform build
|
* Whether we can call checkForUpdate on this platform build
|
||||||
*/
|
*/
|
||||||
async canSelfUpdate(): Promise<boolean> {
|
public async canSelfUpdate(): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
startUpdateCheck() {
|
public startUpdateCheck(): void {
|
||||||
hideUpdateToast();
|
hideUpdateToast();
|
||||||
localStorage.removeItem(UPDATE_DEFER_KEY);
|
localStorage.removeItem(UPDATE_DEFER_KEY);
|
||||||
dis.dispatch<CheckUpdatesPayload>({
|
dis.dispatch<CheckUpdatesPayload>({
|
||||||
|
@ -107,8 +107,7 @@ export default abstract class BasePlatform {
|
||||||
* Update the currently running app to the latest available version
|
* Update the currently running app to the latest available version
|
||||||
* and replace this instance of the app with the new 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
|
* 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
|
* Ignore the pending update and don't prompt about this version
|
||||||
* until the next morning (8am).
|
* until the next morning (8am).
|
||||||
*/
|
*/
|
||||||
deferUpdate(newVersion: string) {
|
public deferUpdate(newVersion: string): void {
|
||||||
const date = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
const date = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||||
date.setHours(8, 0, 0, 0); // set to next 8am
|
date.setHours(8, 0, 0, 0); // set to next 8am
|
||||||
localStorage.setItem(UPDATE_DEFER_KEY, JSON.stringify([newVersion, date.getTime()]));
|
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
|
* Return true if platform supports multi-language
|
||||||
* spell-checking, otherwise false.
|
* spell-checking, otherwise false.
|
||||||
*/
|
*/
|
||||||
supportsMultiLanguageSpellCheck(): boolean {
|
public supportsMultiLanguageSpellCheck(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +156,7 @@ export default abstract class BasePlatform {
|
||||||
* notifications, otherwise false.
|
* notifications, otherwise false.
|
||||||
* @returns {boolean} whether the platform supports displaying notifications
|
* @returns {boolean} whether the platform supports displaying notifications
|
||||||
*/
|
*/
|
||||||
supportsNotifications(): boolean {
|
public supportsNotifications(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +165,7 @@ export default abstract class BasePlatform {
|
||||||
* to display notifications. Otherwise false.
|
* to display notifications. Otherwise false.
|
||||||
* @returns {boolean} whether the application has permission to display notifications
|
* @returns {boolean} whether the application has permission to display notifications
|
||||||
*/
|
*/
|
||||||
maySendNotifications(): boolean {
|
public maySendNotifications(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +176,7 @@ export default abstract class BasePlatform {
|
||||||
* that is 'granted' if the user allowed the request or
|
* that is 'granted' if the user allowed the request or
|
||||||
* 'denied' otherwise.
|
* 'denied' otherwise.
|
||||||
*/
|
*/
|
||||||
abstract requestNotificationPermission(): Promise<string>;
|
public abstract requestNotificationPermission(): Promise<string>;
|
||||||
|
|
||||||
public displayNotification(
|
public displayNotification(
|
||||||
title: string,
|
title: string,
|
||||||
|
@ -211,10 +210,9 @@ export default abstract class BasePlatform {
|
||||||
return notification;
|
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
|
// Some browsers don't support this, e.g Safari on iOS
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Notification/close
|
// https://developer.mozilla.org/en-US/docs/Web/API/Notification/close
|
||||||
if (notif.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.
|
* 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
|
* If it's not expected that capturing the screen will work
|
||||||
* with getUserMedia, return a string explaining why not.
|
* with getUserMedia, return a string explaining why not.
|
||||||
* Otherwise, return null.
|
* Otherwise, return null.
|
||||||
*/
|
*/
|
||||||
screenCaptureErrorString(): string {
|
public screenCaptureErrorString(): string {
|
||||||
return "Not implemented";
|
return "Not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,54 +238,54 @@ export default abstract class BasePlatform {
|
||||||
* Restarts the application, without necessarily reloading
|
* Restarts the application, without necessarily reloading
|
||||||
* any application code
|
* any application code
|
||||||
*/
|
*/
|
||||||
abstract reload();
|
public abstract reload(): void;
|
||||||
|
|
||||||
supportsAutoLaunch(): boolean {
|
public supportsAutoLaunch(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: Surely this should be a setting like any other?
|
// XXX: Surely this should be a setting like any other?
|
||||||
async getAutoLaunchEnabled(): Promise<boolean> {
|
public async getAutoLaunchEnabled(): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
|
public async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
|
||||||
throw new Error("Unimplemented");
|
throw new Error("Unimplemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsWarnBeforeExit(): boolean {
|
public supportsWarnBeforeExit(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async shouldWarnBeforeExit(): Promise<boolean> {
|
public async shouldWarnBeforeExit(): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setWarnBeforeExit(enabled: boolean): Promise<void> {
|
public async setWarnBeforeExit(enabled: boolean): Promise<void> {
|
||||||
throw new Error("Unimplemented");
|
throw new Error("Unimplemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsAutoHideMenuBar(): boolean {
|
public supportsAutoHideMenuBar(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAutoHideMenuBarEnabled(): Promise<boolean> {
|
public async getAutoHideMenuBarEnabled(): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
|
public async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
|
||||||
throw new Error("Unimplemented");
|
throw new Error("Unimplemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsMinimizeToTray(): boolean {
|
public supportsMinimizeToTray(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMinimizeToTrayEnabled(): Promise<boolean> {
|
public async getMinimizeToTrayEnabled(): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
|
public async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
|
||||||
throw new Error("Unimplemented");
|
throw new Error("Unimplemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,23 +307,23 @@ export default abstract class BasePlatform {
|
||||||
* @return {BaseEventIndexManager} The EventIndex manager for our platform,
|
* @return {BaseEventIndexManager} The EventIndex manager for our platform,
|
||||||
* can be null if the platform doesn't support event indexing.
|
* can be null if the platform doesn't support event indexing.
|
||||||
*/
|
*/
|
||||||
getEventIndexingManager(): BaseEventIndexManager | null {
|
public getEventIndexingManager(): BaseEventIndexManager | null {
|
||||||
return 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>> {
|
public async getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
supportsDesktopCapturer(): boolean {
|
public supportsDesktopCapturer(): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +333,7 @@ export default abstract class BasePlatform {
|
||||||
|
|
||||||
public navigateForwardBack(back: boolean): void {}
|
public navigateForwardBack(back: boolean): void {}
|
||||||
|
|
||||||
getAvailableSpellCheckLanguages(): Promise<string[]> | null {
|
public getAvailableSpellCheckLanguages(): Promise<string[]> | null {
|
||||||
return 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} fragmentAfterLogin the hash to pass to the app during sso callback.
|
||||||
* @param {string} idpId The ID of the Identity Provider being targeted, optional.
|
* @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
|
// 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());
|
localStorage.setItem(SSO_HOMESERVER_URL_KEY, mxClient.getHomeserverUrl());
|
||||||
if (mxClient.getIdentityServerUrl()) {
|
if (mxClient.getIdentityServerUrl()) {
|
||||||
|
@ -365,10 +368,6 @@ export default abstract class BasePlatform {
|
||||||
window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType, idpId); // redirect to SSO
|
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
|
* Get a previously stored pickle key. The pickle key is used for
|
||||||
* encrypting libolm objects.
|
* encrypting libolm objects.
|
||||||
|
@ -377,7 +376,7 @@ export default abstract class BasePlatform {
|
||||||
* @returns {string|null} the previously stored pickle key, or null if no
|
* @returns {string|null} the previously stored pickle key, or null if no
|
||||||
* pickle key has been stored.
|
* 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) {
|
if (!window.crypto || !window.crypto.subtle) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -423,7 +422,7 @@ export default abstract class BasePlatform {
|
||||||
* @returns {string|null} the pickle key, or null if the platform does not
|
* @returns {string|null} the pickle key, or null if the platform does not
|
||||||
* support storing pickle keys.
|
* 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) {
|
if (!window.crypto || !window.crypto.subtle) {
|
||||||
return null;
|
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 user ID for the user that the pickle key is for.
|
||||||
* @param {string} userId the device ID 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 {
|
try {
|
||||||
await idbDelete("pickleKey", [userId, deviceId]);
|
await idbDelete("pickleKey", [userId, deviceId]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue