Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: retain Windows caption controls during loading and errors
Richie McIlroy6a555698a09f
diff --git a/apps/desktop/src/components/CapErrorBoundary.tsx b/apps/desktop/src/components/CapErrorBoundary.tsxindex 2dca68d1d..b7f3801a9 100644--- a/apps/desktop/src/components/CapErrorBoundary.tsx+++ b/apps/desktop/src/components/CapErrorBoundary.tsx@@ -1,55 +1,72 @@import { Button } from "@cap/ui-solid";import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";import { writeText } from "@tauri-apps/plugin-clipboard-manager";+import { type as ostype } from "@tauri-apps/plugin-os";import { ErrorBoundary, type ParentProps } from "solid-js";+import Titlebar from "./titlebar/Titlebar";export function CapErrorBoundary(props: ParentProps) {return (<ErrorBoundaryfallback={(e: Error) => {console.error(e);+ const windowLabel = getCurrentWebviewWindow().label;+ const showTitlebar =+ ostype() === "windows" &&+ ([+ "main",+ "settings",+ "upgrade",+ "mode-select",+ "onboarding",+ "teleprompter",+ ].includes(windowLabel) ||+ /^(editor|screenshot-editor)-\d+$/.test(windowLabel));return (- <div class="w-full h-full flex flex-col justify-center items-center bg-gray-2 border-gray-3 max-h-screen overflow-hidden transition-[border-radius] duration-200 text-(--text-secondary) gap-y-4 max-sm:gap-y-2 px-8 text-center">- <IconCapLogo class="max-sm:size-16" />- <h1 class="text-(--text-primary) text-3xl max-sm:text-xl font-bold">- An Error Occured- </h1>- <p class="mb-2 max-sm:text-sm">- We're very sorry, but something has gone wrong.- </p>- <div class="flex flex-row gap-4 max-sm:flex-col max-sm:gap-2">- <Button- onClick={() => {- writeText(`${e.toString()}\n\n${e.stack}`);- }}- >- Copy Error to Clipboard- </Button>- <Button- onClick={() => {- location.reload();- }}- variant="gray"- >- Reload- </Button>- <Button- onClick={() => getCurrentWebviewWindow().close()}- variant="destructive"- >- Close- </Button>- </div>-- {import.meta.env.DEV && (- <div class="h-0 text-sm">- <pre class="text-left mt-8">{`${e.toString()}\n\n${e.stack- ?.toString()- .split("\n")- .slice(0, 10)- .join("\n")}`}</pre>+ <div class="w-full h-full flex flex-col bg-gray-2 max-h-screen overflow-hidden">+ {showTitlebar && <Titlebar />}+ <div class="flex flex-col flex-1 min-h-0 justify-center items-center border-gray-3 overflow-hidden transition-[border-radius] duration-200 text-(--text-secondary) gap-y-4 max-sm:gap-y-2 px-8 text-center">+ <IconCapLogo class="max-sm:size-16" />+ <h1 class="text-(--text-primary) text-3xl max-sm:text-xl font-bold">+ An Error Occured+ </h1>+ <p class="mb-2 max-sm:text-sm">+ We're very sorry, but something has gone wrong.+ </p>+ <div class="flex flex-row gap-4 max-sm:flex-col max-sm:gap-2">+ <Button+ onClick={() => {+ writeText(`${e.toString()}\n\n${e.stack}`);+ }}+ >+ Copy Error to Clipboard+ </Button>+ <Button+ onClick={() => {+ location.reload();+ }}+ variant="gray"+ >+ Reload+ </Button>+ <Button+ onClick={() => getCurrentWebviewWindow().close()}+ variant="destructive"+ >+ Close+ </Button></div>- )}++ {import.meta.env.DEV && (+ <div class="h-0 text-sm">+ <pre class="text-left mt-8">{`${e.toString()}\n\n${e.stack+ ?.toString()+ .split("\n")+ .slice(0, 10)+ .join("\n")}`}</pre>+ </div>+ )}+ </div></div>);}}diff --git a/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx b/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsxindex 422dc6e7b..1b3233b44 100644--- a/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx+++ b/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx@@ -9,7 +9,7 @@ import {Show,splitProps,} from "solid-js";-import titlebarState from "~/utils/titlebar-state";+import titlebarState, { initializeTitlebar } from "~/utils/titlebar-state";import { WindowControlButton as ControlButton } from "./WindowControlButton";export default function (@@ -33,13 +33,34 @@ export default function ((hasCustomMaximize() || titlebarState.maximizable);const maximized = () => local.maximized ?? titlebarState.maximized;- let unlisten: (() => void) | undefined;- onMount(async () => {- unlisten = await currentWindow.onFocusChanged(({ payload: focused }) =>- setFocus(focused),- );+ let disposed = false;+ const unlisteners: (() => void)[] = [];+ const retainListener = (unlisten: (() => void) | undefined) => {+ if (!unlisten) return;+ if (disposed) unlisten();+ else unlisteners.push(unlisten);+ };++ onMount(() => {+ void Promise.allSettled([+ currentWindow+ .onFocusChanged(({ payload: focused }) => {+ if (!disposed) setFocus(focused);+ })+ .then(retainListener),+ initializeTitlebar().then(retainListener),+ ]).then((results) => {+ for (const result of results) {+ if (result.status === "rejected") {+ console.error("Failed to initialize window controls:", result.reason);+ }+ }+ });+ });+ onCleanup(() => {+ disposed = true;+ for (const unlisten of unlisteners) unlisten();});- onCleanup(() => unlisten?.());const handleClose = async () => {currentWindow.close();diff --git a/apps/desktop/src/routes/(window-chrome).tsx b/apps/desktop/src/routes/(window-chrome).tsxindex 8bb12b3c1..4b80f9c88 100644--- a/apps/desktop/src/routes/(window-chrome).tsx+++ b/apps/desktop/src/routes/(window-chrome).tsx@@ -1,5 +1,4 @@import { type RouteSectionProps, useLocation } from "@solidjs/router";-import type { UnlistenFn } from "@tauri-apps/api/event";import { getCurrentWindow } from "@tauri-apps/api/window";import { type as ostype } from "@tauri-apps/plugin-os";import { cx } from "cva";@@ -15,23 +14,14 @@ import { AbsoluteInsetLoader } from "~/components/Loader";import CaptionControlsMacOS from "~/components/titlebar/controls/CaptionControlsMacOS";import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";import { applyMacOSWindowMaterial } from "~/utils/macos-window-material";-import { initializeTitlebar } from "~/utils/titlebar-state";import {useWindowChromeContext,WindowChromeContext,} from "./(window-chrome)/Context";export default function (props: RouteSectionProps) {- let unlistenResize: UnlistenFn | undefined;const location = useLocation();- onMount(async () => {- console.log("window chrome mounted");- void initializeTitlebar().then((unlisten) => {- unlistenResize = unlisten;- });- });-const handleKeyDown = (e: KeyboardEvent) => {const isMac = ostype() === "macos";const closeShortcut = isMac@@ -49,7 +39,6 @@ export default function (props: RouteSectionProps) {});onCleanup(() => {- unlistenResize?.();window.removeEventListener("keydown", handleKeyDown);});diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsxindex 217556b4d..23a88edbe 100644--- a/apps/desktop/src/routes/editor/Editor.tsx+++ b/apps/desktop/src/routes/editor/Editor.tsx@@ -53,6 +53,7 @@ import {useEditorInstanceContext,} from "./context";import { EditorErrorScreen } from "./EditorErrorScreen";+import { EditorSkeleton } from "./editor-skeleton";import { Header, type TitleSaveRegistration } from "./Header";import { ImportProgress } from "./ImportProgress";import { PlayerContent } from "./Player";@@ -287,13 +288,7 @@ export function Editor() {};return (- <Switch- fallback={- <div class="flex items-center justify-center h-full w-full">- <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-500" />- </div>- }- >+ <Switch fallback={<EditorSkeleton />}><Matchwhen={importStatus() === "importing" ? (projectPath() ?? null) : null}>@@ -362,7 +357,7 @@ function EditorContent(props: {};return (- <Switch>+ <Switch fallback={<EditorSkeleton />}><Match when={errorInfo()}>{(info) => (<EditorErrorScreen@@ -763,7 +758,7 @@ function Inner(props: {<Showwhen={!fullscreenMode()}fallback={- <Suspense>+ <Suspense fallback={<EditorSkeleton />}><ExportPage /></Suspense>}diff --git a/apps/desktop/src/routes/editor/Header.tsx b/apps/desktop/src/routes/editor/Header.tsxindex ce4d7dd60..36b3c7224 100644--- a/apps/desktop/src/routes/editor/Header.tsx+++ b/apps/desktop/src/routes/editor/Header.tsx@@ -1,5 +1,4 @@import { Button } from "@cap/ui-solid";-import type { UnlistenFn } from "@tauri-apps/api/event";import { ask } from "@tauri-apps/plugin-dialog";import { revealItemInDir } from "@tauri-apps/plugin-opener";import { type as ostype } from "@tauri-apps/plugin-os";@@ -11,7 +10,6 @@ import {createSignal,on,onCleanup,- onMount,Show,} from "solid-js";import toast from "solid-toast";@@ -20,7 +18,6 @@ import CaptionControlsMacOS from "~/components/titlebar/controls/CaptionControlsimport CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";import { trackEvent } from "~/utils/analytics";import { commands } from "~/utils/tauri";-import { initializeTitlebar } from "~/utils/titlebar-state";import { useEditorContext } from "./context";import OrganizationDropdown from "./OrganizationDropdown";import PresetsDropdown from "./PresetsDropdown";@@ -69,12 +66,6 @@ export function Header(props: { registerTitleSave: RegisterTitleSave }) {setEditorState,} = useEditorContext();- let unlistenTitlebar: UnlistenFn | undefined;- onMount(async () => {- unlistenTitlebar = await initializeTitlebar();- });- onCleanup(() => unlistenTitlebar?.());-const clearTimelineSelection = () => {if (!editorState.timeline.selection) return false;setEditorState("timeline", "selection", null);diff --git a/apps/desktop/src/routes/editor/ImportProgress.tsx b/apps/desktop/src/routes/editor/ImportProgress.tsxindex d69ef3378..1312bf65c 100644--- a/apps/desktop/src/routes/editor/ImportProgress.tsx+++ b/apps/desktop/src/routes/editor/ImportProgress.tsx@@ -1,6 +1,8 @@import { Button } from "@cap/ui-solid";import { getCurrentWindow } from "@tauri-apps/api/window";+import { type as ostype } from "@tauri-apps/plugin-os";import { createSignal, Match, onCleanup, onMount, Switch } from "solid-js";+import Titlebar from "~/components/titlebar/Titlebar";import {events,type VideoImportProgress as VideoImportProgressEvent,@@ -66,74 +68,77 @@ export function ImportProgress(props: ImportProgressProps) {};return (- <div class="flex flex-col items-center justify-center h-full gap-6">- <Switch>- <Match when={failed()}>- {(errorMessage) => (- <div class="w-80 text-center">+ <div class="flex flex-col flex-1 min-h-0">+ {ostype() === "windows" && <Titlebar />}+ <div class="flex flex-col flex-1 min-h-0 items-center justify-center gap-6">+ <Switch>+ <Match when={failed()}>+ {(errorMessage) => (+ <div class="w-80 text-center">+ <div class="flex items-center justify-center mb-6">+ <div class="w-16 h-16 rounded-full bg-red-3 flex items-center justify-center">+ <IconLucideAlertCircle class="w-8 h-8 text-red-9" />+ </div>+ </div>++ <h2 class="text-lg font-medium text-gray-12 mb-2">+ Import Failed+ </h2>+ <p class="text-sm text-gray-11 mb-6">{errorMessage()}</p>++ <Button variant="gray" onClick={handleClose}>+ Close+ </Button>+ </div>+ )}+ </Match>+ <Match when={!failed()}>+ <div class="w-72 text-center"><div class="flex items-center justify-center mb-6">- <div class="w-16 h-16 rounded-full bg-red-3 flex items-center justify-center">- <IconLucideAlertCircle class="w-8 h-8 text-red-9" />+ <div class="relative">+ <svg+ class="w-20 h-20 animate-spin-slow"+ viewBox="0 0 64 64"+ fill="none"+ >+ <circle+ cx="32"+ cy="32"+ r="28"+ stroke="currentColor"+ stroke-width="4"+ class="text-gray-3"+ />+ <circle+ cx="32"+ cy="32"+ r="28"+ stroke="currentColor"+ stroke-width="4"+ stroke-dasharray={`${progressPercent() * 1.76} 176`}+ stroke-linecap="round"+ class="text-blue-9 transition-all duration-300"+ transform="rotate(-90 32 32)"+ />+ </svg>+ <div class="absolute inset-0 flex items-center justify-center">+ <span class="text-lg font-semibold text-gray-12">+ {progressPercent()}%+ </span>+ </div></div></div><h2 class="text-lg font-medium text-gray-12 mb-2">- Import Failed+ Importing Video</h2>- <p class="text-sm text-gray-11 mb-6">{errorMessage()}</p>-- <Button variant="gray" onClick={handleClose}>- Close- </Button>+ <p class="text-sm text-gray-11 animate-pulse h-5 animate-pulse-slow">+ {funMessages[messageIndex()]}+ </p></div>- )}- </Match>- <Match when={!failed()}>- <div class="w-72 text-center">- <div class="flex items-center justify-center mb-6">- <div class="relative">- <svg- class="w-20 h-20 animate-spin-slow"- viewBox="0 0 64 64"- fill="none"- >- <circle- cx="32"- cy="32"- r="28"- stroke="currentColor"- stroke-width="4"- class="text-gray-3"- />- <circle- cx="32"- cy="32"- r="28"- stroke="currentColor"- stroke-width="4"- stroke-dasharray={`${progressPercent() * 1.76} 176`}- stroke-linecap="round"- class="text-blue-9 transition-all duration-300"- transform="rotate(-90 32 32)"- />- </svg>- <div class="absolute inset-0 flex items-center justify-center">- <span class="text-lg font-semibold text-gray-12">- {progressPercent()}%- </span>- </div>- </div>- </div>-- <h2 class="text-lg font-medium text-gray-12 mb-2">- Importing Video- </h2>- <p class="text-sm text-gray-11 animate-pulse h-5 animate-pulse-slow">- {funMessages[messageIndex()]}- </p>- </div>- </Match>- </Switch>+ </Match>+ </Switch>+ </div></div>);}diff --git a/apps/desktop/src/routes/mode-select.tsx b/apps/desktop/src/routes/mode-select.tsxindex 669cb414d..827de2c43 100644--- a/apps/desktop/src/routes/mode-select.tsx+++ b/apps/desktop/src/routes/mode-select.tsx@@ -1,26 +1,15 @@-import type { UnlistenFn } from "@tauri-apps/api/event";import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";import { type as ostype } from "@tauri-apps/plugin-os";-import { onCleanup, onMount } from "solid-js";+import { onMount } from "solid-js";import ModeSelect from "~/components/ModeSelect";import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";-import { initializeTitlebar } from "~/utils/titlebar-state";const ModeSelectWindow = () => {- let unlistenResize: UnlistenFn | undefined;const isWindows = ostype() === "windows";onMount(async () => {const window = getCurrentWindow();- if (isWindows) {- try {- unlistenResize = await initializeTitlebar();- } catch (error) {- console.error("Failed to initialize titlebar:", error);- }- }-try {const currentSize = await window.innerSize();@@ -32,10 +21,6 @@ const ModeSelectWindow = () => {}});- onCleanup(() => {- unlistenResize?.();- });-return (<divdata-tauri-drag-regiondiff --git a/apps/desktop/src/routes/screenshot-editor/screenshot-editor-skeleton.tsx b/apps/desktop/src/routes/screenshot-editor/screenshot-editor-skeleton.tsxindex 28257ed84..53837bf34 100644--- a/apps/desktop/src/routes/screenshot-editor/screenshot-editor-skeleton.tsx+++ b/apps/desktop/src/routes/screenshot-editor/screenshot-editor-skeleton.tsx@@ -1,5 +1,6 @@import { type as ostype } from "@tauri-apps/plugin-os";import { cx } from "cva";+import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";import IconCapLogo from "~icons/cap/logo";function SkeletonPulse(props: { class?: string }) {@@ -50,7 +51,7 @@ function HeaderSkeleton() {<divclass={cx(- "flex flex-row items-center gap-2",+ "flex flex-row items-center gap-2 h-full",ostype() !== "windows" && "pr-2",)}>@@ -58,6 +59,7 @@ function HeaderSkeleton() {<SkeletonButton /><SkeletonButton /><SkeletonButton />+ {ostype() === "windows" && <CaptionControlsWindows11 />}</div></div>);diff --git a/apps/desktop/src/routes/teleprompter.tsx b/apps/desktop/src/routes/teleprompter.tsxindex 6f65011a5..09fb0db11 100644--- a/apps/desktop/src/routes/teleprompter.tsx+++ b/apps/desktop/src/routes/teleprompter.tsx@@ -22,7 +22,6 @@ import {} from "~/store";import { applyMacOSWindowMaterial } from "~/utils/macos-window-material";import { commands, events } from "~/utils/tauri";-import { initializeTitlebar } from "~/utils/titlebar-state";import IconLucideChevronLeft from "~icons/lucide/chevron-left";import IconLucideChevronRight from "~icons/lucide/chevron-right";import IconLucideEyeOff from "~icons/lucide/eye-off";@@ -111,7 +110,6 @@ export default function Teleprompter() {let scrollElement: HTMLDivElement | undefined;let editorElement: HTMLTextAreaElement | undefined;let saveTimer: ReturnType<typeof setTimeout> | undefined;- let unlistenTitlebar: UnlistenFn | undefined;let unlistenCloseRequested: UnlistenFn | undefined;let resizeObserver: ResizeObserver | undefined;let playbackFrame = 0;@@ -215,12 +213,7 @@ export default function Teleprompter() {document.documentElement.setAttribute("data-transparent-window", "true");document.body.style.background = "transparent";- void Promise.allSettled([- applyMacOSWindowMaterial("teleprompter"),- initializeTitlebar().then((unlisten) => {- unlistenTitlebar = unlisten;- }),- ])+ void Promise.allSettled([applyMacOSWindowMaterial("teleprompter")]).then(async () => {await commands.setTeleprompterWindowLevel(true);await currentWindow.show();@@ -301,7 +294,6 @@ export default function Teleprompter() {clearTimeout(saveTimer);cancelAnimationFrame(playbackFrame);resizeObserver?.disconnect();- unlistenTitlebar?.();unlistenCloseRequested?.();});