Tidy up modules (#29089)

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2025-01-27 17:27:27 +00:00
committed by GitHub
parent 3c22e5dc68
commit c390ec333e
7 changed files with 23 additions and 12 deletions

13
src/modules.d.ts vendored Normal file
View 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[];
}

View File

@@ -65,7 +65,7 @@ import { navigateToPermalink } from "../../utils/permalinks/navigator";
import { SdkContextClass } from "../../contexts/SDKContext";
import { ModuleRunner } from "../../modules/ModuleRunner";
import SettingsStore from "../../settings/SettingsStore";
import { Media } from "../../customisations/Media";
import { mediaFromMxc } from "../../customisations/Media";
// TODO: Purge this from the universe
@@ -684,7 +684,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
*/
public async downloadFile(contentUri: string): Promise<{ file: XMLHttpRequestBodyInit }> {
const client = MatrixClientPeg.safeGet();
const media = new Media({ mxc: contentUri }, client);
const media = mediaFromMxc(contentUri, client);
const response = await media.downloadSource();
const blob = await response.blob();
return { file: blob };

View File

@@ -125,12 +125,8 @@ export async function showIncompatibleBrowser(onAccept: () => void): Promise<voi
}
export async function loadModules(): Promise<void> {
// 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
const { INSTALLED_MODULES } = await import("../modules");
const { INSTALLED_MODULES } = await import("../modules.js");
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));
}
}