Release RuneStone 0.1.4 with installable plugins and settings
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
const sessions = new Set<string>();
|
||||
const opening = new Set<Promise<void>>();
|
||||
const closing = new Map<string, Promise<void>>();
|
||||
let stopped = false;
|
||||
|
||||
export async function closeTerminals(): Promise<void> {
|
||||
stopped = true;
|
||||
await Promise.allSettled([...opening]);
|
||||
const results = await Promise.allSettled([...sessions].map(ptyClose));
|
||||
const errors = results.filter(result => result.status === "rejected");
|
||||
if (errors.length) throw new Error(errors.map(result => String(result.reason)).join("\n"));
|
||||
}
|
||||
|
||||
export function ptyOpen(id: string, cols: number, rows: number, cwd: string, profile?: string, directory?: string): Promise<void> {
|
||||
if (stopped) return Promise.reject(new Error("This plugin is disabled."));
|
||||
sessions.add(id);
|
||||
const pending = invoke<void>("pty_open", { id, cols, rows, cwd, profile, directory });
|
||||
opening.add(pending);
|
||||
void pending.finally(() => opening.delete(pending)).catch(() => {});
|
||||
return pending;
|
||||
}
|
||||
|
||||
export function ptyProfiles(): Promise<import("./model").ShellProfile[]> {
|
||||
return invoke("pty_profiles");
|
||||
}
|
||||
export function ptyNewWindow(): Promise<void> {
|
||||
return invoke("pty_new_window", { id: crypto.randomUUID() });
|
||||
}
|
||||
export function ptyDictation(): Promise<void> { return invoke("pty_dictation"); }
|
||||
|
||||
export function ptyWrite(id: string, data: string): Promise<void> {
|
||||
return invoke("pty_write", { id, data });
|
||||
}
|
||||
|
||||
export function ptyResize(id: string, cols: number, rows: number): Promise<void> {
|
||||
return invoke("pty_resize", { id, cols, rows });
|
||||
}
|
||||
|
||||
export function ptyClose(id: string): Promise<void> {
|
||||
const pending = closing.get(id);
|
||||
if (pending) return pending;
|
||||
const close = invoke<void>("pty_close", { id }).then(() => { sessions.delete(id); }).finally(() => closing.delete(id));
|
||||
closing.set(id, close);
|
||||
return close;
|
||||
}
|
||||
Reference in New Issue
Block a user