Release RuneStone 0.1.4 with installable plugins and settings
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy } from "svelte";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import IconButton from "$lib/ui/IconButton.svelte";
|
||||
import { installedPlugins, externalErrors, pluginServiceError, restartPlugins, refreshPlugins, setPluginEnabled } from "./external";
|
||||
import type { Candidate, RemovalPlan, InstalledPlugin } from "./sdk";
|
||||
const desktop = isTauri();
|
||||
let busy = $state(false);
|
||||
let error = $state("");
|
||||
let message = $state("");
|
||||
let candidates = $state<Candidate[]>([]);
|
||||
let selected = $state<string[]>([]);
|
||||
let plan = $state<RemovalPlan | null>(null);
|
||||
let modal: HTMLDialogElement | undefined = $state();
|
||||
let cancelButton: HTMLButtonElement | undefined = $state();
|
||||
let previous: HTMLElement | null = null;
|
||||
const external = $derived($installedPlugins.plugins);
|
||||
$effect(() => {
|
||||
if (modal && (plan || candidates.length)) {
|
||||
if (!modal.open) { previous = document.activeElement instanceof HTMLElement ? document.activeElement : null; modal.showModal(); }
|
||||
if (!busy) cancelButton?.focus();
|
||||
}
|
||||
});
|
||||
function tokens() { return [...candidates.map(item => item.token), ...(plan ? [plan.token] : [])]; }
|
||||
async function cancel() {
|
||||
if (busy) return;
|
||||
const pending = tokens();
|
||||
plan = null; candidates = []; selected = [];
|
||||
modal?.close(); previous?.focus();
|
||||
if (pending.length) await invoke("plugins_cancel", { tokens: pending }).catch(reason => error = String(reason));
|
||||
}
|
||||
onDestroy(() => { const pending = tokens(); if (pending.length) void invoke("plugins_cancel", { tokens: pending }).catch(() => {}); });
|
||||
async function run(action: () => Promise<void>) {
|
||||
busy = true; error = ""; message = "";
|
||||
try { await action(); } catch (reason) { error = String(reason); }
|
||||
finally { busy = false; }
|
||||
}
|
||||
async function choose(folder: boolean) {
|
||||
await run(async () => {
|
||||
candidates = await invoke<Candidate[]>("plugins_choose", { folder });
|
||||
selected = candidates.filter(item => !item.error && item.manifest).map(item => item.token);
|
||||
});
|
||||
}
|
||||
async function install(enabled: boolean) {
|
||||
await run(async () => {
|
||||
const result = await invoke<{ name: string; error: string | null }[]>("plugins_install", { tokens: selected, enabled });
|
||||
message = result.filter(item => !item.error).map(item => `${item.name} installed${enabled ? " and enabled" : ""}.`).join(" ");
|
||||
error = result.filter(item => item.error).map(item => `${item.name}: ${item.error}`).join("\n");
|
||||
await invoke("plugins_cancel", { tokens: candidates.map(item => item.token) });
|
||||
candidates = []; selected = []; await refreshPlugins(); previous?.focus();
|
||||
});
|
||||
}
|
||||
async function toggle(id: string, enabled: boolean, hash?: string) {
|
||||
await run(async () => {
|
||||
await setPluginEnabled(id, enabled, hash);
|
||||
message = "Changes saved.";
|
||||
});
|
||||
}
|
||||
async function prepare(plugin: InstalledPlugin) {
|
||||
await run(async () => { plan = await invoke<RemovalPlan>("plugins_prepare_remove", { id: plugin.manifest.id }); });
|
||||
}
|
||||
async function remove() {
|
||||
if (!plan) return;
|
||||
const current = plan;
|
||||
await run(async () => {
|
||||
try { await invoke("plugins_remove", { token: current.token }); message = `${current.plugin.manifest.name} uninstalled. Settings and workspace documents were kept.`; }
|
||||
finally { plan = null; await refreshPlugins(); previous?.focus(); }
|
||||
});
|
||||
}
|
||||
async function reveal(id?: string) { await run(async () => { await invoke("plugins_reveal", { id: id ?? null }); }); }
|
||||
function trap(event: KeyboardEvent) {
|
||||
event.stopPropagation();
|
||||
if (event.repeat && (event.key === "Enter" || event.key === " ")) event.preventDefault();
|
||||
if (event.key !== "Tab" || !modal) return;
|
||||
const controls = [...modal.querySelectorAll<HTMLElement>("button:not(:disabled),input:not(:disabled)")];
|
||||
const first = controls[0], last = controls.at(-1);
|
||||
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last?.focus(); }
|
||||
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first?.focus(); }
|
||||
}
|
||||
</script>
|
||||
|
||||
<h2>Plug-ins</h2>
|
||||
<p>Install a package file or select a folder containing plugins.</p>
|
||||
<div class="toolbar">
|
||||
<button disabled={!desktop || busy} onclick={() => choose(false)}><Icon icon="file-plus" />Install from file</button>
|
||||
<button disabled={!desktop || busy} onclick={() => choose(true)}><Icon icon="folder-plus" />Install from folder</button>
|
||||
<IconButton icon="folder-open" label="Open plugins folder" disabled={!desktop || busy} onclick={() => reveal()} />
|
||||
<button disabled={!desktop || busy} onclick={() => run(refreshPlugins)}><Icon icon="refresh" />Refresh</button>
|
||||
</div>
|
||||
{#if $installedPlugins.root}<p class="path">{$installedPlugins.root}</p>{/if}
|
||||
{#if !desktop}<p>Installation requires the RuneStone desktop app.</p>{/if}
|
||||
{#if $pluginServiceError}<p class="error" role="alert">{$pluginServiceError}</p>{/if}
|
||||
<h3>Installed plugins</h3>
|
||||
<p class="note">Plugins run with RuneStone's access. Only enable code you trust.</p>
|
||||
{#if !external.length}<p>No plugins installed.</p>{/if}
|
||||
{#each external as plugin (plugin.manifest.id)}
|
||||
<div class="card">
|
||||
<div class="row">
|
||||
<div><label for={`external-${plugin.manifest.id}`}>{plugin.manifest.name}</label><p>{plugin.manifest.description}</p><small>{plugin.manifest.author} · {plugin.manifest.version} · Full app access</small></div>
|
||||
<input id={`external-${plugin.manifest.id}`} type="checkbox" role="switch" checked={plugin.enabled} disabled={busy || plugin.removal} onchange={event => { const value = event.currentTarget.checked; event.currentTarget.checked = plugin.enabled; void toggle(plugin.manifest.id, value, plugin.hash); }} />
|
||||
</div>
|
||||
<p class="path">{plugin.path}</p>
|
||||
{#if plugin.error || $externalErrors[plugin.manifest.id]}<p class="error" role="alert">{plugin.error || $externalErrors[plugin.manifest.id]}</p>{/if}
|
||||
<div class="actions">
|
||||
<span class="badge">{plugin.removal ? "Removal incomplete" : plugin.enabled ? "Enabled" : "Disabled"}</span>
|
||||
<button disabled={busy || plugin.removal} onclick={() => reveal(plugin.manifest.id)}><Icon icon="folder-open" />Show files</button>
|
||||
{#if plugin.removal}
|
||||
<button disabled={busy} onclick={() => run(async () => { await invoke("plugins_retry_remove", { id: plugin.manifest.id }); await refreshPlugins(); message = "Plugin file cleanup completed."; })}><Icon icon="refresh" />Retry cleanup</button>
|
||||
{:else}
|
||||
<button class="danger" disabled={busy} aria-label={`Uninstall ${plugin.manifest.name}`} onclick={() => prepare(plugin)}><Icon icon="trash" />Uninstall</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{#if $restartPlugins.length}<p class="note" role="status">Restart RuneStone to clear all code from plugins that stopped in this window.</p>{/if}
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<p class="saved" role="status">{message}</p>
|
||||
|
||||
{#if candidates.length || plan}
|
||||
<dialog bind:this={modal} aria-labelledby="plugin-dialog-title" onkeydown={trap} oncancel={event => { event.preventDefault(); event.stopPropagation(); void cancel(); }}>
|
||||
{#if plan}
|
||||
<h2 id="plugin-dialog-title">{`Uninstall ${plan.plugin.manifest.name}?`}</h2>
|
||||
<p>{plan.plugin.manifest.author} · {plan.plugin.manifest.version}</p>
|
||||
<p class="path">{plan.plugin.path}</p>
|
||||
<p>This stops the plugin in every window and permanently deletes its installed folder. Settings, source packages, and workspace documents stay intact.</p>
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<footer>
|
||||
<button bind:this={cancelButton} disabled={busy} onclick={() => cancel()}>Cancel</button>
|
||||
<button disabled={busy} onclick={async () => { const current = plan; await cancel(); if (current) await toggle(current.plugin.manifest.id, false); }}>Disable instead</button>
|
||||
<button class="danger" disabled={busy} onclick={event => { if (event.detail < 2) void remove(); }}>{busy ? "Removing…" : "Uninstall and delete files"}</button>
|
||||
</footer>
|
||||
{:else}
|
||||
<h2 id="plugin-dialog-title">Review plugin installation</h2>
|
||||
<p>Plugins run with RuneStone's access. Only enable code you trust.</p>
|
||||
{#each candidates as candidate (candidate.token)}
|
||||
<div class="candidate">
|
||||
<label><input type="checkbox" bind:group={selected} value={candidate.token} disabled={busy || !!candidate.error} />{candidate.manifest?.name ?? "Invalid package"}</label>
|
||||
{#if candidate.manifest}<p>{candidate.manifest.author} · {candidate.manifest.version}</p><p>{candidate.manifest.description}</p><p class="path">Destination: {$installedPlugins.root}\{candidate.manifest.id}</p>{/if}
|
||||
<p class="path">Source: {candidate.source}</p>
|
||||
{#if candidate.error}<p class="error">{candidate.error}</p>{/if}
|
||||
</div>
|
||||
{/each}
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<footer><button bind:this={cancelButton} disabled={busy} onclick={() => cancel()}>Cancel</button><button disabled={busy || !selected.length} onclick={() => install(false)}>Install</button><button disabled={busy || !selected.length} onclick={() => install(true)}>Install and enable</button></footer>
|
||||
{/if}
|
||||
</dialog>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
h2 { margin: 0; font-size: 23px; color: var(--rs-text-strong); }
|
||||
h3 { font-size: 14px; margin: 24px 0 10px; }
|
||||
p { color: var(--rs-text-dim); line-height: 1.6; }
|
||||
button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 10px; color: var(--rs-text); background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||||
button:hover:not(:disabled) { background: var(--rs-bg-active); }
|
||||
button:disabled { opacity: .5; }
|
||||
.toolbar, .actions, footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
|
||||
.card { background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); padding: 0 18px 14px; margin-bottom: 12px; }
|
||||
.row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 0; }
|
||||
.row p { margin: 5px 0; font-size: 12px; }
|
||||
label { font-weight: 500; }
|
||||
.path { overflow-wrap: anywhere; font-size: 11px; }
|
||||
small, .badge, .note { color: var(--rs-text-dim); font-size: 12px; }
|
||||
.badge { margin-right: auto; }
|
||||
.error { color: var(--rs-error); white-space: pre-wrap; }
|
||||
.saved { color: var(--rs-ok); min-height: 20px; }
|
||||
.danger { color: var(--rs-error); }
|
||||
input[role=switch] { appearance: none; width: 38px; height: 22px; flex: 0 0 38px; border-radius: 20px; background: var(--rs-bg-active); border: 1px solid var(--rs-text-dim); cursor: pointer; }
|
||||
input[role=switch]::before { content: ""; display: block; width: 16px; height: 16px; margin: 2px; background: var(--rs-text); border-radius: 50%; }
|
||||
input[role=switch]:checked { background: var(--rs-accent); border-color: var(--rs-accent); }
|
||||
input[role=switch]:checked::before { transform: translateX(16px); background: var(--rs-bg); }
|
||||
dialog { width: min(650px, 90vw); max-height: 85vh; padding: 24px; color: var(--rs-text); background: var(--rs-bg); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||||
dialog::backdrop { background: #0009; }
|
||||
footer { justify-content: flex-end; margin-top: 24px; }
|
||||
.candidate { padding: 16px 0; border-bottom: 1px solid var(--rs-border); }
|
||||
.candidate label { display: flex; gap: 8px; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user