2016-11-02 18:45:35 +01:00
|
|
|
|
/*
|
2016-11-03 12:51:41 +01:00
|
|
|
|
Copyright 2016 Aviral Dasgupta
|
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2020-05-20 20:56:54 +02:00
|
|
|
|
Copyright 2018, 2020 New Vector Ltd
|
2019-06-26 22:08:04 +02:00
|
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2016-11-02 18:45:35 +01: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-09 13:28:29 +01:00
|
|
|
|
import BasePlatform from "matrix-react-sdk/src/BasePlatform";
|
|
|
|
|
import { _t } from "matrix-react-sdk/src/languageHandler";
|
2017-05-31 15:51:08 +02:00
|
|
|
|
|
2022-03-18 17:12:44 +01:00
|
|
|
|
import type { IConfigOptions } from "matrix-react-sdk/src/IConfigOptions";
|
2021-12-09 23:57:46 +01:00
|
|
|
|
import { getVectorConfig } from "../getconfig";
|
2020-05-20 20:56:54 +02:00
|
|
|
|
import Favicon from "../../favicon";
|
2016-11-02 18:45:35 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Vector-specific extensions to the BasePlatform template
|
|
|
|
|
*/
|
2020-05-21 19:07:01 +02:00
|
|
|
|
export default abstract class VectorBasePlatform extends BasePlatform {
|
2020-05-20 20:56:54 +02:00
|
|
|
|
protected _favicon: Favicon;
|
2017-05-13 13:37:13 +02:00
|
|
|
|
|
2023-04-25 10:36:17 +02:00
|
|
|
|
public async getConfig(): Promise<IConfigOptions | undefined> {
|
2019-06-26 22:08:04 +02:00
|
|
|
|
return getVectorConfig();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 23:38:46 +02:00
|
|
|
|
public getHumanReadableName(): string {
|
2022-12-09 13:28:29 +01:00
|
|
|
|
return "Vector Base Platform"; // no translation required: only used for analytics
|
2017-05-29 20:51:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 14:29:25 +02:00
|
|
|
|
/**
|
2020-05-20 20:56:54 +02:00
|
|
|
|
* Delay creating the `Favicon` instance until first use (on the first notification) as
|
|
|
|
|
* it uses canvas, which can trigger a permission prompt in Firefox's resist fingerprinting mode.
|
2020-11-25 15:16:55 +01:00
|
|
|
|
* See https://github.com/vector-im/element-web/issues/9605.
|
2019-05-02 14:29:25 +02:00
|
|
|
|
*/
|
2022-11-23 17:24:36 +01:00
|
|
|
|
public get favicon(): Favicon {
|
2019-05-02 14:29:25 +02:00
|
|
|
|
if (this._favicon) {
|
|
|
|
|
return this._favicon;
|
|
|
|
|
}
|
2022-07-11 14:22:37 +02:00
|
|
|
|
this._favicon = new Favicon();
|
|
|
|
|
return this._favicon;
|
2019-05-02 14:29:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
|
private updateFavicon(): void {
|
2020-05-20 20:56:54 +02:00
|
|
|
|
let bgColor = "#d00";
|
|
|
|
|
let notif: string | number = this.notificationCount;
|
|
|
|
|
|
|
|
|
|
if (this.errorDidOccur) {
|
|
|
|
|
notif = notif || "×";
|
|
|
|
|
bgColor = "#f00";
|
2017-05-13 13:37:13 +02:00
|
|
|
|
}
|
2020-05-20 20:56:54 +02:00
|
|
|
|
|
|
|
|
|
this.favicon.badge(notif, { bgColor });
|
2017-05-13 13:37:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
|
public setNotificationCount(count: number): void {
|
2017-05-13 13:37:13 +02:00
|
|
|
|
if (this.notificationCount === count) return;
|
|
|
|
|
super.setNotificationCount(count);
|
2021-07-19 23:47:32 +02:00
|
|
|
|
this.updateFavicon();
|
2017-05-13 13:37:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
|
public setErrorStatus(errorDidOccur: boolean): void {
|
2017-05-13 13:37:13 +02:00
|
|
|
|
if (this.errorDidOccur === errorDidOccur) return;
|
|
|
|
|
super.setErrorStatus(errorDidOccur);
|
2021-07-19 23:47:32 +02:00
|
|
|
|
this.updateFavicon();
|
2017-05-13 13:37:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-03 13:50:47 +02:00
|
|
|
|
/**
|
|
|
|
|
* Begin update polling, if applicable
|
|
|
|
|
*/
|
2022-12-09 13:28:29 +01:00
|
|
|
|
public startUpdater(): void {}
|
2017-06-03 13:50:47 +02:00
|
|
|
|
|
2016-11-24 17:46:15 +01:00
|
|
|
|
/**
|
|
|
|
|
* Get a sensible default display name for the
|
|
|
|
|
* device Vector is running on
|
|
|
|
|
*/
|
2022-06-10 23:38:46 +02:00
|
|
|
|
public getDefaultDeviceDisplayName(): string {
|
2017-05-31 15:51:08 +02:00
|
|
|
|
return _t("Unknown device");
|
2016-11-24 17:46:15 +01:00
|
|
|
|
}
|
2016-11-02 18:45:35 +01:00
|
|
|
|
}
|