2016-11-02 18:10:21 +03:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
/*
|
2016-11-03 14:47:57 +03:00
|
|
|
Copyright 2016 Aviral Dasgupta
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2018-12-18 20:40:30 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2016-11-02 18:10:21 +03: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.
|
|
|
|
*/
|
|
|
|
|
2017-06-20 22:15:25 +03:00
|
|
|
import dis from './dispatcher';
|
2019-11-19 14:52:12 +03:00
|
|
|
import BaseEventIndexManager from './indexing/BaseEventIndexManager';
|
2017-06-20 20:47:35 +03:00
|
|
|
|
2016-11-02 18:10:21 +03: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.
|
|
|
|
*/
|
|
|
|
export default class BasePlatform {
|
|
|
|
constructor() {
|
|
|
|
this.notificationCount = 0;
|
|
|
|
this.errorDidOccur = false;
|
2017-06-20 20:47:35 +03:00
|
|
|
|
|
|
|
dis.register(this._onAction.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
_onAction(payload: Object) {
|
|
|
|
switch (payload.action) {
|
2019-07-04 01:46:37 +03:00
|
|
|
case 'on_client_not_viable':
|
2017-06-20 20:47:35 +03:00
|
|
|
case 'on_logged_out':
|
|
|
|
this.setNotificationCount(0);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-02 18:10:21 +03:00
|
|
|
}
|
|
|
|
|
2017-05-29 21:50:04 +03:00
|
|
|
// Used primarily for Analytics
|
2017-05-29 22:02:46 +03:00
|
|
|
getHumanReadableName(): string {
|
2017-05-29 21:50:04 +03:00
|
|
|
return 'Base Platform';
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:10:21 +03:00
|
|
|
setNotificationCount(count: number) {
|
|
|
|
this.notificationCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
setErrorStatus(errorDidOccur: boolean) {
|
|
|
|
this.errorDidOccur = errorDidOccur;
|
|
|
|
}
|
|
|
|
|
2016-11-02 20:35:31 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the platform supports displaying
|
|
|
|
* notifications, otherwise false.
|
2017-07-01 16:15:26 +03:00
|
|
|
* @returns {boolean} whether the platform supports displaying notifications
|
2016-11-02 20:35:31 +03:00
|
|
|
*/
|
2017-01-20 17:22:27 +03:00
|
|
|
supportsNotifications(): boolean {
|
2016-11-02 20:35:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the application currently has permission
|
|
|
|
* to display notifications. Otherwise false.
|
2017-07-01 16:15:26 +03:00
|
|
|
* @returns {boolean} whether the application has permission to display notifications
|
2016-11-02 20:35:31 +03:00
|
|
|
*/
|
2017-01-20 17:22:27 +03:00
|
|
|
maySendNotifications(): boolean {
|
2016-11-02 20:35:31 +03: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.
|
|
|
|
*/
|
2017-01-20 17:22:27 +03:00
|
|
|
requestNotificationPermission(): Promise<string> {
|
2016-11-02 20:35:31 +03:00
|
|
|
}
|
|
|
|
|
2016-12-06 16:27:36 +03:00
|
|
|
displayNotification(title: string, msg: string, avatarUrl: string, room: Object) {
|
2016-11-02 18:10:21 +03:00
|
|
|
}
|
2016-11-08 13:45:19 +03:00
|
|
|
|
2017-06-01 01:49:55 +03:00
|
|
|
loudNotification(ev: Event, room: Object) {
|
|
|
|
}
|
|
|
|
|
2016-11-08 13:45:19 +03:00
|
|
|
/**
|
|
|
|
* Returns a promise that resolves to a string representing
|
|
|
|
* the current version of the application.
|
|
|
|
*/
|
2017-05-24 17:40:50 +03:00
|
|
|
getAppVersion(): Promise<string> {
|
2016-11-08 14:43:24 +03:00
|
|
|
throw new Error("getAppVersion not implemented!");
|
2016-11-08 13:45:19 +03:00
|
|
|
}
|
2017-01-10 21:37:57 +03: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 17:40:50 +03:00
|
|
|
screenCaptureErrorString(): string {
|
2017-01-10 21:37:57 +03:00
|
|
|
return "Not implemented";
|
|
|
|
}
|
2017-04-10 19:39:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restarts the application, without neccessarily reloading
|
|
|
|
* any application code
|
|
|
|
*/
|
|
|
|
reload() {
|
|
|
|
throw new Error("reload not implemented!");
|
|
|
|
}
|
2019-02-24 04:06:53 +03:00
|
|
|
|
2019-02-24 04:20:49 +03:00
|
|
|
supportsAutoLaunch(): boolean {
|
2019-02-24 04:06:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: Surely this should be a setting like any other?
|
2019-02-24 04:20:49 +03:00
|
|
|
async getAutoLaunchEnabled(): boolean {
|
2019-02-24 04:06:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-24 04:38:31 +03:00
|
|
|
async setAutoLaunchEnabled(enabled: boolean): void {
|
2019-02-24 04:06:53 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-08-05 13:58:53 +03:00
|
|
|
supportsAutoHideMenuBar(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAutoHideMenuBarEnabled(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async setAutoHideMenuBarEnabled(enabled: boolean): void {
|
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-02-24 04:20:49 +03:00
|
|
|
supportsMinimizeToTray(): boolean {
|
2019-02-24 04:06:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-24 04:20:49 +03:00
|
|
|
async getMinimizeToTrayEnabled(): boolean {
|
2019-02-24 04:06:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-24 04:38:31 +03:00
|
|
|
async setMinimizeToTrayEnabled(enabled: boolean): void {
|
2019-02-24 04:06:53 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
2019-10-11 17:07:59 +03:00
|
|
|
|
2019-11-13 18:21:26 +03: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 14:25:16 +03:00
|
|
|
getEventIndexingManager(): BaseEventIndexManager | null {
|
|
|
|
return null;
|
2019-10-11 17:07:59 +03:00
|
|
|
}
|
2016-11-02 18:10:21 +03:00
|
|
|
}
|