Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): extract teleprompter window options helper

Richie McIlroy2f4b201494c0
diff --git a/apps/desktop/src/utils/teleprompter-window-options.test.ts b/apps/desktop/src/utils/teleprompter-window-options.test.ts
new file mode 100644
index 000000000..0305c2833
--- /dev/null
+++ b/apps/desktop/src/utils/teleprompter-window-options.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from "vitest";
+import { getTeleprompterWindowOptions } from "./teleprompter-window-options";
+
+describe("getTeleprompterWindowOptions", () => {
+ it("keeps a Windows window unfocused and reuses the process browser arguments", () => {
+ const browserArgs = "--disable-vulkan --use-angle=d3d11 --disable-gpu";
+
+ expect(getTeleprompterWindowOptions("windows", browserArgs)).toMatchObject({
+ focus: false,
+ visible: false,
+ decorations: false,
+ additionalBrowserArgs: browserArgs,
+ });
+ });
+
+ it("preserves the macOS window behavior without Windows browser arguments", () => {
+ expect(
+ getTeleprompterWindowOptions("macos", "--disable-gpu"),
+ ).toMatchObject({
+ focus: true,
+ visible: false,
+ decorations: true,
+ additionalBrowserArgs: undefined,
+ });
+ });
+
+ it("refuses to create a Windows window without the process browser arguments", () => {
+ expect(() => getTeleprompterWindowOptions("windows")).toThrow(
+ "Missing Windows WebView2 browser arguments",
+ );
+ });
+});
diff --git a/apps/desktop/src/utils/teleprompter-window-options.ts b/apps/desktop/src/utils/teleprompter-window-options.ts
new file mode 100644
index 000000000..0a78e32dc
--- /dev/null
+++ b/apps/desktop/src/utils/teleprompter-window-options.ts
@@ -0,0 +1,43 @@
+import { LogicalPosition } from "@tauri-apps/api/dpi";
+import type { WebviewWindow } from "@tauri-apps/api/webviewWindow";
+import type { OsType } from "@tauri-apps/plugin-os";
+
+export type TeleprompterWindowOptions = NonNullable<
+ ConstructorParameters<typeof WebviewWindow>[1]
+> & {
+ additionalBrowserArgs?: string;
+};
+
+export function getTeleprompterWindowOptions(
+ platform: OsType,
+ windowsWebview2BrowserArgs?: string,
+): TeleprompterWindowOptions {
+ const isMacOS = platform === "macos";
+ const isWindows = platform === "windows";
+ if (isWindows && !windowsWebview2BrowserArgs) {
+ throw new Error("Missing Windows WebView2 browser arguments");
+ }
+
+ return {
+ url: "/teleprompter",
+ title: "Cap Teleprompter",
+ width: 560,
+ height: 320,
+ minWidth: 420,
+ minHeight: 220,
+ center: true,
+ focus: !isWindows,
+ visible: false,
+ resizable: true,
+ decorations: isMacOS,
+ titleBarStyle: isMacOS ? "overlay" : undefined,
+ hiddenTitle: isMacOS,
+ trafficLightPosition: isMacOS ? new LogicalPosition(14, 14) : undefined,
+ transparent: true,
+ shadow: true,
+ alwaysOnTop: true,
+ visibleOnAllWorkspaces: true,
+ skipTaskbar: true,
+ additionalBrowserArgs: isWindows ? windowsWebview2BrowserArgs : undefined,
+ };
+}