mirror of
https://github.com/vector-im/element-web.git
synced 2025-12-17 15:21:21 +01:00
Tidy up modules (#29089)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
3c22e5dc68
commit
c390ec333e
@ -7,3 +7,4 @@ test/end-to-end-tests/lib/
|
|||||||
src/component-index.js
|
src/component-index.js
|
||||||
# Auto-generated file
|
# Auto-generated file
|
||||||
src/modules.ts
|
src/modules.ts
|
||||||
|
src/modules.js
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,6 +26,7 @@ electron/pub
|
|||||||
/coverage
|
/coverage
|
||||||
# Auto-generated file
|
# Auto-generated file
|
||||||
/src/modules.ts
|
/src/modules.ts
|
||||||
|
/src/modules.js
|
||||||
/build_config.yaml
|
/build_config.yaml
|
||||||
/book
|
/book
|
||||||
/index.html
|
/index.html
|
||||||
|
|||||||
@ -17,6 +17,7 @@ electron/pub
|
|||||||
/coverage
|
/coverage
|
||||||
# Auto-generated file
|
# Auto-generated file
|
||||||
/src/modules.ts
|
/src/modules.ts
|
||||||
|
/src/modules.js
|
||||||
/src/i18n/strings
|
/src/i18n/strings
|
||||||
/build_config.yaml
|
/build_config.yaml
|
||||||
# Raises an error because it contains a template var breaking the script tag
|
# Raises an error because it contains a template var breaking the script tag
|
||||||
|
|||||||
@ -23,10 +23,9 @@ const MODULES_TS_HEADER = `
|
|||||||
* You are not a salmon.
|
* You are not a salmon.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { RuntimeModule } from "@matrix-org/react-sdk-module-api/lib/RuntimeModule";
|
|
||||||
`;
|
`;
|
||||||
const MODULES_TS_DEFINITIONS = `
|
const MODULES_TS_DEFINITIONS = `
|
||||||
export const INSTALLED_MODULES: RuntimeModule[] = [];
|
export const INSTALLED_MODULES = [];
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export function installer(config: BuildConfig): void {
|
export function installer(config: BuildConfig): void {
|
||||||
@ -78,8 +77,8 @@ export function installer(config: BuildConfig): void {
|
|||||||
return; // hit the finally{} block before exiting
|
return; // hit the finally{} block before exiting
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach here, everything seems fine. Write modules.ts and log some output
|
// If we reach here, everything seems fine. Write modules.js and log some output
|
||||||
// Note: we compile modules.ts in two parts for developer friendliness if they
|
// Note: we compile modules.js in two parts for developer friendliness if they
|
||||||
// happen to look at it.
|
// happen to look at it.
|
||||||
console.log("The following modules have been installed: ", installedModules);
|
console.log("The following modules have been installed: ", installedModules);
|
||||||
let modulesTsHeader = MODULES_TS_HEADER;
|
let modulesTsHeader = MODULES_TS_HEADER;
|
||||||
@ -193,5 +192,5 @@ function isModuleVersionCompatible(ourApiVersion: string, moduleApiVersion: stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeModulesTs(content: string): void {
|
function writeModulesTs(content: string): void {
|
||||||
fs.writeFileSync("./src/modules.ts", content, "utf-8");
|
fs.writeFileSync("./src/modules.js", content, "utf-8");
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/modules.d.ts
vendored
Normal file
13
src/modules.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2025 New Vector Ltd.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||||
|
Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ModuleApi, RuntimeModule } from "@matrix-org/react-sdk-module-api";
|
||||||
|
|
||||||
|
declare module "./modules.js" {
|
||||||
|
export type RuntimeModuleConstructor = { new (api: ModuleApi): RuntimeModule };
|
||||||
|
export const INSTALLED_MODULES: RuntimeModuleConstructor[];
|
||||||
|
}
|
||||||
@ -65,7 +65,7 @@ import { navigateToPermalink } from "../../utils/permalinks/navigator";
|
|||||||
import { SdkContextClass } from "../../contexts/SDKContext";
|
import { SdkContextClass } from "../../contexts/SDKContext";
|
||||||
import { ModuleRunner } from "../../modules/ModuleRunner";
|
import { ModuleRunner } from "../../modules/ModuleRunner";
|
||||||
import SettingsStore from "../../settings/SettingsStore";
|
import SettingsStore from "../../settings/SettingsStore";
|
||||||
import { Media } from "../../customisations/Media";
|
import { mediaFromMxc } from "../../customisations/Media";
|
||||||
|
|
||||||
// TODO: Purge this from the universe
|
// TODO: Purge this from the universe
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||||||
*/
|
*/
|
||||||
public async downloadFile(contentUri: string): Promise<{ file: XMLHttpRequestBodyInit }> {
|
public async downloadFile(contentUri: string): Promise<{ file: XMLHttpRequestBodyInit }> {
|
||||||
const client = MatrixClientPeg.safeGet();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const media = new Media({ mxc: contentUri }, client);
|
const media = mediaFromMxc(contentUri, client);
|
||||||
const response = await media.downloadSource();
|
const response = await media.downloadSource();
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
return { file: blob };
|
return { file: blob };
|
||||||
|
|||||||
@ -125,12 +125,8 @@ export async function showIncompatibleBrowser(onAccept: () => void): Promise<voi
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function loadModules(): Promise<void> {
|
export async function loadModules(): Promise<void> {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
const { INSTALLED_MODULES } = await import("../modules.js");
|
||||||
// @ts-ignore - this path is created at runtime and therefore won't exist at typecheck time
|
|
||||||
const { INSTALLED_MODULES } = await import("../modules");
|
|
||||||
for (const InstalledModule of INSTALLED_MODULES) {
|
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));
|
ModuleRunner.instance.registerModule((api) => new InstalledModule(api));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user