Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Open camera window on load (if not open)

Richie McIlroy64956df42dc9
diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json
index ffad27e2e..0dd6e4695 100644
--- a/apps/desktop/src-tauri/capabilities/default.json
+++ b/apps/desktop/src-tauri/capabilities/default.json
@@ -17,6 +17,7 @@
"core:window:allow-set-focus",
"core:window:allow-start-dragging",
"core:window:allow-set-position",
+ "core:webview:default",
"core:webview:allow-create-webview-window",
"core:app:allow-version",
"shell:default",
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 795815748..c5dad46f9 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -2232,6 +2232,12 @@ async fn reset_microphone_permissions(app: AppHandle) -> Result<(), ()> {
Ok(())
}
+#[tauri::command]
+#[specta::specta]
+async fn is_camera_window_open(app: AppHandle) -> bool {
+ CapWindow::Camera { ws_port: 0 }.get(&app).is_some()
+}
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub async fn run() {
let specta_builder = tauri_specta::Builder::new()
@@ -2286,7 +2292,8 @@ pub async fn run() {
set_general_settings,
delete_auth_open_signin,
reset_camera_permissions,
- reset_microphone_permissions
+ reset_microphone_permissions,
+ is_camera_window_open
])
.events(tauri_specta::collect_events![
RecordingOptionsChanged,
diff --git a/apps/desktop/src/routes/(window-chrome)/index.tsx b/apps/desktop/src/routes/(window-chrome)/index.tsx
index 8e0b4d9bb..a1d31348b 100644
--- a/apps/desktop/src/routes/(window-chrome)/index.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/index.tsx
@@ -86,7 +86,6 @@ export default function () {
}
});
- // important for sign in redirect, trust me
createAsync(() => getAuth());
createUpdateCheck();
@@ -184,6 +183,19 @@ export default function () {
});
};
+ onMount(async () => {
+ if (options.data?.cameraLabel && options.data.cameraLabel !== "No Camera") {
+ const cameraWindowActive = await commands.isCameraWindowOpen();
+
+ if (!cameraWindowActive) {
+ console.log("cameraWindow not found");
+ setOptions({
+ ...options.data,
+ });
+ }
+ }
+ });
+
return (
<div class="flex justify-center flex-col p-[1rem] gap-[0.75rem] text-[0.875rem] font-[400] bg-gray-50 h-full">
<div class="absolute top-3 right-3">
diff --git a/apps/desktop/src/routes/(window-chrome)/update.tsx b/apps/desktop/src/routes/(window-chrome)/update.tsx
index 7f26f1405..c5e90ca34 100644
--- a/apps/desktop/src/routes/(window-chrome)/update.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/update.tsx
@@ -59,12 +59,13 @@ export default function () {
<div>
<Switch fallback={<IconCapLogo class="animate-spin size-4" />}>
<Match when={updateStatus()?.type === "done"}>
- Update has been installed. Restart Cap to finish updating.
- <div class="flex flex-row gap-4">
- <Button variant="secondary" onClick={() => navigate("/")}>
- Restart Later
- </Button>
- <Button onClick={() => relaunch()}>Restart Now</Button>
+ <div class="flex flex-col gap-4">
+ <p>
+ Update has been installed. Restart Cap to finish updating.
+ </p>
+ <div class="flex flex-row">
+ <Button onClick={() => relaunch()}>Restart Now</Button>
+ </div>
</div>
</Match>
<Match
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 49b0fab32..f02b8f207 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -307,6 +307,9 @@ async resetMicrophonePermissions() : Promise<Result<null, null>> {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
+},
+async isCameraWindowOpen() : Promise<boolean> {
+ return await TAURI_INVOKE("is_camera_window_open");
}
}