fix(UI): ensure GTK calls are executed on the main thread to prevent segfaults

This commit is contained in:
Alexandr Stelnykovych
2025-12-08 17:31:26 +02:00
parent 9af071ef17
commit 9a2b4f6256

View File

@@ -91,14 +91,19 @@ pub fn get_app_info<R: Runtime>(
} }
let cloned = id.clone(); let cloned = id.clone();
std::thread::spawn(move || match crate::xdg::get_app_info(info) { // GTK calls are not thread-safe and must run on the main thread.
Ok(info) => window.emit(&id, info), // Schedule the work on the GTK/GLib main thread to avoid random segfaults.
Err(err) => window.emit( glib::idle_add_local(move || {
&id, let _ = match crate::xdg::get_app_info(info.clone()) {
Error { Ok(info) => window.emit(&id, info),
error: err.to_string(), Err(err) => window.emit(
}, &id,
), Error {
error: err.to_string(),
},
),
};
glib::ControlFlow::Break
}); });
Ok(cloned) Ok(cloned)