2020-03-25 13:53:28 +00:00
|
|
|
/*
|
2024-09-06 15:44:31 +01:00
|
|
|
Copyright 2018-2024 New Vector Ltd.
|
2020-03-25 13:53:28 +00:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2024-09-06 15:44:31 +01:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2020-03-25 13:53:28 +00:00
|
|
|
|
2024-09-06 15:44:31 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-03-25 13:53:28 +00:00
|
|
|
*/
|
|
|
|
|
|
2020-04-05 00:05:59 +01:00
|
|
|
import * as ReactDOM from "react-dom";
|
2024-10-25 12:20:25 +01:00
|
|
|
import React, { StrictMode } from "react";
|
2021-10-15 16:56:22 +02:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
import * as languageHandler from "../languageHandler";
|
|
|
|
|
import SettingsStore from "../settings/SettingsStore";
|
|
|
|
|
import PlatformPeg from "../PlatformPeg";
|
|
|
|
|
import SdkConfig from "../SdkConfig";
|
|
|
|
|
import { setTheme } from "../theme";
|
|
|
|
|
import { ModuleRunner } from "../modules/ModuleRunner";
|
|
|
|
|
import MatrixChat from "../components/structures/MatrixChat";
|
2021-12-09 22:57:46 +00:00
|
|
|
import ElectronPlatform from "./platform/ElectronPlatform";
|
|
|
|
|
import PWAPlatform from "./platform/PWAPlatform";
|
|
|
|
|
import WebPlatform from "./platform/WebPlatform";
|
|
|
|
|
import { initRageshake, initRageshakeStore } from "./rageshakesetup";
|
2022-07-05 20:26:54 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
|
// @ts-ignore - this path is created at runtime and therefore won't exist at typecheck time
|
|
|
|
|
import { INSTALLED_MODULES } from "../modules";
|
2021-12-09 22:57:46 +00:00
|
|
|
|
2020-04-04 17:34:33 +01:00
|
|
|
export const rageshakePromise = initRageshake();
|
2020-03-25 13:55:25 +00:00
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export function preparePlatform(): void {
|
2021-01-13 15:39:18 +00:00
|
|
|
if (window.electron) {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Using Electron platform");
|
2020-06-02 16:58:05 +01:00
|
|
|
PlatformPeg.set(new ElectronPlatform());
|
|
|
|
|
} else if (window.matchMedia("(display-mode: standalone)").matches) {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Using PWA platform");
|
2020-06-02 16:58:05 +01:00
|
|
|
PlatformPeg.set(new PWAPlatform());
|
2020-03-25 14:32:37 +00:00
|
|
|
} else {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Using Web platform");
|
2020-03-25 14:32:37 +00:00
|
|
|
PlatformPeg.set(new WebPlatform());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export function setupLogStorage(): Promise<void> {
|
2021-03-16 14:21:59 -06:00
|
|
|
if (SdkConfig.get().bug_report_endpoint_url) {
|
|
|
|
|
return initRageshakeStore();
|
|
|
|
|
}
|
2021-10-15 17:00:43 +02:00
|
|
|
logger.warn("No bug report endpoint set - logs will not be persisted");
|
2021-03-16 14:21:59 -06:00
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export async function loadConfig(): Promise<void> {
|
2020-04-08 19:35:16 +01:00
|
|
|
// XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure
|
|
|
|
|
// granular settings are loaded correctly and to avoid duplicating the override logic for the theme.
|
|
|
|
|
//
|
|
|
|
|
// Note: this isn't called twice for some wrappers, like the Jitsi wrapper.
|
2023-04-25 09:36:17 +01:00
|
|
|
const platformConfig = await PlatformPeg.get()?.getConfig();
|
2022-03-18 10:12:44 -06:00
|
|
|
if (platformConfig) {
|
|
|
|
|
SdkConfig.put(platformConfig);
|
|
|
|
|
} else {
|
2023-04-26 11:12:57 +01:00
|
|
|
SdkConfig.reset();
|
2022-03-18 10:12:44 -06:00
|
|
|
}
|
2020-03-25 14:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export async function loadLanguage(): Promise<void> {
|
2020-03-25 13:55:25 +00:00
|
|
|
const prefLang = SettingsStore.getValue("language", null, /*excludeDefault=*/ true);
|
2023-04-25 09:36:17 +01:00
|
|
|
let langs: string[] = [];
|
2020-03-25 13:55:25 +00:00
|
|
|
|
|
|
|
|
if (!prefLang) {
|
|
|
|
|
languageHandler.getLanguagesFromBrowser().forEach((l) => {
|
|
|
|
|
langs.push(...languageHandler.getNormalizedLanguageKeys(l));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
langs = [prefLang];
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await languageHandler.setLanguage(langs);
|
|
|
|
|
document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage());
|
|
|
|
|
} catch (e) {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Unable to set language", e);
|
2020-03-25 13:55:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-04 17:21:59 +01:00
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export async function loadTheme(): Promise<void> {
|
2024-06-12 17:17:29 +01:00
|
|
|
return setTheme();
|
2020-04-08 16:17:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export async function loadApp(fragParams: {}): Promise<void> {
|
2020-04-04 23:42:19 +01:00
|
|
|
// load app.js async so that its code is not executed immediately and we can catch any exceptions
|
2020-04-04 17:21:59 +01:00
|
|
|
const module = await import(
|
2020-11-25 17:01:19 +00:00
|
|
|
/* webpackChunkName: "element-web-app" */
|
2020-04-04 17:21:59 +01:00
|
|
|
/* webpackPreload: true */
|
|
|
|
|
"./app"
|
|
|
|
|
);
|
2023-10-19 03:13:30 +02:00
|
|
|
function setWindowMatrixChat(matrixChat: MatrixChat): void {
|
|
|
|
|
window.matrixChat = matrixChat;
|
|
|
|
|
}
|
|
|
|
|
ReactDOM.render(await module.loadApp(fragParams, setWindowMatrixChat), document.getElementById("matrixchat"));
|
2020-04-04 17:21:59 +01:00
|
|
|
}
|
2020-04-08 19:47:52 +01:00
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export async function showError(title: string, messages?: string[]): Promise<void> {
|
2024-07-30 14:16:19 +01:00
|
|
|
const { ErrorView } = await import(
|
|
|
|
|
/* webpackChunkName: "error-view" */
|
|
|
|
|
"../async-components/structures/ErrorView"
|
|
|
|
|
);
|
2020-04-08 20:03:45 +01:00
|
|
|
window.matrixChat = ReactDOM.render(
|
2024-10-25 12:20:25 +01:00
|
|
|
<StrictMode>
|
|
|
|
|
<ErrorView title={title} messages={messages} />
|
|
|
|
|
</StrictMode>,
|
2020-04-08 19:47:52 +01:00
|
|
|
document.getElementById("matrixchat"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 09:36:17 +01:00
|
|
|
export async function showIncompatibleBrowser(onAccept: () => void): Promise<void> {
|
2024-07-30 14:16:19 +01:00
|
|
|
const { UnsupportedBrowserView } = await import(
|
|
|
|
|
/* webpackChunkName: "error-view" */
|
|
|
|
|
"../async-components/structures/ErrorView"
|
|
|
|
|
);
|
2020-04-23 16:45:24 +01:00
|
|
|
window.matrixChat = ReactDOM.render(
|
2024-10-25 12:20:25 +01:00
|
|
|
<StrictMode>
|
|
|
|
|
<UnsupportedBrowserView onAccept={onAccept} />
|
|
|
|
|
</StrictMode>,
|
2020-04-08 21:41:22 +01:00
|
|
|
document.getElementById("matrixchat"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export async function loadModules(): Promise<void> {
|
2022-07-05 20:26:54 +02:00
|
|
|
for (const InstalledModule of INSTALLED_MODULES) {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
|
// @ts-ignore - we know the constructor exists even if TypeScript can't be convinced of that
|
|
|
|
|
ModuleRunner.instance.registerModule((api) => new InstalledModule(api));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-22 16:32:03 +01:00
|
|
|
export { _t } from "../languageHandler";
|
2024-07-08 15:52:53 +01:00
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
export { extractErrorMessageFromError } from "../components/views/dialogs/ErrorDialog";
|