feat(app): add voice shortcuts and scoped recovery controls

Share selected video URLs for independent browser playback while retaining explicit byte forwarding. Bring original-page sharing into the player list, verify workspace destinations, and keep local startup independent of external site checks.

Reuse voice actions for page and Windows background shortcuts, derive troubleshooting from current operation facts, and keep floating tools below the native caption.
This commit is contained in:
AAA committed 2026-11-22 01:32:57 -05:00
1 parent f275c5c713
commit 0bb17bf5be
70 files changed
+1825 -267

No files matched your search

@@ -17,6 +17,8 @@ import { channelAppDiscovery } from "../../channel/app-link";
import { OpenInClient } from "./OpenInClient";
import { currentTheme, subscribeTheme } from "../../ui/theme";
import type {} from "../../ui/native-window";
import { diagnoseChannelFact, type AppConnectionState } from "../../channel/diagnosis";
import { ChannelDiagnosisHelp } from "../../channel/components/ChannelDiagnosisHelp";
interface AppConnectionProps {
onConnected?: (health: NonNullable<Awaited<ReturnType<AppDiscovery["health"]>>>, signal: AbortSignal) => void | Promise<void>;
@@ -40,7 +42,7 @@ interface ConnectionAttempt {
export function AppConnectionButton({ onConnected, discovery = channelAppDiscovery, connected, available = true, targetURL, wakeURL: launchTarget }: AppConnectionProps) {
const { lang, t } = useCopy();
const theme = useSyncExternalStore(subscribeTheme, currentTheme, currentTheme);
const [state, setState] = useState<"idle" | "waking" | "busy" | "approval" | "approving" | "ready" | "unavailable" | "incompatible">("idle");
const [state, setState] = useState<AppConnectionState>("idle");
const wakeURL = launchTarget === undefined ? androidAppIntent("piik://app") : launchTarget;
const [helpOpen, setHelpOpen] = useState(false);
const downloadURL = useProjectLink("/#download", "https://github.com/TNTcraftHIM/Piik/releases/latest", helpOpen);
@@ -264,6 +266,7 @@ export function AppConnectionButton({ onConnected, discovery = channelAppDiscove
incompatible: "native.incompatible",
} as const)[state]);
const failed = state === "unavailable" || state === "incompatible";
const diagnosis = diagnoseChannelFact({ area: "app", state });
const update = ready ? release : null;
const availableUpdate = update?.kind === "update-available" || update?.kind === "major-update";
const title = availableUpdate ? t("client.connect.update", { current: build!.version, version: update.version }) : label;
@@ -306,15 +309,15 @@ export function AppConnectionButton({ onConnected, discovery = channelAppDiscove
<Glyph name="x" size={16} />
</button>
</div>
<p id={`${helpId}-message`}>{state === "busy" ? t("client.connect.permissionHint") : label}</p>
<p id={`${helpId}-message`}>{state === "busy" ? t("client.connect.permissionHint") : diagnosis ? t(diagnosis.message) : label}</p>
{state === "ready" && build && <p className="lr-app-connect-version">
<span>{t("client.launch.version", { version: build.version })}</span>
</p>}
{update && <AppReleaseNotice update={update} managementURL={management?.updateSupported ? management.url : undefined} />}
<div className="lr-app-connect-actions">
{!ready && state !== "busy" && state !== "approving" && <button type="button" className="lr-btn" aria-label={t(state === "approval" ? "client.connect.open" : state === "waking" ? "client.connect.continue" : "common.retry")} onClick={() => void connect()}>
<Glyph name={state === "approval" ? "arrowRight" : "refresh"} size={16} /><span>{t(state === "approval" ? "client.connect.open" : state === "waking" ? "client.connect.continue" : "common.retry")}</span>
{!ready && state !== "busy" && state !== "approving" && <button type="button" className={state === "approval" ? "lr-btn is-primary" : "lr-btn"} onClick={() => void connect()}>
<Glyph name={state === "approval" ? "arrowRight" : "refresh"} size={16} /><span>{t(diagnosis?.next ?? (state === "waking" ? "client.connect.continue" : "common.retry"))}</span>
</button>}
{failed && wakeURL && <a className="lr-btn" href={wakeURL} onClick={event => { event.preventDefault(); void connect(true); }}>
<Glyph name="window" size={16} /><span>{t("client.connect.wakeApp")}</span>
@@ -323,6 +326,7 @@ export function AppConnectionButton({ onConnected, discovery = channelAppDiscove
<Glyph name="arrowDown" size={16} /><span>{t("client.connect.download")}</span>
</a>}
</div>
{helpOpen && diagnosis && <ChannelDiagnosisHelp diagnosis={diagnosis} />}
{targetURL && !(typeof window !== "undefined" && window.piikNativeWindow) && <OpenInClient
discovery={discovery} targetURL={targetURL} active={helpOpen} disabled={busy} downloadURL={downloadURL} />}
{state !== "ready" && <p className="lr-app-connect-optional">{t("client.connect.browserHint")}</p>}
@@ -3,6 +3,7 @@ import { useLayoutEffect, useRef, useState, type PointerEvent, type ReactNode, t
import { createPortal } from "react-dom";
import { useCopy } from "../../ui/copy";
import { Glyph } from "../../ui/icons";
import { surfaceViewport } from "../../ui/window-appearance";
import { usePanelWindow, panelWindowAPI, SurfaceDocument, PANEL_SIZE } from "../../ui/panel-window";
import { Btn } from "./primitives";
import "./floating-panel.css";
@@ -143,10 +144,9 @@ export function FloatingPanel({ id, trigger, title, compact = false, anchorOnOpe
// Native hiding/adoption can precede React's effect cleanup. Only this
// document's visible panel can update its remembered in-page position.
if (panel.ownerDocument !== document || !panel.matches(":popover-open")) return;
const layout = document.documentElement;
const width = viewport?.width ?? layout.clientWidth, height = viewport?.height ?? layout.clientHeight;
const maxWidth = Math.max(0, width - 24), maxHeight = Math.max(0, height - 24);
const left = (viewport?.offsetLeft ?? 0) + 12, top = (viewport?.offsetTop ?? 0) + 12;
const bounds = surfaceViewport(panel.ownerDocument);
const maxWidth = Math.max(0, bounds.width - 24), maxHeight = Math.max(0, bounds.height - 24);
const left = bounds.left + 12, top = bounds.top + 12;
let point = change && "x" in change ? change : undefined;
if (change && "corner" in change) {
const { rect, corner, dx, dy } = change;
@@ -180,8 +180,7 @@ export function FloatingPanel({ id, trigger, title, compact = false, anchorOnOpe
// movement owner. Retargeting an open palette must not undo a user's drag.
const anchor = anchorOnOpen && getTrigger()?.getBoundingClientRect();
if (anchor) {
const top = (viewport?.offsetTop ?? 0) + 12;
const bottom = top + (viewport?.height ?? document.documentElement.clientHeight) - 24;
const bottom = surfaceViewport(panel.ownerDocument).bottom - 12;
const below = anchor.bottom + 8;
place({ x: anchor.x + anchor.width / 2 - panel.offsetWidth / 2,
y: below + panel.offsetHeight <= bottom ? below : anchor.top - panel.offsetHeight - 8 });
@@ -189,6 +188,7 @@ export function FloatingPanel({ id, trigger, title, compact = false, anchorOnOpe
viewport?.addEventListener("resize", resize);
viewport?.addEventListener("scroll", resize);
window.addEventListener("resize", resize);
document.addEventListener("fullscreenchange", resize);
// Content changes keep the chosen top-left corner; viewport changes above
// retain relative placement. Both still constrain the panel to the viewport.
const observer = new ResizeObserver(() => place({ x: panel.offsetLeft, y: panel.offsetTop }));
@@ -199,6 +199,7 @@ export function FloatingPanel({ id, trigger, title, compact = false, anchorOnOpe
viewport?.removeEventListener("resize", resize);
viewport?.removeEventListener("scroll", resize);
window.removeEventListener("resize", resize);
document.removeEventListener("fullscreenchange", resize);
observer.disconnect();
};
}, [open, trigger, compact, anchorOnOpen, detached]);
+2 -3
View File
@@ -10,7 +10,7 @@ import { applyTheme, currentTheme, subscribeTheme } from "../../ui/theme";
import { Glyph } from "../../ui/icons";
import { AppConnectionButton } from "./AppConnectionButton";
import { useAnchoredPopover } from "./use-anchored-popover";
import { useProjectLink } from "../../lib/use-project-link";
import { diagnosisGuide } from "../../channel/diagnosis";
import { Btn } from "./primitives";
export type LedState = "live" | "busy" | "warn" | "bad" | "off";
@@ -85,8 +85,7 @@ const webRelease = /^v\d+\.\d+\.\d+$/.test(webVersion)
function BrowserHelpContent({ active, diagnosticControl }: { active: boolean; diagnosticControl?: React.ReactNode }) {
const { lang, t } = useCopy();
const guide = useProjectLink(`/docs/${lang === "zh" ? "zh/" : ""}troubleshooting.html`,
`https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/troubleshooting${lang === "zh" ? ".zh-CN" : ""}.md`, active);
const guide = diagnosisGuide("troubleshooting", lang).fallback;
return <div className="lr-help-content">
<header><strong>Piik Web</strong>
{webRelease ? <a href={webRelease} target="_blank" rel="noopener noreferrer"
@@ -1,5 +1,5 @@
import { useId, useRef, useState } from "react";
import { useProjectLink } from "../../lib/use-project-link";
import { diagnosisGuide } from "../../channel/diagnosis";
import type { StatusDescriptor } from "../../ui/media-status";
import { useCopy, type CopyKey } from "../../ui/copy";
import { Glyph } from "../../ui/icons";
@@ -20,8 +20,7 @@ export function ShareFailureHelp({ status, label, code, checks }: {
const [copied, setCopied] = useState<"idle" | "done" | "failed">("idle");
const copyRequest = useRef<object | null>(null);
const hint = (status.tooltip ?? status.comic)!;
const guide = useProjectLink(`/docs/${lang === "zh" ? "zh/" : ""}troubleshooting.html`,
`https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/troubleshooting${lang === "zh" ? ".zh-CN" : ""}.md`, open);
const guide = diagnosisGuide("troubleshooting", lang).fallback;
return <>
<StatusIndicator status={status} label={label} onActivate={() => {
copyRequest.current = null;
@@ -2,7 +2,7 @@ import { useId, useLayoutEffect, useRef, useState } from "react";
import { BackButton, Btn, Pill } from "./primitives";
import { Glyph } from "../../ui/icons";
import { useCopy, type CopyKey } from "../../ui/copy";
import { siteEntryURL } from "../../lib/site-address";
import { siteEntryError, siteEntryURL } from "../../lib/site-address";
import { isStartupSite, type AppMode } from "../../lib/app-launch";
import type { SiteBookmark } from "../../lib/site-address";
import "./site-management.css";
@@ -76,7 +76,7 @@ export function SiteManagement({ bookmarks, sites, currentOrigin, startupSite, o
}
setDetail(undefined);
} catch (error) {
setBookmarkError(error instanceof Error && error.message === "bookmark_exists" ? "client.bookmarks.duplicate" : "client.connect.saveFailed");
setBookmarkError(error instanceof Error && error.message === "bookmark_exists" ? "client.bookmarks.duplicate" : siteEntryError(error instanceof Error && error.message) ?? "client.connect.saveFailed");
} finally { setPending(undefined); }
}
// Device-operation failures belong to the caller's accessError.
@@ -56,6 +56,7 @@ export function Btn({
pressed,
expanded,
hasPopup,
keyShortcuts,
controls,
popoverTarget,
onClick,
@@ -87,6 +88,7 @@ export function Btn({
hasPopup?: AriaAttributes["aria-haspopup"];
controls?: string;
popoverTarget?: string;
keyShortcuts?: string;
onClick?: () => void;
type?: "button" | "submit";
/** Shared hint comic with its localized caption. */
@@ -123,6 +125,7 @@ export function Btn({
aria-pressed={pressed}
aria-expanded={expanded}
aria-haspopup={hasPopup}
aria-keyshortcuts={keyShortcuts}
aria-controls={controls}
popoverTarget={popoverTarget}
style={softDisabled ? SOFT_DISABLED_STYLE : undefined}