@@ -108,32 +108,48 @@ public class He.Desktop : GLib.Object {
108108 // Platform detection + macOS fallback helpers
109109 // -------------------------------------------------------------------------
110110
111+ private static int _is_macos_cache = - 1 ;
112+
111113 private static bool is_macos () {
112- Posix . utsname u;
113- if (Posix . uname (out u) != 0 ) {
114- return false ;
114+ if (_is_macos_cache != - 1 ) {
115+ return _is_macos_cache == 1 ;
115116 }
116- return u. sysname == " Darwin" ;
117+
118+ // Cheap, dependency-free heuristic that works for macOS builds.
119+ bool ok = GLib . FileUtils . test (
120+ " /usr/bin/defaults" ,
121+ GLib . FileTest . EXISTS
122+ ) &&
123+ GLib . FileUtils . test (
124+ " /System/Library/CoreServices" ,
125+ GLib . FileTest . EXISTS
126+ );
127+
128+ _is_macos_cache = ok ? 1 : 0 ;
129+ return ok;
117130 }
118131
119132 private static string ? macos_defaults_read (string domain , string key ) {
133+ // Use argv spawn (no shell, no quoting issues, no PATH dependency).
120134 string stdout_str;
121135 string stderr_str;
122136 int status;
123137
124- string cmd;
138+ string [] argv;
139+
125140 if (domain == " -g" || domain == " NSGlobalDomain" ) {
126- cmd = " defaults read -g %s " . printf ( GLib . Shell . quote ( key)) ;
141+ argv = { " /usr/bin/ defaults" , " read" , " -g " , key } ;
127142 } else {
128- cmd = " defaults read %s %s " . printf (
129- GLib . Shell . quote (domain),
130- GLib . Shell . quote (key)
131- );
143+ argv = { " /usr/bin/defaults" , " read" , domain, key };
132144 }
133145
134146 try {
135- GLib . Process . spawn_command_line_sync (
136- cmd,
147+ GLib . Process . spawn_sync (
148+ null ,
149+ argv,
150+ null ,
151+ GLib . SpawnFlags . STDERR_TO_DEV_NULL ,
152+ null ,
137153 out stdout_str,
138154 out stderr_str,
139155 out status
0 commit comments