YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
Fix intermittent tray/menu crash on macOS (panic across Obj-C FFI) (#2263)
Divanshu7ba05575da82
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rsindex 093dfcc8d..f9e0b9a78 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs@@ -281,7 +281,7 @@ pub async fn open_pipe_window(let window_clone = window.clone();window.on_window_event(move |event| {if let tauri::WindowEvent::CloseRequested { api, .. } = event {- let mut is_closing = is_closing_clone.lock().unwrap();+ let mut is_closing = is_closing_clone.lock().unwrap_or_else(|e| e.into_inner());if *is_closing {return;}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/health.rs b/apps/screenpipe-app-tauri/src-tauri/src/health.rsindex cc1447410..dc2662d3c 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/health.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/health.rs@@ -57,20 +57,20 @@ static RECORDING_INFO: Lazy<RwLock<RecordingInfo>> = Lazy::new(|| {});pub fn get_recording_status() -> RecordingStatus {- RECORDING_INFO.read().unwrap().status+ RECORDING_INFO.read().unwrap_or_else(|e| e.into_inner()).status}pub fn get_recording_info() -> RecordingInfo {- RECORDING_INFO.read().unwrap().clone()+ RECORDING_INFO.read().unwrap_or_else(|e| e.into_inner()).clone()}#[allow(dead_code)]fn set_recording_status(status: RecordingStatus) {- RECORDING_INFO.write().unwrap().status = status;+ RECORDING_INFO.write().unwrap_or_else(|e| e.into_inner()).status = status;}fn set_recording_info(status: RecordingStatus, devices: Vec<DeviceInfo>) {- let mut info = RECORDING_INFO.write().unwrap();+ let mut info = RECORDING_INFO.write().unwrap_or_else(|e| e.into_inner());info.status = status;info.devices = devices;}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex d5e02567c..ae5238cad 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -116,14 +116,20 @@ fn setup_dock_menu(app_handle: AppHandle) {extern "C" fn show_screenpipe(_this: &Object, _sel: Sel, _sender: id) {unsafe {if let Some(ref app) = DOCK_APP_HANDLE {- show_main_window(app, false);+ let app_for_closure = app.clone();+ let _ = app.run_on_main_thread(move || {+ show_main_window(&app_for_closure, false);+ });}}}extern "C" fn open_settings(_this: &Object, _sel: Sel, _sender: id) {unsafe {if let Some(ref app) = DOCK_APP_HANDLE {- let _ = ShowRewindWindow::Settings { page: None }.show(app);+ let app_for_closure = app.clone();+ let _ = app.run_on_main_thread(move || {+ let _ = ShowRewindWindow::Settings { page: None }.show(&app_for_closure);+ });}}}@@ -290,9 +296,9 @@ async fn register_shortcut(global_shortcut.on_shortcut(shortcut, move |app, _shortcut, event| {- // Only trigger on key press, not release- // Wrap in catch_unwind: shortcut handlers are called from tao::send_event- // which crosses the Obj-C FFI boundary (nounwind). A panic here would abort().+ // Only trigger on key press, not release.+ // Shortcut handlers are called from tao::send_event (Obj-C FFI, nounwind).+ // Handler must defer heavy work itself (clone + run_on_main_thread) so sync path stays minimal.if matches!(event.state, ShortcutState::Pressed) {if let Err(e) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {handler(app);@@ -340,67 +346,69 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),error!("failed to unregister all shortcuts: {}", e);}- // Register show shortcut+ // Register show shortcut (defer off event stack: handler runs from tao::send_event)register_shortcut(app, &config.show, config.is_disabled("show"), |app| {- info!("show shortcut triggered - attempting to show/hide main overlay");- let _ = app.emit("shortcut-show", ());- #[cfg(target_os = "macos")]- {- use crate::window_api::main_label_for_mode;- use crate::store::SettingsStore;- // Get current mode to find the right window label- let mode = SettingsStore::get(app)- .unwrap_or_default()- .unwrap_or_default()- .overlay_mode;- let label = main_label_for_mode(&mode);-- if let Some(window) = app.get_webview_window(label) {- match window.is_visible() {- Ok(true) => {- info!("window is visible, hiding main window");- hide_main_window(app)- }- _ => {- info!(- "window is not visible, showing main window"- );- show_main_window(app, false)+ let app_for_closure = app.clone();+ let _ = app.run_on_main_thread(move || {+ let app = &app_for_closure;+ info!("show shortcut triggered - attempting to show/hide main overlay");+ let _ = app.emit("shortcut-show", ());+ #[cfg(target_os = "macos")]+ {+ use crate::window_api::main_label_for_mode;+ use crate::store::SettingsStore;+ // Get current mode to find the right window label+ let mode = SettingsStore::get(app)+ .unwrap_or_default()+ .unwrap_or_default()+ .overlay_mode;+ let label = main_label_for_mode(&mode);++ if let Some(window) = app.get_webview_window(label) {+ match window.is_visible() {+ Ok(true) => {+ info!("window is visible, hiding main window");+ hide_main_window(app)+ }+ _ => {+ info!("window is not visible, showing main window");+ show_main_window(app, false)+ }}+ } else {+ info!("main window not found for mode '{}', creating it", mode);+ show_main_window(app, false)}- } else {- debug!("main window not found for mode '{}', creating it", mode);- show_main_window(app, false)- }- }- #[cfg(not(target_os = "macos"))]- {- // Debug: list all existing windows- for (label, _) in app.webview_windows() {- info!("existing window: {}", label);}+ #[cfg(not(target_os = "macos"))]+ {+ // Debug: list all existing windows+ for (label, _) in app.webview_windows() {+ info!("existing window: {}", label);+ }- if let Some(window) = app.get_webview_window("main") {- info!("found main window, checking visibility");- match window.is_visible() {- Ok(true) => {- info!("main window is visible, hiding it");- hide_main_window(app)- }- Ok(false) => {- info!("main window exists but not visible, showing it");- show_main_window(app, false)- }- Err(e) => {- info!("error checking visibility: {}, showing main window anyway", e);- show_main_window(app, false)+ if let Some(window) = app.get_webview_window("main") {+ info!("found main window, checking visibility");+ match window.is_visible() {+ Ok(true) => {+ info!("main window is visible, hiding it");+ hide_main_window(app)+ }+ Ok(false) => {+ info!("main window exists but not visible, showing it");+ show_main_window(app, false)+ }+ Err(e) => {+ info!("error checking visibility: {}, showing main window anyway", e);+ show_main_window(app, false)+ }}+ } else {+ info!("main window not found, creating it");+ show_main_window(app, false)}- } else {- info!("main window not found, creating it");- show_main_window(app, false)}- }+ });}).await?;@@ -433,9 +441,10 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),&config.start_audio,config.is_disabled("start_audio"),|app| {- let store = get_store(app, None).unwrap();- store.set("disableAudio", false);- store.save().unwrap();+ if let Ok(store) = get_store(app, None) {+ store.set("disableAudio", false);+ let _ = store.save();+ }let _ = app.emit("shortcut-start-audio", ());info!("start audio shortcut triggered");},@@ -448,88 +457,96 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),&config.stop_audio,config.is_disabled("stop_audio"),|app| {- let store = get_store(app, None).unwrap();- store.set("disableAudio", true);- store.save().unwrap();+ if let Ok(store) = get_store(app, None) {+ store.set("disableAudio", true);+ let _ = store.save();+ }let _ = app.emit("shortcut-stop-audio", ());info!("stop audio shortcut triggered");},).await?;- // Register show chat shortcut (global - toggles standalone AI chat window)+ // Register show chat shortcut (global - toggles standalone AI chat window) (defer off event stack)register_shortcut(app,&config.show_chat,config.is_disabled("show_chat"),|app| {- info!("show chat shortcut triggered");- let _ = app.emit("shortcut-show-chat", ());- // Toggle the chat window - hide if visible, show if not.- // Use order_out (not close) to preserve the pre-created panel- // so it can reappear on fullscreen Spaces without re-creation.- if let Some(_window) = app.get_webview_window("chat") {- #[cfg(target_os = "macos")]- {- use tauri_nspanel::ManagerExt;- if let Ok(panel) = app.get_webview_panel("chat") {- if panel.is_visible() {- panel.order_out(None);- return;+ let app_for_closure = app.clone();+ let _ = app.run_on_main_thread(move || {+ let app = &app_for_closure;+ info!("show chat shortcut triggered");+ let _ = app.emit("shortcut-show-chat", ());+ // Toggle the chat window - hide if visible, show if not.+ // Use order_out (not close) to preserve the pre-created panel+ // so it can reappear on fullscreen Spaces without re-creation.+ if let Some(_window) = app.get_webview_window("chat") {+ #[cfg(target_os = "macos")]+ {+ use tauri_nspanel::ManagerExt;+ if let Ok(panel) = app.get_webview_panel("chat") {+ if panel.is_visible() {+ panel.order_out(None);+ return;+ }}}- }- #[cfg(not(target_os = "macos"))]- {- if _window.is_visible().unwrap_or(false) {- let _ = _window.hide();- return;+ #[cfg(not(target_os = "macos"))]+ {+ if _window.is_visible().unwrap_or(false) {+ let _ = _window.hide();+ return;+ }}}- }- let _ = ShowRewindWindow::Chat.show(app);+ let _ = ShowRewindWindow::Chat.show(app);+ });},).await?;- // Register search shortcut (global - opens overlay with search focused)+ // Register search shortcut (global - opens overlay with search focused) (defer off event stack)register_shortcut(app,&config.search,config.is_disabled("search"),|app| {- info!("search shortcut triggered");- // Always show the overlay, then emit search event to focus the search input- #[cfg(target_os = "macos")]- {- use crate::window_api::main_label_for_mode;- use crate::store::SettingsStore;- let mode = SettingsStore::get(app)- .unwrap_or_default()- .unwrap_or_default()- .overlay_mode;- let label = main_label_for_mode(&mode);-- if let Some(window) = app.get_webview_window(label) {- if !window.is_visible().unwrap_or(false) {+ let app_for_closure = app.clone();+ let _ = app.run_on_main_thread(move || {+ let app = &app_for_closure;+ info!("search shortcut triggered");+ // Always show the overlay, then emit search event to focus the search input+ #[cfg(target_os = "macos")]+ {+ use crate::window_api::main_label_for_mode;+ use crate::store::SettingsStore;+ let mode = SettingsStore::get(app)+ .unwrap_or_default()+ .unwrap_or_default()+ .overlay_mode;+ let label = main_label_for_mode(&mode);+ if let Some(window) = app.get_webview_window(label) {+ if !window.is_visible().unwrap_or(false) {+ show_main_window(app, false);+ }+ } else {show_main_window(app, false);}- } else {- show_main_window(app, false);}- }- #[cfg(not(target_os = "macos"))]- {- if let Some(window) = app.get_webview_window("main") {- if !window.is_visible().unwrap_or(false) {+ #[cfg(not(target_os = "macos"))]+ {+ if let Some(window) = app.get_webview_window("main") {+ if !window.is_visible().unwrap_or(false) {+ show_main_window(app, false);+ }+ } else {show_main_window(app, false);}- } else {- show_main_window(app, false);}- }- // Emit event so the frontend opens the search modal- let _ = app.emit("open-search", ());+ // Emit event so the frontend opens the search modal+ let _ = app.emit("open-search", ());+ });},).await?;@@ -1020,6 +1037,10 @@ async fn main() {// By logging here we capture the actual panic message for diagnosis.let default_hook = std::panic::take_hook();std::panic::set_hook(Box::new(move |info| {+ // Log the actual panic first — before any processing. Once unwinding hits+ // Obj-C (e.g. tao::send_event), we get panic_cannot_unwind and lose the real message.+ eprintln!("PANIC: {}", info);+let thread = std::thread::current();let thread_name = thread.name().unwrap_or("<unnamed>");let payload = if let Some(s) = info.payload().downcast_ref::<&str>() {@@ -1260,18 +1281,23 @@ async fn main() {;#[cfg(not(target_os = "linux"))]let app = app.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {- // Focus the existing window- show_main_window(app, false);-- // Forward deep-link URL from args- if let Some(url) = args.iter().find(|a| a.starts_with("screenpipe://")) {- let _ = app.emit("deep-link-received", url.clone());- }+ // Defer off event stack: plugin may invoke this from run loop (nounwind).+ let app_for_closure = app.clone();+ let args_clone = args.clone();+ let _ = app.run_on_main_thread(move || {+ // Focus the existing window+ show_main_window(&app_for_closure, false);++ // Forward deep-link URL from args+ if let Some(url) = args_clone.iter().find(|a| a.starts_with("screenpipe://")) {+ let _ = app_for_closure.emit("deep-link-received", url.clone());+ }- // Forward CLI args- if !args.is_empty() {- let _ = app.emit("second-instance-args", args.clone());- }+ // Forward CLI args+ if !args_clone.is_empty() {+ let _ = app_for_closure.emit("second-instance-args", args_clone.clone());+ }+ });}));let app = app.plugin(tauri_plugin_global_shortcut::Builder::new().build());@@ -1441,7 +1467,11 @@ async fn main() {app.on_menu_event(|app_handle, event| {match event.id().as_ref() {"settings" => {- let _ = ShowRewindWindow::Settings { page: None }.show(app_handle);+ // Defer off event stack (same as tray: runs from tao::send_event).+ let app_for_closure = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ let _ = ShowRewindWindow::Settings { page: None }.show(&app_for_closure);+ });}"check_for_updates" => {let app = app_handle.clone();@@ -1989,8 +2019,10 @@ async fn main() {}app.run(|app_handle, event| {- // Wrap in catch_unwind: this closure is called from tao::send_event- // which crosses the Obj-C FFI boundary (nounwind). A panic here would abort().+ // CRITICAL: This closure is called from tao::send_event (Obj-C FFI, nounwind).+ // Unwinding cannot cross that boundary, so catch_unwind never runs — any panic+ // triggers panic_cannot_unwind and abort(). Do not use unwrap/expect/panic! here+ // or in any code this synchronously calls (e.g. ShowRewindWindow::show/close).let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {match event {tauri::RunEvent::Ready { .. } => {@@ -2063,11 +2095,13 @@ async fn main() {if let Ok(window_id) = RewindWindowId::from_str(label.as_str()) {match window_id {RewindWindowId::Settings => {- // Closing Settings hides the Main panel (it's always a panel now)- let _ = ShowRewindWindow::Main.close(&app_handle);- return;+ // Closing Settings hides the Main panel (it's always a panel now).+ // Defer off the event stack: run handler must stay panic-free.+ let app = app_handle.app_handle().clone();+ let _ = app_handle.app_handle().run_on_main_thread(move || {+ let _ = ShowRewindWindow::Main.close(&app);+ });}-_ => {}}}@@ -2077,9 +2111,11 @@ async fn main() {tauri::RunEvent::Reopen {..} => {--- let _ = ShowRewindWindow::Main.show(&app_handle);+ // Defer off the event stack so run handler stays panic-free.+ let app = app_handle.app_handle().clone();+ let _ = app_handle.app_handle().run_on_main_thread(move || {+ let _ = ShowRewindWindow::Main.show(&app);+ });}_ => {}}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/tray.rs b/apps/screenpipe-app-tauri/src-tauri/src/tray.rsindex e76f512f1..d2f0abcc0 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/tray.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/tray.rs@@ -387,8 +387,8 @@ fn create_dynamic_menu(fn setup_tray_click_handlers(main_tray: &TrayIcon) -> Result<()> {main_tray.on_menu_event(move |app_handle, event| {- // Wrap in catch_unwind: menu event handlers are called from tao::send_event- // which crosses the Obj-C FFI boundary (nounwind). A panic here would abort().+ // This runs inside tao::send_event (Obj-C FFI, nounwind). handle_menu_event+ // only clones and schedules work via run_on_main_thread — no heavy work here.if let Err(e) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {handle_menu_event(app_handle, event);})) {@@ -399,22 +399,34 @@ fn setup_tray_click_handlers(main_tray: &TrayIcon) -> Result<()> {Ok(())}+/// Tray menu handler runs inside tao::send_event (Obj-C FFI, nounwind). We must not+/// do any heavy or panicking work here — defer all window/show/open work to+/// run_on_main_thread so the sync path is minimal and panic-free.fn handle_menu_event(app_handle: &AppHandle, event: tauri::menu::MenuEvent) {match event.id().as_ref() {"show" => {- show_main_window(app_handle, false);- let _ = app_handle.emit("tray-show-timeline", ());+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ show_main_window(&app, false);+ let _ = app.emit("tray-show-timeline", ());+ });}"show_search" => {// Search is a modal on the main window, not a separate window.// Show main window first, then emit event to open the search modal.- show_main_window(app_handle, false);- let _ = app_handle.emit("open-search", ());- let _ = app_handle.emit("tray-show-search", ());+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ show_main_window(&app, false);+ let _ = app.emit("open-search", ());+ let _ = app.emit("tray-show-search", ());+ });}"show_chat" => {- let _ = ShowRewindWindow::Chat.show(app_handle);- let _ = app_handle.emit("tray-show-chat", ());+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ let _ = ShowRewindWindow::Chat.show(&app);+ let _ = app.emit("tray-show-chat", ());+ });}"start_recording" => {let _ = app_handle.emit("shortcut-start-recording", ());@@ -423,56 +435,77 @@ fn handle_menu_event(app_handle: &AppHandle, event: tauri::menu::MenuEvent) {let _ = app_handle.emit("shortcut-stop-recording", ());}"fix_permissions" => {- let _ = ShowRewindWindow::PermissionRecovery.show(app_handle);+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ let _ = ShowRewindWindow::PermissionRecovery.show(&app);+ });}"releases" => {- let _ = app_handle.opener().open_url("https://screenpi.pe/changelog", None::<&str>);+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ let _ = app.opener().open_url("https://screenpi.pe/changelog", None::<&str>);+ });}"update_now" => {- // For source builds, show info dialog about updates- if is_source_build(app_handle) {- let app = app_handle.clone();- tauri::async_runtime::spawn(async move {- let dialog = app- .dialog()- .message(- "auto-updates are only available in the pre-built version.\n\n\- source builds require manual updates from github.",- )- .title("source build detected")- .buttons(MessageDialogButtons::OkCancelCustom(- "download pre-built".to_string(),- "view on github".to_string(),- ));-- dialog.show(move |clicked_download| {- if clicked_download {- let _ = app.opener().open_url("https://screenpi.pe/download", None::<&str>);- } else {- let _ = app.opener().open_url("https://github.com/screenpipe/screenpipe/releases", None::<&str>);- }+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ // For source builds, show info dialog about updates+ if is_source_build(&app) {+ tauri::async_runtime::spawn(async move {+ let dialog = app+ .dialog()+ .message(+ "auto-updates are only available in the pre-built version.\n\n\+ source builds require manual updates from github.",+ )+ .title("source build detected")+ .buttons(MessageDialogButtons::OkCancelCustom(+ "download pre-built".to_string(),+ "view on github".to_string(),+ ));++ dialog.show(move |clicked_download| {+ if clicked_download {+ let _ = app.opener().open_url("https://screenpi.pe/download", None::<&str>);+ } else {+ let _ = app.opener().open_url("https://github.com/screenpipe/screenpipe/releases", None::<&str>);+ }+ });});- });- } else {- // For production builds, emit event to trigger update- let _ = app_handle.emit("update-now-clicked", ());- }+ } else {+ // For production builds, emit event to trigger update+ let _ = app.emit("update-now-clicked", ());+ }+ });}"settings" => {- let _ = ShowRewindWindow::Settings { page: None }.show(app_handle);+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ let _ = ShowRewindWindow::Settings { page: None }.show(&app);+ });}"feedback" => {- let _ = ShowRewindWindow::Settings { page: Some("feedback".to_string()) }.show(app_handle);+ let app = app_handle.clone();+ let page = Some("feedback".to_string());+ let _ = app_handle.run_on_main_thread(move || {+ let _ = ShowRewindWindow::Settings { page }.show(&app);+ });}"book_call" => {- let _ = app_handle.opener().open_url("https://cal.com/team/screenpipe/chat", None::<&str>);+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ let _ = app.opener().open_url("https://cal.com/team/screenpipe/chat", None::<&str>);+ });}"onboarding" => {- // Reset onboarding state so it shows even if previously completed- let _ = OnboardingStore::update(app_handle, |onboarding| {- onboarding.reset();+ let app = app_handle.clone();+ let _ = app_handle.run_on_main_thread(move || {+ // Reset onboarding state so it shows even if previously completed+ let _ = OnboardingStore::update(&app, |onboarding| {+ onboarding.reset();+ });+ let _ = ShowRewindWindow::Onboarding.show(&app);});- let _ = ShowRewindWindow::Onboarding.show(app_handle);}"quit" => {debug!("Quit requested");@@ -538,9 +571,9 @@ async fn update_menu_if_needed(.collect(),};- // Compare with last state+ // Compare with last state (poison-safe: run handler must not panic)let should_update = {- let mut last_state = LAST_MENU_STATE.lock().unwrap();+ let mut last_state = LAST_MENU_STATE.lock().unwrap_or_else(|e| e.into_inner());if *last_state != new_state {*last_state = new_state.clone();truediff --git a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rsindex f39b270a0..fb2178d0c 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/window_api.rs@@ -46,7 +46,7 @@ fn save_frontmost_app() {let frontmost: id = msg_send![workspace, frontmostApplication];if frontmost != nil {let _: () = msg_send![frontmost, retain];- let mut prev = PREVIOUS_FRONTMOST_APP.lock().unwrap();+ let mut prev = PREVIOUS_FRONTMOST_APP.lock().unwrap_or_else(|e| e.into_inner());if *prev != 0 {let old = *prev as id;let _: () = msg_send![old, release];@@ -62,7 +62,7 @@ fn save_frontmost_app() {pub fn restore_frontmost_app() {use objc::{msg_send, sel, sel_impl};let ptr = {- let mut prev = PREVIOUS_FRONTMOST_APP.lock().unwrap();+ let mut prev = PREVIOUS_FRONTMOST_APP.lock().unwrap_or_else(|e| e.into_inner());let p = *prev;*prev = 0;p@@ -85,7 +85,7 @@ pub fn restore_frontmost_app() {pub fn clear_frontmost_app() {use objc::{msg_send, sel, sel_impl};let ptr = {- let mut prev = PREVIOUS_FRONTMOST_APP.lock().unwrap();+ let mut prev = PREVIOUS_FRONTMOST_APP.lock().unwrap_or_else(|e| e.into_inner());let p = *prev;*prev = 0;p@@ -666,7 +666,7 @@ impl ShowRewindWindow {// No existing window for this mode — fall through to creation below// (record the mode so we know what was created)- *MAIN_CREATED_MODE.lock().unwrap() = overlay_mode.clone();+ *MAIN_CREATED_MODE.lock().unwrap_or_else(|e| e.into_inner()) = overlay_mode.clone();// === Other windows: standard show path ===} else if let Some(window) = id.get(app) {@@ -795,7 +795,7 @@ impl ShowRewindWindow {#[allow(unused_variables)] // used only on macOSlet show_in_recording = settings.show_overlay_in_screen_recording;// Record what mode we're creating so we can detect changes later- *MAIN_CREATED_MODE.lock().unwrap() = overlay_mode.clone();+ *MAIN_CREATED_MODE.lock().unwrap_or_else(|e| e.into_inner()) = overlay_mode.clone();let use_window_mode = overlay_mode == "window";if use_window_mode {@@ -1191,7 +1191,7 @@ impl ShowRewindWindow {{use objc::{msg_send, sel, sel_impl};let lbl = {- let mode = MAIN_CREATED_MODE.lock().unwrap().clone();+ let mode = MAIN_CREATED_MODE.lock().unwrap_or_else(|e| e.into_inner()).clone();main_label_for_mode(&mode).to_string()};if let Ok(panel) = app_clone.get_webview_panel(&lbl) {@@ -1218,7 +1218,7 @@ impl ShowRewindWindow {{let app2 = app.clone();let lbl = {- let mode = MAIN_CREATED_MODE.lock().unwrap().clone();+ let mode = MAIN_CREATED_MODE.lock().unwrap_or_else(|e| e.into_inner()).clone();main_label_for_mode(&mode).to_string()};let _ = app.run_on_main_thread(move || {@@ -1242,7 +1242,7 @@ impl ShowRewindWindow {{use objc::{msg_send, sel, sel_impl};let lbl = {- let mode = MAIN_CREATED_MODE.lock().unwrap().clone();+ let mode = MAIN_CREATED_MODE.lock().unwrap_or_else(|e| e.into_inner()).clone();main_label_for_mode(&mode).to_string()};if let Ok(panel) = app_clone.get_webview_panel(&lbl) {