0c2f49876d
- Users page: one Edit user form (display name, email, role, active, a new or generated password, workspaces given or taken back, sign out everywhere), validated as a whole before anything is written (PATCH /api/users/:id, GET /api/users/:id); users.display_name/email added migration-safe. - Settings → Account for every signed-in user: profile, own password (the current one required, this login kept), sign out other devices (/api/me/account, /api/me/password, /api/me/sign-out-others; login cookie only, never a pane token). - Display names wherever a person is named (sidebar, workspace owner groups, Users page and audit log); owner_display_name / reader_display additive. - Users page: admins add and remove Claude/Codex pool accounts. - Folder browser: an admin with their own Linux account opens in their home; the "Server folder" tick opens the host's (never remembered). - AI Proxy: "Config 9router" beside Add profile when 9router is installed, opened on the dashboard's own host (GET /api/ai-proxies/9router). - Terminal: a tmux selection reaches the clipboard over plain HTTP too (writeClipboard's textarea fallback, focus handed back). - Chat: a file the session touched outside the workspace previews (GET /api/sessions/:id/file). - install-system: `!requiretty` only when visudo accepts it (sudo-rs on Ubuntu 25.10+ rejects the setting). - openapi.yaml regenerated; docs (API, SERVER-MODE, LANES) updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
/**
|
|
* @file clipboard.ts
|
|
* @description `copyText(text)` — the one copy path for every "Copy …" action.
|
|
* Uses the async Clipboard API when it exists and falls back to a hidden
|
|
* textarea + `execCommand("copy")`, because `navigator.clipboard` is undefined
|
|
* on a non-secure origin such as `http://<lan-ip>:4820`. Reports the outcome as
|
|
* a toast, so a copy is never silent. `writeClipboard(text)` is the same two
|
|
* paths with no toast, for a copy the user did not click (a terminal
|
|
* selection); it hands the focus back to wherever it was.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import i18n from "../i18n";
|
|
import { toast } from "./toast";
|
|
|
|
function fallbackCopy(text: string): boolean {
|
|
// Selecting the textarea moves the focus: give it back (a terminal keeps typing).
|
|
const was = document.activeElement as HTMLElement | null;
|
|
const ta = document.createElement("textarea");
|
|
ta.value = text;
|
|
ta.setAttribute("readonly", "");
|
|
ta.style.position = "fixed";
|
|
ta.style.opacity = "0";
|
|
document.body.appendChild(ta);
|
|
ta.select();
|
|
try {
|
|
return document.execCommand("copy");
|
|
} catch {
|
|
return false;
|
|
} finally {
|
|
ta.remove();
|
|
was?.focus?.({ preventScroll: true });
|
|
}
|
|
}
|
|
|
|
/** Copy `text` silently: the Clipboard API, else the textarea path. */
|
|
export async function writeClipboard(text: string): Promise<boolean> {
|
|
try {
|
|
if (navigator.clipboard?.writeText) {
|
|
await navigator.clipboard.writeText(text);
|
|
return true;
|
|
}
|
|
} catch {
|
|
/* fall through to the textarea path */
|
|
}
|
|
return fallbackCopy(text);
|
|
}
|
|
|
|
/**
|
|
* Copy text to the clipboard and toast the result.
|
|
* @param quiet Skip the success toast (the caller shows its own feedback).
|
|
* @returns Whether the copy succeeded.
|
|
*/
|
|
export async function copyText(text: string, quiet = false): Promise<boolean> {
|
|
const ok = await writeClipboard(text);
|
|
if (!ok) toast.error(i18n.t("common:copyFailed"));
|
|
else if (!quiet) toast.success(i18n.t("common:copied"));
|
|
return ok;
|
|
}
|