@@ -261,7 +261,9 @@ fn daemon() -> Rc<dyn Daemon> {
261
261
262
262
#[ cfg( target_os = "macos" ) ]
263
263
fn macos_init ( ) {
264
+ use gtk:: SettingsExt ;
264
265
use std:: { env, process} ;
266
+ let mut prefer_dark = false ;
265
267
// This command returns Dark if we should use the dark theme
266
268
// defaults read -g AppleInterfaceStyle
267
269
if let Ok ( output) = process:: Command :: new ( "defaults" )
@@ -270,37 +272,42 @@ fn macos_init() {
270
272
. arg ( "AppleInterfaceStyle" )
271
273
. output ( )
272
274
{
273
- if output. stdout . starts_with ( b"Dark" ) {
274
- let _ = env:: set_var ( "GTK_THEME" , "Adwaita:dark" ) ;
275
- }
275
+ prefer_dark = output. stdout . starts_with ( b"Dark" ) ;
276
+ }
277
+
278
+ if let Some ( settings) = gtk:: Settings :: get_default ( ) {
279
+ settings. set_property_gtk_application_prefer_dark_theme ( prefer_dark) ;
276
280
}
277
281
}
278
282
279
283
#[ cfg( target_os = "windows" ) ]
280
284
fn windows_init ( ) {
281
- use std:: env;
282
285
// This is a dword with a value of 0 if we should use the dark theme:
283
286
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme
287
+ use gtk:: SettingsExt ;
284
288
use winreg:: RegKey ;
289
+ let mut prefer_dark = false ;
285
290
let hkcu = RegKey :: predef ( winreg:: enums:: HKEY_CURRENT_USER ) ;
286
291
if let Ok ( subkey) = hkcu. open_subkey ( "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Themes\\ Personalize" ) {
287
292
if let Ok ( dword) = subkey. get_value :: < u32 , _ > ( "AppsUseLightTheme" ) {
288
- if dword == 0 {
289
- let _ = env:: set_var ( "GTK_THEME" , "Adwaita:dark" ) ;
290
- }
293
+ prefer_dark = ( dword == 0 ) ;
291
294
}
292
295
}
296
+
297
+ if let Some ( settings) = gtk:: Settings :: get_default ( ) {
298
+ settings. set_property_gtk_application_prefer_dark_theme ( prefer_dark) ;
299
+ }
293
300
}
294
301
295
302
pub fn run ( args : Vec < String > ) -> i32 {
303
+ gtk:: init ( ) . unwrap ( ) ;
304
+
296
305
#[ cfg( target_os = "macos" ) ]
297
306
macos_init ( ) ;
298
307
299
308
#[ cfg( target_os = "windows" ) ]
300
309
windows_init ( ) ;
301
310
302
- gtk:: init ( ) . unwrap ( ) ;
303
-
304
311
let application = ConfiguratorApp :: new ( ) ;
305
312
application. run ( & args)
306
313
}
0 commit comments