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