mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 03:25:52 +01:00
support loading logs through postMessage in logviewer
This commit is contained in:
parent
a2a17dbf7a
commit
2a729f8969
@ -218,5 +218,20 @@
|
||||
<main></main>
|
||||
<aside></aside>
|
||||
<script type="module" src="main.js"></script>
|
||||
<script type="module">
|
||||
import {loadBlob} from "./main.js";
|
||||
window.addEventListener("message", event => {
|
||||
console.log("message", event);
|
||||
if (event.data.type === "open") {
|
||||
document.getElementById("filename").innerText = "Loading logs from other tab...";
|
||||
loadBlob(event.data.logs).then(() => {
|
||||
document.getElementById("filename").innerText = "Logs from other tab at " + new Date();
|
||||
});
|
||||
} else if (event.data.type === "ping") {
|
||||
document.getElementById("filename").innerText = "Waiting for logs from other tab...";
|
||||
event.source.postMessage({type: "pong"});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -164,7 +164,11 @@ function getRootItemHeader(prevItem, item) {
|
||||
async function loadFile() {
|
||||
const file = await openFile();
|
||||
document.getElementById("filename").innerText = file.name;
|
||||
const json = await readFileAsText(file);
|
||||
await loadBlob(file);
|
||||
}
|
||||
|
||||
export async function loadBlob(blob) {
|
||||
const json = await readFileAsText(blob);
|
||||
const logs = JSON.parse(json);
|
||||
logs.items.sort((a, b) => itemStart(a) - itemStart(b));
|
||||
rootItem = {c: logs.items};
|
||||
@ -181,6 +185,7 @@ async function loadFile() {
|
||||
return fragment;
|
||||
}, document.createDocumentFragment());
|
||||
main.replaceChildren(fragment);
|
||||
main.scrollTop = main.scrollHeight;
|
||||
}
|
||||
|
||||
// TODO: make this use processRecursively
|
||||
|
Loading…
Reference in New Issue
Block a user