2016-11-02 23:10:21 +08:00
|
|
|
/*
|
2016-11-03 19:47:57 +08:00
|
|
|
Copyright 2016 Aviral Dasgupta
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2018-12-19 01:40:30 +08:00
|
|
|
Copyright 2018 New Vector Ltd
|
2020-03-02 22:59:54 +08:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2016-11-02 23:10:21 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
import {MatrixClient} from "matrix-js-sdk/src/client";
|
2020-05-14 10:41:41 +08:00
|
|
|
import dis from './dispatcher/dispatcher';
|
2019-11-19 19:52:12 +08:00
|
|
|
import BaseEventIndexManager from './indexing/BaseEventIndexManager';
|
2020-05-22 01:06:36 +08:00
|
|
|
import {ActionPayload} from "./dispatcher/payloads";
|
2017-06-21 01:47:35 +08:00
|
|
|
|
2016-11-02 23:10:21 +08:00
|
|
|
/**
|
|
|
|
* Base class for classes that provide platform-specific functionality
|
|
|
|
* eg. Setting an application badge or displaying notifications
|
|
|
|
*
|
|
|
|
* Instances of this class are provided by the application.
|
|
|
|
*/
|
2020-05-22 01:06:36 +08:00
|
|
|
export default abstract class BasePlatform {
|
2020-05-22 01:11:21 +08:00
|
|
|
protected notificationCount = 0;
|
|
|
|
protected errorDidOccur = false;
|
2017-06-21 01:47:35 +08:00
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
constructor() {
|
|
|
|
dis.register(this.onAction);
|
2017-06-21 01:47:35 +08:00
|
|
|
}
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
protected onAction = (payload: ActionPayload) => {
|
2017-06-21 01:47:35 +08:00
|
|
|
switch (payload.action) {
|
2019-07-04 06:46:37 +08:00
|
|
|
case 'on_client_not_viable':
|
2017-06-21 01:47:35 +08:00
|
|
|
case 'on_logged_out':
|
|
|
|
this.setNotificationCount(0);
|
|
|
|
break;
|
|
|
|
}
|
2020-05-22 01:06:36 +08:00
|
|
|
};
|
2016-11-02 23:10:21 +08:00
|
|
|
|
2017-05-30 02:50:04 +08:00
|
|
|
// Used primarily for Analytics
|
2020-05-22 01:06:36 +08:00
|
|
|
abstract getHumanReadableName(): string;
|
2017-05-30 02:50:04 +08:00
|
|
|
|
2016-11-02 23:10:21 +08:00
|
|
|
setNotificationCount(count: number) {
|
|
|
|
this.notificationCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
setErrorStatus(errorDidOccur: boolean) {
|
|
|
|
this.errorDidOccur = errorDidOccur;
|
|
|
|
}
|
|
|
|
|
2016-11-03 01:35:31 +08:00
|
|
|
/**
|
|
|
|
* Returns true if the platform supports displaying
|
|
|
|
* notifications, otherwise false.
|
2017-07-01 21:15:26 +08:00
|
|
|
* @returns {boolean} whether the platform supports displaying notifications
|
2016-11-03 01:35:31 +08:00
|
|
|
*/
|
2017-01-20 22:22:27 +08:00
|
|
|
supportsNotifications(): boolean {
|
2016-11-03 01:35:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the application currently has permission
|
|
|
|
* to display notifications. Otherwise false.
|
2017-07-01 21:15:26 +08:00
|
|
|
* @returns {boolean} whether the application has permission to display notifications
|
2016-11-03 01:35:31 +08:00
|
|
|
*/
|
2017-01-20 22:22:27 +08:00
|
|
|
maySendNotifications(): boolean {
|
2016-11-03 01:35:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Requests permission to send notifications. Returns
|
|
|
|
* a promise that is resolved when the user has responded
|
|
|
|
* to the request. The promise has a single string argument
|
|
|
|
* that is 'granted' if the user allowed the request or
|
|
|
|
* 'denied' otherwise.
|
|
|
|
*/
|
2020-05-22 01:06:36 +08:00
|
|
|
abstract requestNotificationPermission(): Promise<string>;
|
2016-11-03 01:35:31 +08:00
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
abstract displayNotification(title: string, msg: string, avatarUrl: string, room: Object);
|
2016-11-08 18:45:19 +08:00
|
|
|
|
2017-06-01 06:49:55 +08:00
|
|
|
loudNotification(ev: Event, room: Object) {
|
2020-05-22 01:25:52 +08:00
|
|
|
};
|
2017-06-01 06:49:55 +08:00
|
|
|
|
2016-11-08 18:45:19 +08:00
|
|
|
/**
|
2020-05-22 01:06:36 +08:00
|
|
|
* Returns a promise that resolves to a string representing the current version of the application.
|
2016-11-08 18:45:19 +08:00
|
|
|
*/
|
2020-05-22 01:06:36 +08:00
|
|
|
abstract getAppVersion(): Promise<string>;
|
2017-01-11 02:37:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's not expected that capturing the screen will work
|
|
|
|
* with getUserMedia, return a string explaining why not.
|
|
|
|
* Otherwise, return null.
|
|
|
|
*/
|
2017-05-24 22:40:50 +08:00
|
|
|
screenCaptureErrorString(): string {
|
2017-01-11 02:37:57 +08:00
|
|
|
return "Not implemented";
|
|
|
|
}
|
2017-04-11 00:39:27 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restarts the application, without neccessarily reloading
|
|
|
|
* any application code
|
|
|
|
*/
|
2020-05-22 01:06:36 +08:00
|
|
|
abstract reload();
|
2019-02-24 09:06:53 +08:00
|
|
|
|
2019-02-24 09:20:49 +08:00
|
|
|
supportsAutoLaunch(): boolean {
|
2019-02-24 09:06:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: Surely this should be a setting like any other?
|
2020-05-22 01:06:36 +08:00
|
|
|
async getAutoLaunchEnabled(): Promise<boolean> {
|
2019-02-24 09:06:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
async setAutoLaunchEnabled(enabled: boolean): Promise<void> {
|
2019-02-24 09:06:53 +08:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:58:53 +08:00
|
|
|
supportsAutoHideMenuBar(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
async getAutoHideMenuBarEnabled(): Promise<boolean> {
|
2019-08-05 18:58:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
async setAutoHideMenuBarEnabled(enabled: boolean): Promise<void> {
|
2019-08-05 18:58:53 +08:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-02-24 09:20:49 +08:00
|
|
|
supportsMinimizeToTray(): boolean {
|
2019-02-24 09:06:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
async getMinimizeToTrayEnabled(): Promise<boolean> {
|
2019-02-24 09:06:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-22 01:06:36 +08:00
|
|
|
async setMinimizeToTrayEnabled(enabled: boolean): Promise<void> {
|
2019-02-24 09:06:53 +08:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
2019-10-11 22:07:59 +08:00
|
|
|
|
2019-11-13 23:21:26 +08:00
|
|
|
/**
|
|
|
|
* Get our platform specific EventIndexManager.
|
|
|
|
*
|
|
|
|
* @return {BaseEventIndexManager} The EventIndex manager for our platform,
|
|
|
|
* can be null if the platform doesn't support event indexing.
|
|
|
|
*/
|
2019-11-13 19:25:16 +08:00
|
|
|
getEventIndexingManager(): BaseEventIndexManager | null {
|
|
|
|
return null;
|
2019-10-11 22:07:59 +08:00
|
|
|
}
|
2020-02-25 01:11:08 +08:00
|
|
|
|
2020-02-25 18:57:40 +08:00
|
|
|
setLanguage(preferredLangs: string[]) {}
|
2020-03-02 22:59:54 +08:00
|
|
|
|
2020-05-13 13:24:04 +08:00
|
|
|
getSSOCallbackUrl(hsUrl: string, isUrl: string, fragmentAfterLogin: string): URL {
|
2020-03-02 22:59:54 +08:00
|
|
|
const url = new URL(window.location.href);
|
2020-05-13 13:24:04 +08:00
|
|
|
url.hash = fragmentAfterLogin || "";
|
2020-03-02 22:59:54 +08:00
|
|
|
url.searchParams.set("homeserver", hsUrl);
|
|
|
|
url.searchParams.set("identityServer", isUrl);
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Begin Single Sign On flows.
|
2020-03-02 23:05:56 +08:00
|
|
|
* @param {MatrixClient} mxClient the matrix client using which we should start the flow
|
|
|
|
* @param {"sso"|"cas"} loginType the type of SSO it is, CAS/SSO.
|
2020-05-13 13:24:04 +08:00
|
|
|
* @param {string} fragmentAfterLogin the hash to pass to the app during sso callback.
|
2020-03-02 22:59:54 +08:00
|
|
|
*/
|
2020-05-13 13:24:04 +08:00
|
|
|
startSingleSignOn(mxClient: MatrixClient, loginType: "sso" | "cas", fragmentAfterLogin: string) {
|
|
|
|
const callbackUrl = this.getSSOCallbackUrl(mxClient.getHomeserverUrl(), mxClient.getIdentityServerUrl(),
|
|
|
|
fragmentAfterLogin);
|
2020-03-02 22:59:54 +08:00
|
|
|
window.location.href = mxClient.getSsoLoginUrl(callbackUrl.toString(), loginType); // redirect to SSO
|
|
|
|
}
|
2020-04-12 01:57:59 +08:00
|
|
|
|
|
|
|
onKeyDown(ev: KeyboardEvent): boolean {
|
|
|
|
return false; // no shortcuts implemented
|
|
|
|
}
|
2020-05-28 12:05:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a previously stored pickle key. The pickle key is used for
|
|
|
|
* encrypting libolm objects.
|
|
|
|
* @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.
|
|
|
|
* @returns {string|null} the previously stored pickle key, or null if no
|
|
|
|
* pickle key has been stored.
|
|
|
|
*/
|
2020-05-28 23:56:48 +08:00
|
|
|
async getPickleKey(userId: string, deviceId: string): Promise<string | null> {
|
2020-05-28 12:05:45 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and store a pickle key for encrypting libolm objects.
|
|
|
|
* @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.
|
|
|
|
* @returns {string|null} the pickle key, or null if the platform does not
|
|
|
|
* support storing pickle keys.
|
|
|
|
*/
|
2020-05-28 23:56:48 +08:00
|
|
|
async createPickleKey(userId: string, deviceId: string): Promise<string | null> {
|
2020-05-28 12:05:45 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a previously stored pickle key from storage.
|
|
|
|
* @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.
|
|
|
|
*/
|
2020-05-28 23:56:48 +08:00
|
|
|
async destroyPickleKey(userId: string, deviceId: string): Promise<void> {
|
2020-05-28 12:05:45 +08:00
|
|
|
}
|
2016-11-02 23:10:21 +08:00
|
|
|
}
|