Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add camera webview window label helpers

Richie McIlroy613a183bbf98
diff --git a/apps/desktop/src/utils/camera-window.ts b/apps/desktop/src/utils/camera-window.ts
new file mode 100644
index 000000000..7e5d08daf
--- /dev/null
+++ b/apps/desktop/src/utils/camera-window.ts
@@ -0,0 +1,24 @@
+import { WebviewWindow } from "@tauri-apps/api/webviewWindow";
+
+const CAMERA_WINDOW_PREFIX = "camera-";
+
+const cameraWindowRank = (label: string) => {
+ if (label === "camera") return 0;
+ if (!label.startsWith(CAMERA_WINDOW_PREFIX)) return -1;
+ const rank = Number(label.slice(CAMERA_WINDOW_PREFIX.length));
+ return Number.isInteger(rank) && rank > 0 ? rank : -1;
+};
+
+export const isCameraWindowLabel = (label: string) =>
+ cameraWindowRank(label) >= 0;
+
+export const getCameraWindow = async () => {
+ const windows = await WebviewWindow.getAll();
+ return (
+ windows
+ .filter((window) => isCameraWindowLabel(window.label))
+ .sort(
+ (a, b) => cameraWindowRank(b.label) - cameraWindowRank(a.label),
+ )[0] ?? null
+ );
+};