From 9a2b4f6256c65e8b3a2cb9fca0e76182a13c25b2 Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Mon, 8 Dec 2025 17:31:26 +0200 Subject: [PATCH] fix(UI): ensure GTK calls are executed on the main thread to prevent segfaults --- .../src-tauri/src/portmaster/commands.rs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/desktop/tauri/src-tauri/src/portmaster/commands.rs b/desktop/tauri/src-tauri/src/portmaster/commands.rs index 39c05788..fcad32ed 100644 --- a/desktop/tauri/src-tauri/src/portmaster/commands.rs +++ b/desktop/tauri/src-tauri/src/portmaster/commands.rs @@ -91,14 +91,19 @@ pub fn get_app_info( } let cloned = id.clone(); - std::thread::spawn(move || match crate::xdg::get_app_info(info) { - Ok(info) => window.emit(&id, info), - Err(err) => window.emit( - &id, - Error { - error: err.to_string(), - }, - ), + // GTK calls are not thread-safe and must run on the main thread. + // Schedule the work on the GTK/GLib main thread to avoid random segfaults. + glib::idle_add_local(move || { + let _ = match crate::xdg::get_app_info(info.clone()) { + Ok(info) => window.emit(&id, info), + Err(err) => window.emit( + &id, + Error { + error: err.to_string(), + }, + ), + }; + glib::ControlFlow::Break }); Ok(cloned)