mirror of
https://github.com/vector-im/element-web.git
synced 2024-09-10 07:05:14 +00:00
Kill off olm-loader
Now that Olm needs to be inited asynchronously anyway, we can just pass the options to Olm.init(), and as long as we do that before we start the js-sdk, we're all good. This will means the olm js is now part of the main bundle but since it's now just a wrapper around the wasm, this is probably faster. Also add the directwatch flag to olm.wasm because otherwise it doesn't seem to copy the file in watch mode...
This commit is contained in:
parent
c511902356
commit
1f34d2d644
4 changed files with 17 additions and 58 deletions
|
@ -60,7 +60,7 @@ const COPY_LIST = [
|
|||
// XXX: This is tied quite heavily to the matching olm.js so it really should be
|
||||
// in the bundle dir with the js to avoid caching issues giving us wasm that
|
||||
// doesn't match our js, but I cannot find any way to get webpack to do this.
|
||||
["node_modules/olm/olm.wasm", "webapp"],
|
||||
["node_modules/olm/olm.wasm", "webapp", { directwatch: 1 }],
|
||||
["./config.json", "webapp", { directwatch: 1 }],
|
||||
];
|
||||
|
||||
|
|
|
@ -54,6 +54,8 @@ import SettingsStore, {SettingLevel} from "matrix-react-sdk/lib/settings/Setting
|
|||
import Tinter from 'matrix-react-sdk/lib/Tinter';
|
||||
import SdkConfig from "matrix-react-sdk/lib/SdkConfig";
|
||||
|
||||
import Olm from 'olm';
|
||||
|
||||
import rageshake from "matrix-react-sdk/lib/rageshake/rageshake";
|
||||
|
||||
import CallHandler from 'matrix-react-sdk/lib/CallHandler';
|
||||
|
@ -227,6 +229,20 @@ async function loadApp() {
|
|||
|
||||
window.addEventListener('hashchange', onHashChange);
|
||||
|
||||
/* Start loading Olm. Note that we *don't* wait for this to load: the
|
||||
* js-sdk will also call this and actually wait on the promise before it
|
||||
* tries to use the library. It can be loading its wasm while the rest of
|
||||
* the app loads though.
|
||||
*
|
||||
* We also need to tell the Olm js to look for its wasm file at the same
|
||||
* level as index.html. It really should be in the same place as the js,
|
||||
* ie. in the bundle directory, to avoid caching issues, but as far as I
|
||||
* can tell this is completely impossible with webpack.
|
||||
*/
|
||||
Olm.init({
|
||||
locateFile: () => 'olm.wasm',
|
||||
});
|
||||
|
||||
await loadLanguage();
|
||||
|
||||
const fragparts = parseQsFromFragment(window.location);
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2018 New Vector 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 olm from 'olm/olm.js';
|
||||
|
||||
/* a very thin shim for loading olm.js: just sets the global OLM_OPTIONS and
|
||||
* requires the actual olm.js library.
|
||||
*
|
||||
* olm.js reads global.OLM_OPTIONS and defines global.Olm. The latter is fine for us,
|
||||
* but we need to prepare the former.
|
||||
*
|
||||
* We can't use webpack's definePlugin to do this, because we tell webpack not
|
||||
* to parse olm.js. We also can't put this code in index.js, because olm and
|
||||
* index.js are loaded in parallel, and we need to make sure OLM_OPTIONS is set
|
||||
* before olm.js is loaded.
|
||||
*/
|
||||
|
||||
/* Tell the Olm js to look for its wasm file at the same level as index.html.
|
||||
* It really should be in the same place as the js, ie. in the bundle directory,
|
||||
* to avoid caching issues, but as far as I can tell this is completely impossible
|
||||
* with webpack.
|
||||
*/
|
||||
global.OLM_OPTIONS = {
|
||||
locateFile: () => 'olm.wasm',
|
||||
};
|
|
@ -15,15 +15,6 @@ module.exports = {
|
|||
|
||||
"mobileguide": "./src/vector/mobile_guide/index.js",
|
||||
|
||||
// We ship olm.js as a separate lump of javascript. This makes it get
|
||||
// loaded via a separate <script/> tag in index.html (which loads it
|
||||
// into the browser global `Olm`, where js-sdk expects to find it).
|
||||
//
|
||||
// (we should probably make js-sdk load it asynchronously at some
|
||||
// point, so that it doesn't block the pageload, but that is a separate
|
||||
// problem)
|
||||
"olm": "./src/vector/olm-loader.js",
|
||||
|
||||
// CSS themes
|
||||
"theme-light": "./node_modules/matrix-react-sdk/res/themes/light/css/light.scss",
|
||||
"theme-dark": "./node_modules/matrix-react-sdk/res/themes/dark/css/dark.scss",
|
||||
|
@ -154,12 +145,3 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
};
|
||||
|
||||
// olm is an optional dependency. Ignore it if it's not installed, to avoid a
|
||||
// scary-looking error.
|
||||
try {
|
||||
require('olm');
|
||||
} catch (e) {
|
||||
console.log("Olm is not installed; not shipping it");
|
||||
delete(module.exports.entry["olm"]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue