Release RuneStone 0.1.4 with installable plugins and settings
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { flushSync, mount, unmount } from "svelte";
|
||||
import type { PluginApi } from "../../src/lib/plugins/sdk.ts";
|
||||
import { terminalShortcut } from "./model.ts";
|
||||
import TerminalBridge from "./TerminalBridge.svelte";
|
||||
import { closeTerminals } from "./api.ts";
|
||||
|
||||
export async function activate(api: PluginApi) {
|
||||
const css = new TextDecoder().decode(await api.assets.read("style.css"));
|
||||
if (api.signal.aborted) return;
|
||||
const style = document.createElement("style");
|
||||
style.textContent = css;
|
||||
document.head.append(style);
|
||||
api.onDispose(() => style.remove());
|
||||
const mounts = new Set<() => Promise<void>>();
|
||||
api.onDispose(closeTerminals);
|
||||
api.onDispose(async () => { await Promise.all([...mounts].map(dispose => dispose())); });
|
||||
api.contribute("terminal", {
|
||||
shortcut: terminalShortcut,
|
||||
mount(container, props) {
|
||||
if (api.signal.aborted) throw new Error("This plugin is disabled.");
|
||||
const instance = mount(TerminalBridge, { target: container, props: { initial: props } });
|
||||
flushSync();
|
||||
let stopping: Promise<void> | undefined;
|
||||
const dispose = () => stopping ??= unmount(instance).then(() => { mounts.delete(dispose); });
|
||||
mounts.add(dispose);
|
||||
return { update: value => instance.update(value), command: action => instance.command(action), dispose };
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user