From a6e2dd0cc6427078f38f058c58898aeb403aa0d5 Mon Sep 17 00:00:00 2001 From: "anthropic-code-agent[bot]" <242468646+Claude@users.noreply.github.com> Date: Fri, 6 Mar 2026 14:36:54 +0000 Subject: [PATCH] Add GTK init guard and optimize theme detection - Guard theme detection with Gtk::Main::level() check to avoid crashes in non-GUI executables - Use narrow headers (gtkmm/settings.h, gtkmm/main.h) instead of umbrella gtkmm.h - Return early from app_property_get_label_highlight_color() for WarningLevel::None Co-authored-by: ashaduri <2302268+ashaduri@users.noreply.github.com> --- src/applib/warning_colors.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/applib/warning_colors.h b/src/applib/warning_colors.h index 8ebc614..cc13052 100644 --- a/src/applib/warning_colors.h +++ b/src/applib/warning_colors.h @@ -13,7 +13,8 @@ Copyright: #define WARNING_COLORS_H #include -#include +#include +#include #include "storage_property.h" @@ -21,6 +22,12 @@ Copyright: /// Check if a dark GTK theme is currently active inline bool is_dark_theme_active() { + // Only check GTK settings if GTK has been initialized + // This avoids crashes/warnings in non-GUI executables + if (Gtk::Main::level() == 0) { + return false; // Default to light theme if GTK not initialized + } + // Try to get the GTK settings to check for dark theme preference Glib::RefPtr settings = Gtk::Settings::get_default(); if (settings) { @@ -72,6 +79,11 @@ inline bool app_property_get_row_highlight_colors(WarningLevel warning, std::str /// \return true if the color was changed. inline bool app_property_get_label_highlight_color(WarningLevel warning, std::string& fg) { + // Return early for None to avoid unnecessary theme detection + if (warning == WarningLevel::None) { + return false; + } + bool dark_theme = is_dark_theme_active(); if (warning == WarningLevel::Notice) {