1
0
silverbullet/plugs/core/debug.ts

93 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-01-16 09:40:16 +00:00
import { editor, markdown } from "$sb/silverbullet-syscall/mod.ts";
2022-05-09 12:59:12 +00:00
export async function parsePageCommand() {
2022-07-04 13:51:04 +00:00
console.log(
"AST",
2022-10-14 13:11:33 +00:00
JSON.stringify(
await markdown.parseMarkdown(await editor.getText()),
null,
2,
),
2022-07-04 13:51:04 +00:00
);
2022-05-09 12:59:12 +00:00
}
export async function showLogsCommand() {
2023-01-16 09:40:16 +00:00
await editor.showPanel(
"bhs",
1,
`
2022-05-09 12:59:12 +00:00
<style>
2023-01-14 17:51:00 +00:00
#close {
2023-01-16 09:40:16 +00:00
width: 100%;
2023-01-14 17:51:00 +00:00
}
2022-05-09 12:59:12 +00:00
#client-log-header {
position: absolute;
left: 0;
2023-01-14 17:51:00 +00:00
top: 35px;
2022-05-09 12:59:12 +00:00
}
#server-log-header {
position: absolute;
right: 0;
2023-01-14 17:51:00 +00:00
top: 35px;
2022-05-09 12:59:12 +00:00
width: 50%;
}
#client-log {
position: absolute;
left: 0;
2023-01-14 17:51:00 +00:00
top: 60px;
2022-05-09 12:59:12 +00:00
bottom: 0;
width: 50%;
overflow: scroll;
}
#server-log {
position: absolute;
right: 0;
2023-01-14 17:51:00 +00:00
top: 60px;
2022-05-09 12:59:12 +00:00
bottom: 0;
width: 50%;
overflow: scroll;
}
</style>
2023-01-14 17:51:00 +00:00
<button onclick="self.close()" id="close">Close</button>
2022-05-09 12:59:12 +00:00
<div id="client-log-header">Client logs (max 100)</div>
2023-01-16 09:40:16 +00:00
<div id="client-log">Loading...</div>
2022-05-09 12:59:12 +00:00
<div id="server-log-header">Server logs (max 100)</div>
2023-01-16 09:40:16 +00:00
<div id="server-log">Loading...</div>`,
`
const clientDiv = document.getElementById("client-log");
2022-05-09 12:59:12 +00:00
clientDiv.scrollTop = clientDiv.scrollHeight;
2023-01-16 09:40:16 +00:00
const serverDiv = document.getElementById("server-log");
2022-05-09 12:59:12 +00:00
serverDiv.scrollTop = serverDiv.scrollHeight;
2023-01-14 17:51:00 +00:00
self.close = () => {
sendEvent("log:hide");
};
2023-01-16 09:40:16 +00:00
syscall("system.getEnv").then((env) => {
const clientServerMode = !!env;
if (!clientServerMode) {
// Running in hybrid mode (mobile), so let's ignore server logs (they're the same as client logs)
serverDiv.style.display = "none";
clientDiv.style.width = "100%";
document.getElementById("server-log-header").style.display = "none";
2023-01-14 17:51:00 +00:00
}
2023-01-16 09:40:16 +00:00
setInterval(() => {
Promise.resolve().then(async () => {
if(clientServerMode) {
const serverLogs = await syscall("sandbox.getServerLogs");
serverDiv.innerHTML = "<pre>" + serverLogs.map((le) => "[" + le.level + "] " + le.message).join("\\n") + "</pre>";
}
const clientLogs = await syscall("sandbox.getLogs");
clientDiv.innerHTML = "<pre>" + clientLogs.map((le) => "[" + le.level + "] " + le.message).join("\\n") + "</pre>";
}).catch(console.error);
}, 1000);
});
`,
);
2022-05-09 12:59:12 +00:00
}
export async function hideBhsCommand() {
2022-10-14 13:11:33 +00:00
await editor.hidePanel("bhs");
2022-05-09 12:59:12 +00:00
}