From 5413480ea5f51cbae94b9365785d79a581ecdc65 Mon Sep 17 00:00:00 2001 From: Thib Date: Thu, 9 Jun 2022 12:46:26 +0200 Subject: [PATCH] Moving static data out of Element client file --- src/open/clients/Client.js | 35 +++++++++++++++++++++++++++++++++ src/open/clients/Element.js | 33 ++++++------------------------- src/open/clients/ElementData.js | 18 +++++++++++++++++ 3 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 src/open/clients/Client.js create mode 100644 src/open/clients/ElementData.js diff --git a/src/open/clients/Client.js b/src/open/clients/Client.js new file mode 100644 index 0000000..4393d71 --- /dev/null +++ b/src/open/clients/Client.js @@ -0,0 +1,35 @@ +import { Platform } from "../types.js"; + +export class Client { + constructor(data) { + this.data = data; + } + + get id() { return this.data.id; } + + get platforms() { return this.data.platforms; } + + get icon() { return "images/client-icons/"+this.data.icon; } + get name() {return this.data.name; } + get description() { return this.data.description; } + get homepage() { return this.data.homepage; } + get author() { return this.data.author; } + getMaturity(platform) { return this.data.maturity; } + + getLinkInstructions(platform, link) {} + getCopyString(platform, link) {} + getInstallLinks(platform) { + var links = []; + if (platform === Platform.iOS && this.platforms().includes(Platform.iOS) && this.data.applestorelink) { + links.push(this.data.applestorelink); + } else if (platform === Platform.Android && this.platforms.includes(Platform.Android)) { + if (this.data.playstorelink) { links.push(this.data.playstorelink); } + if (this.data.fdroidlink) { links.push(this.data.fdroidlink); } + } + else if (this.data.defaultInstallLink) { links.push(this.data.defaultInstallLink); } + + return links; + } + + canInterceptMatrixToLinks(platform) { return false; } +} \ No newline at end of file diff --git a/src/open/clients/Element.js b/src/open/clients/Element.js index d0d5e24..5c3099a 100644 --- a/src/open/clients/Element.js +++ b/src/open/clients/Element.js @@ -14,8 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {Maturity, Platform, LinkKind, - FDroidLink, AppleStoreLink, PlayStoreLink, WebsiteLink} from "../types.js"; +import {Platform, LinkKind} from "../types.js"; +import {Client} from "./Client.js"; +import {data} from "./ElementData.js"; const trustedWebInstances = [ "app.element.io", // first one is the default one @@ -29,24 +30,12 @@ const trustedWebInstances = [ /** * Information on how to deep link to a given matrix client. */ -export class Element { - get id() { return "element.io"; } - - get platforms() { - return [ - Platform.Android, Platform.iOS, - Platform.Windows, Platform.macOS, Platform.Linux, - Platform.DesktopWeb - ]; +export class Element extends Client { + constructor() { + super(data); } - get icon() { return "images/client-icons/element.svg"; } get appleAssociatedAppId() { return "7J4U792NQT.im.vector.app"; } - get name() {return "Element"; } - get description() { return 'Fully-featured Matrix client, used by millions.'; } - get homepage() { return "https://element.io"; } - get author() { return "Element"; } - getMaturity(platform) { return Maturity.Stable; } getDeepLink(platform, link) { let fragmentPath; @@ -85,16 +74,6 @@ export class Element { } } - getLinkInstructions(platform, link) {} - getCopyString(platform, link) {} - getInstallLinks(platform) { - switch (platform) { - case Platform.iOS: return [new AppleStoreLink('vector', 'id1083446067')]; - case Platform.Android: return [new PlayStoreLink('im.vector.app'), new FDroidLink('im.vector.app')]; - default: return [new WebsiteLink("https://element.io/get-started")]; - } - } - canInterceptMatrixToLinks(platform) { return platform === Platform.Android; } diff --git a/src/open/clients/ElementData.js b/src/open/clients/ElementData.js new file mode 100644 index 0000000..721097f --- /dev/null +++ b/src/open/clients/ElementData.js @@ -0,0 +1,18 @@ +import {Maturity, Platform, FDroidLink, AppleStoreLink, PlayStoreLink, WebsiteLink, FlathubLink} from "../types.js"; + +export const data = { + "id": "element.io", + "platforms": [Platform.Android, Platform.iOS, Platform.Windows, Platform.macOS, Platform.Linux, Platform.DesktopWeb], + "icon": "element.svg", + "appleAssociatedAppId": "7J4U792NQT.im.vector.app", + "name": "Element", + "description": "Fully-featured Matrix client, used by millions.", + "homepage": "https://element.io", + "author": "Element", + "maturity": Maturity.Stable, + "applestorelink": new AppleStoreLink('vector', 'id1083446067'), + "playstorelink": new PlayStoreLink('im.vector.app'), + "fdroidlink": new FDroidLink('im.vector.app'), + "flathublink": new FlathubLink('im.riot.Riot'), + "defaultInstallLink": new WebsiteLink("https://element.io/get-started"), +}; \ No newline at end of file