diff --git a/src/@types/worker-loader.d.ts b/src/@types/worker-loader.d.ts new file mode 100644 index 0000000000..a8f5d8e9a4 --- /dev/null +++ b/src/@types/worker-loader.d.ts @@ -0,0 +1,23 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +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. +*/ + +declare module "*.worker.ts" { + class WebpackWorker extends Worker { + constructor(); + } + + export default WebpackWorker; +} diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index 7de62ba075..e9364b1b47 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -50,15 +50,6 @@ export interface IMatrixClientCreds { export interface IMatrixClientPeg { opts: IStartClientOpts; - /** - * Sets the script href passed to the IndexedDB web worker - * If set, a separate web worker will be started to run the IndexedDB - * queries on. - * - * @param {string} script href to the script to be passed to the web worker - */ - setIndexedDbWorkerScript(script: string): void; - /** * Return the server name of the user's homeserver * Throws an error if unable to deduce the homeserver name @@ -133,10 +124,6 @@ class _MatrixClientPeg implements IMatrixClientPeg { constructor() { } - public setIndexedDbWorkerScript(script: string): void { - createMatrixClient.indexedDbWorkerScript = script; - } - public get(): MatrixClient { return this.matrixClient; } diff --git a/src/components/views/dialogs/ShareDialog.tsx b/src/components/views/dialogs/ShareDialog.tsx index a3443ada02..85e9c6f192 100644 --- a/src/components/views/dialogs/ShareDialog.tsx +++ b/src/components/views/dialogs/ShareDialog.tsx @@ -35,7 +35,7 @@ import SettingsStore from "../../../settings/SettingsStore"; import { UIFeature } from "../../../settings/UIFeature"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import BaseDialog from "./BaseDialog"; -import GenericTextContextMenu from "../context_menus/GenericTextContextMenu.js"; +import GenericTextContextMenu from "../context_menus/GenericTextContextMenu"; const socials = [ { diff --git a/src/utils/createMatrixClient.ts b/src/utils/createMatrixClient.ts index caaf75616d..0cce729e65 100644 --- a/src/utils/createMatrixClient.ts +++ b/src/utils/createMatrixClient.ts @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +// @ts-ignore - `.ts` is needed here to make TS happy +import IndexedDBWorker from "../workers/indexeddb.worker.ts"; import { createClient, ICreateClientOpts } from "matrix-js-sdk/src/matrix"; import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store"; import { WebStorageSessionStore } from "matrix-js-sdk/src/store/session/webstorage"; @@ -35,10 +37,6 @@ try { * @param {Object} opts options to pass to Matrix.createClient. This will be * extended with `sessionStore` and `store` members. * - * @property {string} indexedDbWorkerScript Optional URL for a web worker script - * for IndexedDB store operations. By default, indexeddb ops are done on - * the main thread. - * * @returns {MatrixClient} the newly-created MatrixClient */ export default function createMatrixClient(opts: ICreateClientOpts) { @@ -51,7 +49,7 @@ export default function createMatrixClient(opts: ICreateClientOpts) { indexedDB: indexedDB, dbName: "riot-web-sync", localStorage: localStorage, - workerScript: createMatrixClient.indexedDbWorkerScript, + workerFactory: () => new IndexedDBWorker(), }); } @@ -70,5 +68,3 @@ export default function createMatrixClient(opts: ICreateClientOpts) { ...opts, }); } - -createMatrixClient.indexedDbWorkerScript = null; diff --git a/src/workers/indexeddb.worker.ts b/src/workers/indexeddb.worker.ts new file mode 100644 index 0000000000..a05add1c7d --- /dev/null +++ b/src/workers/indexeddb.worker.ts @@ -0,0 +1,23 @@ +/* +Copyright 2017 Vector Creations Ltd + +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. +*/ + +import { IndexedDBStoreWorker } from "matrix-js-sdk/src/indexeddb-worker"; + +const ctx: Worker = self as any; + +const remoteWorker = new IndexedDBStoreWorker(ctx.postMessage); + +ctx.onmessage = remoteWorker.onMessage;