Skip to content

Commit baf3df5

Browse files
authored
Merge pull request element-hq#7920 from vector-im/dbkr/fix_indexeddb_worker
Fix the IndexedDB worker
2 parents 6c6819f + 7527bdd commit baf3df5

3 files changed

Lines changed: 12 additions & 23 deletions

File tree

‎src/vector/index.html‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,10 @@
3636
<body style="height: 100%;">
3737
<section id="matrixchat" style="height: 100%;"></section>
3838
<noscript>Sorry, Riot requires JavaScript to be enabled.</noscript> <!-- TODO: Translate this? -->
39-
<% for (var i=0; i < htmlWebpackPlugin.files.js.length; i++) {
40-
if (_.endsWith(htmlWebpackPlugin.files.js[i], 'olm.js')) {
41-
var array = htmlWebpackPlugin.files.js;
42-
htmlWebpackPlugin.files.js.unshift(htmlWebpackPlugin.files.js[i]);
43-
htmlWebpackPlugin.files.js.splice(i, 1);
44-
}
45-
}
46-
47-
for (var i=0; i < htmlWebpackPlugin.files.js.length; i++) {
48-
// Not a particularly graceful way of not putting the indexeddb worker script
49-
// into the main page
50-
if (_.endsWith(htmlWebpackPlugin.files.js[i], 'indexeddb-worker.js')) {
51-
%>
52-
<script>
53-
window.vector_indexeddb_worker_script = '<%= htmlWebpackPlugin.files.js[i] %>';
54-
</script>
55-
<%
56-
continue;
57-
}
58-
%>
59-
<script src="<%= htmlWebpackPlugin.files.js[i] %>"></script>
60-
<% } %>
39+
<script>
40+
window.vector_indexeddb_worker_script = '<%= htmlWebpackPlugin.files.chunks['indexeddb-worker'].entry %>';
41+
</script>
42+
<script src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
6143
<img src="img/warning.svg" width="24" height="23" style="visibility: hidden; position: absolute; top: 0px; left: 0px;"/>
6244
<audio id="messageAudio">
6345
<source src="media/message.ogg" type="audio/ogg" />

‎src/vector/index.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ function onTokenLoginCompleted() {
209209
}
210210

211211
async function loadApp() {
212+
if (window.vector_indexeddb_worker_script === undefined) {
213+
// If this is missing, something has probably gone wrong with
214+
// the bundling. The js-sdk will just fall back to accessing
215+
// indexeddb directly with no worker script, but we want to
216+
// make sure the indexeddb script is present, so fail hard.
217+
throw new Error("Missing indexeddb worker script!");
218+
}
212219
MatrixClientPeg.setIndexedDbWorkerScript(window.vector_indexeddb_worker_script);
213220
CallHandler.setConferenceHandler(VectorConferenceHandler);
214221

‎src/vector/indexeddb-worker.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ import {IndexedDBStoreWorker} from 'matrix-js-sdk/lib/indexeddb-worker.js';
1818

1919
const remoteWorker = new IndexedDBStoreWorker(postMessage);
2020

21-
export const onmessage = remoteWorker.onMessage;
21+
global.onmessage = remoteWorker.onMessage;

0 commit comments

Comments
 (0)