Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Camera overlay shows up again (With errors)

Ilya7fd8eab5cebc
diff --git a/apps/desktop/src-tauri/capabilities/migrated.json b/apps/desktop/src-tauri/capabilities/migrated.json
index 1184590dd..b77b9a06d 100644
--- a/apps/desktop/src-tauri/capabilities/migrated.json
+++ b/apps/desktop/src-tauri/capabilities/migrated.json
@@ -12,9 +12,10 @@
"core:window:allow-set-size",
"core:window:allow-set-focus",
"core:window:allow-start-dragging",
- "decorum:allow-show-snap-overlay",
+ "core:webview:allow-create-webview-window",
"fs:allow-read-text-file",
"fs:allow-resource-read-recursive",
- "fs:default"
+ "fs:default",
+ "decorum:allow-show-snap-overlay"
]
}
diff --git a/apps/desktop/src-tauri/gen/schemas/capabilities.json b/apps/desktop/src-tauri/gen/schemas/capabilities.json
index bf351ee60..10e66932d 100644
--- a/apps/desktop/src-tauri/gen/schemas/capabilities.json
+++ b/apps/desktop/src-tauri/gen/schemas/capabilities.json
@@ -1 +1 @@
-{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main","camera"],"permissions":["core:default","core:window:allow-close","core:window:allow-center","core:window:allow-minimize","core:window:allow-maximize","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-start-dragging","decorum:allow-show-snap-overlay","fs:allow-read-text-file","fs:allow-resource-read-recursive","fs:default"]}}
\ No newline at end of file
+{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main","camera"],"permissions":["core:default","core:window:allow-close","core:window:allow-center","core:window:allow-minimize","core:window:allow-maximize","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-start-dragging","core:webview:allow-create-webview-window","fs:allow-read-text-file","fs:allow-resource-read-recursive","fs:default","decorum:allow-show-snap-overlay"]}}
\ No newline at end of file
diff --git a/apps/desktop/src-tauri/src/app/commands.rs b/apps/desktop/src-tauri/src/app/commands.rs
index d5f93c3a8..e594df746 100644
--- a/apps/desktop/src-tauri/src/app/commands.rs
+++ b/apps/desktop/src-tauri/src/app/commands.rs
@@ -84,8 +84,31 @@ pub fn reset_camera_permissions() {
#[tauri::command]
#[specta::specta]
-pub fn close_webview(app_handle: tauri::AppHandle, label: String) -> bool {
- app_handle
- .get_webview_window(&label)
- .is_some_and(|window| window.close().is_ok())
+pub fn close_webview(app_handle: tauri::AppHandle, label: String) -> Result<(), String> {
+ match app_handle.get_webview_window(&label) {
+ Some(window) => {
+ let _ = window.close();
+ Ok(())
+ }
+ None => Err(format!("No window found with label {}", &label).to_string()),
+ }
+}
+
+#[tauri::command]
+#[specta::specta]
+pub fn make_webview_transparent(app_handle: tauri::AppHandle, label: String) -> Result<(), String> {
+ #[cfg(target_os = "macos")]
+ {
+ use tauri_plugin_decorum::WebviewWindowExt;
+
+ match app_handle.get_webview_window(&label) {
+ Some(window) => {
+ let _ = window.make_transparent();
+ Ok(())
+ }
+ None => Err(format!("No window found with label {}", &label).to_string()),
+ }
+ }
+ #[cfg(not(target_os = "macos"))]
+ "This command is only available on macOS."
}
diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs
index 74e0235d0..5848b542a 100644
--- a/apps/desktop/src-tauri/src/main.rs
+++ b/apps/desktop/src-tauri/src/main.rs
@@ -5,7 +5,7 @@ use specta_typescript::Typescript;
use std::path::PathBuf;
use std::sync::Arc;
use std::vec;
-use tauri::{Listener, Manager};
+use tauri::Manager;
use tauri_specta::{collect_commands, Builder};
use tokio::sync::Mutex;
use tracing::Level;
@@ -137,7 +137,8 @@ fn main() {
reset_screen_permissions,
reset_microphone_permissions,
reset_camera_permissions,
- close_webview
+ close_webview,
+ make_webview_transparent
]);
#[cfg(debug_assertions)] // <- Only export on non-release builds
diff --git a/apps/desktop/src/components/windows/Camera.tsx b/apps/desktop/src/components/windows/Camera.tsx
index 5fba6f6ed..5f6379700 100644
--- a/apps/desktop/src/components/windows/Camera.tsx
+++ b/apps/desktop/src/components/windows/Camera.tsx
@@ -84,7 +84,7 @@ export const Camera = () => {
if (typeof window === "undefined") return;
tauriWindowImport.then(
- ({ currentMonitor, appWindow, LogicalSize, LogicalPosition }) => {
+ ({ currentMonitor, getCurrentWindow, LogicalSize, LogicalPosition }) => {
currentMonitor().then((monitor) => {
const windowWidth = type === "sm" ? 230 : 400;
const windowHeight = type === "sm" ? 230 : 400;
@@ -103,8 +103,11 @@ export const Camera = () => {
monitor
);
- appWindow.setSize(new LogicalSize(windowWidth, windowHeight));
- appWindow.setPosition(new LogicalPosition(x / scalingFactor, y));
+ const currentWindow = getCurrentWindow();
+ currentWindow.setSize(new LogicalSize(windowWidth, windowHeight));
+ currentWindow.setPosition(
+ new LogicalPosition(x / scalingFactor, y)
+ );
setOverlaySize(type);
}
});
@@ -115,14 +118,14 @@ export const Camera = () => {
const closeWindow = (emitSetDevice = true) => {
if (typeof window === "undefined") return;
- tauriWindowImport.then(async ({ appWindow }) => {
+ tauriWindowImport.then(async ({ getCurrentWindow }) => {
if (emitSetDevice) {
await emit("change-device", {
type: "videoinput",
device: null,
});
}
- appWindow.close();
+ getCurrentWindow().close();
});
};
@@ -141,51 +144,46 @@ export const Camera = () => {
};
const handleContextMenu = async () => {
- const { showMenu } = await import("tauri-plugin-context-menu");
- const videoDevices = devices.filter(
- (device) => device.kind === "videoinput"
+ const { Menu, MenuItem, CheckMenuItem, PredefinedMenuItem } = await import(
+ "@tauri-apps/api/menu"
);
-
- const select = async (device: Device | null) => {
- emit("change-device", { type: "videoinput", device: device }).catch(
- (error) => console.log("Failed to emit change-device event:", error)
+ const createDeviceItems = () =>
+ Promise.all(
+ devices
+ .filter((device) => device.kind === "videoinput")
+ .map(
+ async (device) =>
+ await CheckMenuItem.new({
+ text: device.label,
+ checked: selectedVideoDevice?.index === device.index,
+ action: async () => select(device),
+ })
+ )
);
- };
-
- const menuItems = [
- {
- label: "Select Video:",
- disabled: true,
- },
- ...videoDevices.map((device) => ({
- label: device.label,
- checked: selectedVideoDevice.index === device.index,
- event: async () => select(device),
- })),
- {
- is_separator: true,
- },
- {
- label: "Refresh Overlay",
- event: async () => {
- if (typeof window !== "undefined") {
- window.location.reload();
- }
- },
- },
- {
- label: "Close Overlay",
- checked: selectedVideoDevice === null,
- event: async () => select(null),
- },
- ];
- await showMenu({
- items: [...menuItems],
- ...(videoDevices.length === 0 && {
- items: [{ label: "Nothing found." }],
- }),
+ const menu = await Menu.new({
+ items: [
+ await MenuItem.new({
+ text: "Select Camera:",
+ enabled: false,
+ }),
+ ...(await createDeviceItems()),
+ await PredefinedMenuItem.new({
+ item: "Separator",
+ }),
+ await MenuItem.new({
+ text: "Close Overlay",
+ action: () => select(null),
+ }),
+ ],
});
+ menu.popup();
+ };
+
+ const select = async (device: Device | null) => {
+ emit("change-device", { type: "videoinput", device: device }).catch(
+ (error) => console.log("Failed to emit change-device event:", error)
+ );
};
return (
diff --git a/apps/desktop/src/utils/commands.ts b/apps/desktop/src/utils/commands.ts
index cb2396efd..9ff7949d4 100644
--- a/apps/desktop/src/utils/commands.ts
+++ b/apps/desktop/src/utils/commands.ts
@@ -53,8 +53,21 @@ async resetMicrophonePermissions() : Promise<void> {
async resetCameraPermissions() : Promise<void> {
await TAURI_INVOKE("reset_camera_permissions");
},
-async closeWebview(label: string) : Promise<boolean> {
- return await TAURI_INVOKE("close_webview", { label });
+async closeWebview(label: string) : Promise<Result<null, string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("close_webview", { label }) };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
+async makeWebviewTransparent(label: string) : Promise<Result<null, string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("make_webview_transparent", { label }) };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
}
}
diff --git a/apps/desktop/src/utils/recording/utils.ts b/apps/desktop/src/utils/recording/utils.ts
index 591229904..78e0da91d 100644
--- a/apps/desktop/src/utils/recording/utils.ts
+++ b/apps/desktop/src/utils/recording/utils.ts
@@ -1,6 +1,7 @@
"use client";
import { commands } from "@/utils/commands";
+import { Window } from "@tauri-apps/api/window";
export const enumerateAndStoreDevices = async () => {
if (typeof navigator !== "undefined" && typeof window !== "undefined") {
@@ -78,12 +79,15 @@ export const initializeCameraWindow = async () => {
maximized: false,
resizable: false,
fullscreen: false,
- transparent: true,
decorations: false,
alwaysOnTop: true,
+ visibleOnAllWorkspaces: true,
center: false,
shadow: false,
- })
+ focus: false,
+ }).once("tauri://window-created", () => {
+ commands.makeWebviewTransparent("camera");
+ });
}
}
});