Release RuneStone 0.1.7 with plugin documents and shared menus

This commit is contained in:
Knotty Wyvern
2026-10-06 09:29:09 -07:00
parent 6b7af0d527
commit 5d0a4a24f9
75 changed files with 2286 additions and 1665 deletions
+71 -22
View File
@@ -6,18 +6,27 @@
import { installedPlugins, externalErrors, pluginServiceError, restartPlugins, refreshPlugins, setPluginEnabled } from "./external";
import type { Candidate, RemovalPlan, InstalledPlugin } from "./sdk";
const desktop = isTauri();
const installDateFormat = new Intl.DateTimeFormat(undefined, {
year: "numeric", month: "short", day: "numeric",
hour: "numeric", minute: "2-digit", second: "2-digit", timeZoneName: "short",
});
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 gitForm = $state(false);
let gitUrl = $state("");
let gitTag = $state("");
let gitToken = $state("");
let disposed = false;
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 && (plan || candidates.length || gitForm)) {
if (!modal.open) { previous = document.activeElement instanceof HTMLElement ? document.activeElement : null; modal.showModal(); }
if (!busy) cancelButton?.focus();
}
@@ -26,19 +35,19 @@
async function cancel() {
if (busy) return;
const pending = tokens();
plan = null; candidates = []; selected = [];
plan = null; candidates = []; selected = []; gitForm = false; gitToken = "";
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(() => {}); });
onDestroy(() => { disposed = true; gitToken = ""; 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) {
async function choose() {
await run(async () => {
candidates = await invoke<Candidate[]>("plugins_choose", { folder });
candidates = await invoke<Candidate[]>("plugins_choose");
selected = candidates.filter(item => !item.error && item.manifest).map(item => item.token);
});
}
@@ -51,6 +60,17 @@
candidates = []; selected = []; await refreshPlugins(); previous?.focus();
});
}
async function fromGit() {
await run(async () => {
try {
const result = await invoke<Candidate[]>("plugins_from_git", { url: gitUrl.trim(), tag: gitTag.trim(), token: gitToken || null });
if (disposed) { await invoke("plugins_cancel", { tokens: result.map(item => item.token) }); return; }
candidates = result;
selected = result.filter(item => !item.error && item.manifest).map(item => item.token);
gitForm = false;
} finally { gitToken = ""; }
});
}
async function toggle(id: string, enabled: boolean, hash?: string) {
await run(async () => {
await setPluginEnabled(id, enabled, hash);
@@ -73,7 +93,7 @@
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 controls = [...modal.querySelectorAll<HTMLElement>("button:not(:disabled),input:not(:disabled),select: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(); }
@@ -81,10 +101,10 @@
</script>
<h2>Plug-ins</h2>
<p>Install a package file or select a folder containing plugins.</p>
<p>Install a plugin ZIP file or get a release from a Git repository link.</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>
<button disabled={!desktop || busy} onclick={() => choose()}><Icon icon="file-plus" />Install plugin ZIP</button>
<button disabled={!desktop || busy} onclick={() => { error = ""; gitForm = true; }}><Icon icon="link" />Install from Git link</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>
@@ -100,16 +120,26 @@
<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 class="status">
<span class="badge">{plugin.removal ? "Removal incomplete" : plugin.enabled ? "Enabled" : "Disabled"}</span>
<span class="note">
{#if plugin.installedAt != null}
Installed <time datetime={new Date(plugin.installedAt).toISOString()}>{installDateFormat.format(plugin.installedAt)}</time>
{:else}
Install date unknown
{/if}
</span>
</div>
<div class="controls">
<IconButton icon="folder-open" label="Show files" disabled={busy || plugin.removal} onclick={() => reveal(plugin.manifest.id)} />
{#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}
<span class="danger"><IconButton icon="trash" label="Uninstall" disabled={busy} onclick={() => prepare(plugin)} /></span>
{/if}
</div>
</div>
</div>
{/each}
@@ -117,9 +147,21 @@
{#if error}<p class="error" role="alert">{error}</p>{/if}
<p class="saved" role="status">{message}</p>
{#if candidates.length || plan}
{#if candidates.length || plan || gitForm}
<dialog bind:this={modal} aria-labelledby="plugin-dialog-title" onkeydown={trap} oncancel={event => { event.preventDefault(); event.stopPropagation(); void cancel(); }}>
{#if plan}
{#if gitForm}
<h2 id="plugin-dialog-title">Install from Git link</h2>
<p>Get a Gitea release ZIP, then review it before installation. Git-link installation is an experimental feature.</p>
<form onsubmit={event => { event.preventDefault(); if (!busy) void fromGit(); }}>
<label class="field">Repository link<input type="url" required bind:value={gitUrl} disabled={busy} placeholder="https://host/owner/repository" /></label>
<label class="field">Release tag (optional)<input bind:value={gitTag} disabled={busy} placeholder="Latest release" maxlength="200" /></label>
<label class="field">Access token (optional)<input type="password" bind:value={gitToken} disabled={busy} autocomplete="off" /></label>
<p class="note">Private repositories need a token with read access. RuneStone does not save the token.</p>
{#if gitUrl.trim().startsWith("http:")}<p class="note">HTTP sends the token and package without encryption. Use it only for a trusted local server.</p>{/if}
{#if error}<p class="error" role="alert">{error}</p>{/if}
<footer><button type="button" bind:this={cancelButton} disabled={busy} onclick={() => cancel()}>Cancel</button><button type="submit" disabled={busy || !gitUrl.trim()}><Icon icon="link" />{busy ? "Downloading…" : "Review release"}</button></footer>
</form>
{:else 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>
@@ -155,13 +197,18 @@
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; }
.card { background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); padding: 0 14px 10px; margin-bottom: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 0 8px; }
.row > div { min-width: 0; overflow-wrap: anywhere; }
.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; }
.status { display: flex; flex: 1 1 240px; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.controls { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.controls :global(.icon-btn) { width: 32px; height: 32px; flex-basis: 32px; }
.controls .danger { display: flex; }
.controls .danger :global(.icon-btn) { color: var(--rs-error); }
.error { color: var(--rs-error); white-space: pre-wrap; }
.saved { color: var(--rs-ok); min-height: 20px; }
.danger { color: var(--rs-error); }
@@ -174,4 +221,6 @@
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; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.field input { min-width: 0; padding: 8px 10px; color: var(--rs-text); background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
</style>