Add launch crash detection with detailed error dialog, fix all warnings

Detect AppImages that crash immediately after spawning (within 1.5s) by
capturing stderr and using try_wait(). Show a full AlertDialog with a
plain-text explanation, scrollable error output, and a copy-to-clipboard
button. Covers Qt plugin errors, missing libraries, segfaults, permission
issues, and display connection failures.

Move launch operations to background threads in both the detail view and
context menu to avoid blocking the UI during the 1.5s crash detection
window.

Suppress all 57 compiler warnings across future-use modules (backup,
notification, report, watcher) and individual unused fields/variants in
other core modules.
This commit is contained in:
lashman
2026-02-27 20:23:10 +02:00
parent c9c9c0341b
commit d493516efa
16 changed files with 324 additions and 70 deletions

View File

@@ -1,4 +1,4 @@
use gtk::prelude::*;
use adw::prelude::*;
use std::sync::OnceLock;
/// Ensures the shared letter-icon CSS provider is registered on the default
@@ -194,6 +194,141 @@ pub fn copy_button(text_to_copy: &str, toast_overlay: Option<&adw::ToastOverlay>
btn
}
/// Show a detailed crash dialog when an AppImage fails to start.
/// Includes a plain-text explanation, the full error output in a copyable text view,
/// and a button to copy the full error to clipboard.
pub fn show_crash_dialog(
parent: &impl gtk::prelude::IsA<gtk::Widget>,
app_name: &str,
exit_code: Option<i32>,
stderr: &str,
) {
let explanation = crash_explanation(stderr);
let exit_str = exit_code
.map(|c| c.to_string())
.unwrap_or_else(|| "unknown".to_string());
let body = format!("{}\n\nExit code: {}", explanation, exit_str);
let dialog = adw::AlertDialog::builder()
.heading(&format!("{} failed to start", app_name))
.body(&body)
.close_response("close")
.default_response("close")
.build();
// Build the full text that gets copied
let full_error = format!(
"App: {}\nExit code: {}\n\n{}\n\nError output:\n{}",
app_name,
exit_str,
explanation,
stderr.trim(),
);
// Extra content: scrollable text view with full stderr + copy button
if !stderr.trim().is_empty() {
let vbox = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.spacing(8)
.build();
let heading = gtk::Label::builder()
.label("Error output:")
.xalign(0.0)
.build();
heading.add_css_class("heading");
vbox.append(&heading);
let text_view = gtk::TextView::builder()
.editable(false)
.cursor_visible(false)
.monospace(true)
.wrap_mode(gtk::WrapMode::WordChar)
.top_margin(8)
.bottom_margin(8)
.left_margin(8)
.right_margin(8)
.build();
text_view.buffer().set_text(stderr.trim());
text_view.add_css_class("card");
let scrolled = gtk::ScrolledWindow::builder()
.child(&text_view)
.min_content_height(120)
.max_content_height(300)
.build();
vbox.append(&scrolled);
let copy_btn = gtk::Button::builder()
.label("Copy to clipboard")
.halign(gtk::Align::Start)
.build();
copy_btn.add_css_class("pill");
let full_error_copy = full_error.clone();
copy_btn.connect_clicked(move |btn| {
let clipboard = btn.display().clipboard();
clipboard.set_text(&full_error_copy);
btn.set_label("Copied!");
btn.set_sensitive(false);
});
vbox.append(&copy_btn);
dialog.set_extra_child(Some(&vbox));
}
dialog.add_response("close", "Close");
dialog.present(Some(parent));
}
/// Generate a plain-text explanation of why an app crashed based on stderr patterns.
fn crash_explanation(stderr: &str) -> String {
if stderr.contains("Could not find the Qt platform plugin") || stderr.contains("qt.qpa.plugin") {
return "The app couldn't find a required display plugin. This usually means \
it needs a Qt library that isn't bundled inside the AppImage or \
available on your system.".to_string();
}
if stderr.contains("cannot open shared object file") {
if let Some(pos) = stderr.find("cannot open shared object file") {
let before = &stderr[..pos];
if let Some(start) = before.rfind(": ") {
let lib = before[start + 2..].trim();
if !lib.is_empty() {
return format!(
"The app needs a system library ({}) that isn't installed. \
You may be able to fix this by installing the missing package.",
lib,
);
}
}
}
return "The app needs a system library that isn't installed on your system.".to_string();
}
if stderr.contains("Segmentation fault") || stderr.contains("SIGSEGV") {
return "The app crashed due to a memory error. This is usually a bug \
in the app itself, not something you can fix.".to_string();
}
if stderr.contains("Permission denied") {
return "The app was blocked from accessing something it needs. \
Check that the AppImage file has the right permissions.".to_string();
}
if stderr.contains("fatal IO error") || stderr.contains("display connection") {
return "The app lost its connection to the display server. This can happen \
with apps that don't fully support your display system.".to_string();
}
if stderr.contains("FATAL:") || stderr.contains("Aborted") {
return "The app hit a fatal error and had to stop. The error details \
below may help identify the cause.".to_string();
}
if stderr.contains("Failed to initialize") {
return "The app couldn't set itself up properly. It may need additional \
system components to run.".to_string();
}
"The app exited immediately after starting. The error details below \
may help identify the cause.".to_string()
}
/// Create a screen-reader live region announcement.
/// Inserts a hidden label with AccessibleRole::Alert into the given container,
/// which causes AT-SPI to announce the text to screen readers.