Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Fix traffic lights losing their inset when changing the app theme
Ilya67f1ecaf32be
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 1736e6399..86f5170ee 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -1643,6 +1643,7 @@ pub async fn run() {seek_to,send_feedback_request,windows::position_traffic_lights,+ windows::set_theme,global_message_dialog,show_window,write_clipboard_string,diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex 3ea549fc9..6e5b34b3b 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -1,6 +1,6 @@#![allow(unused_mut)]-use crate::fake_window;+use crate::{fake_window, general_settings::AppTheme};use cap_flags::FLAGS;use serde::Deserialize;use specta::Type;@@ -398,11 +398,32 @@ fn add_traffic_lights(window: &WebviewWindow<Wry>, controls_inset: Option<Logica.ok();}+#[tauri::command]+#[specta::specta]+pub fn set_theme(window: tauri::Window, theme: AppTheme) {+ let _ = window.set_theme(match theme {+ AppTheme::System => None,+ AppTheme::Light => Some(tauri::Theme::Light),+ AppTheme::Dark => Some(tauri::Theme::Dark),+ });++ #[cfg(target_os = "macos")]+ position_traffic_lights(window, None);+}+#[tauri::command]#[specta::specta]pub fn position_traffic_lights(window: tauri::Window, controls_inset: Option<(f64, f64)>) {#[cfg(target_os = "macos")]- position_traffic_lights_impl(&window, controls_inset.map(LogicalPosition::from));+ position_traffic_lights_impl(+ &window,+ controls_inset.map(LogicalPosition::from).or_else(|| {+ // Attempt to get the default inset from the window's traffic lights position+ CapWindowId::from_str(window.label())+ .ok()+ .and_then(|id| id.traffic_lights_position().flatten())+ }),+ );}#[cfg(target_os = "macos")]diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsxindex ce99edb13..a830874ec 100644--- a/apps/desktop/src/App.tsx+++ b/apps/desktop/src/App.tsx@@ -14,7 +14,7 @@ import "@cap/ui-solid/main.css";import "unfonts.css";import "./styles/theme.css";import { generalSettingsStore } from "./store";-import type { AppTheme } from "./utils/tauri";+import { commands, type AppTheme } from "./utils/tauri";import type { UnlistenFn } from "@tauri-apps/api/event";import { getCurrentWebviewWindow, WebviewWindow } from "@tauri-apps/api/webviewWindow";@@ -95,18 +95,18 @@ function createThemeListener(currentWindow: WebviewWindow) {onCleanup(() => unlisten?.());function update(appTheme: AppTheme | null | undefined) {- if (appTheme === undefined) return;+ if (appTheme === undefined || appTheme === null) return;if (location.pathname === "/camera" ||location.pathname === "/prev-recordings")return;- currentWindow.setTheme(appTheme === "system" ? null : appTheme).then(() => {+ commands.setTheme(appTheme).then(() => {document.documentElement.classList.toggle("dark",appTheme === "dark" ||- window.matchMedia("(prefers-color-scheme: dark)").matches+ window.matchMedia("(prefers-color-scheme: dark)").matches);});}diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex f73b3dde2..a1be7e26b 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -149,6 +149,9 @@ async sendFeedbackRequest(feedback: string) : Promise<null> {async positionTrafficLights(controlsInset: [number, number] | null) : Promise<void> {await TAURI_INVOKE("position_traffic_lights", { controlsInset });},+async setTheme(theme: AppTheme) : Promise<void> {+ await TAURI_INVOKE("set_theme", { theme });+},async globalMessageDialog(message: string) : Promise<void> {await TAURI_INVOKE("global_message_dialog", { message });},