@@ -47,10 +47,11 @@ - (void) awakeFromNib
4747 name: NSWindowDidEndLiveResizeNotification
4848 object: self .view.window];
4949
50- if (@available (macOS 10.14 , *)) {
51- [[NSApplication sharedApplication ] addObserver: self forKeyPath: @" effectiveAppearance" options: (NSKeyValueObservingOptions )0 context: PBEffectiveAppearanceContext];
52- }
53-
50+ [nc addObserver: self
51+ selector: @selector (effectiveAppearanceDidChange: )
52+ name: PBEffectiveAppearanceChanged
53+ object: nil ];
54+
5455 finishedLoading = NO ;
5556
5657 [self .view setDrawsBackground: NO ];
@@ -78,21 +79,10 @@ - (WebScriptObject *) script
7879 return self.view .windowScriptObject ;
7980}
8081
81- - (void ) setWebAppearance : ( NSAppearance *)appearance
82+ - (void )effectiveAppearanceDidChange : ( NSNotification *)notif
8283{
83- if (@available (macOS 10.14 , *)) {
84- if (appearance == nil ) {
85- appearance = [NSApplication sharedApplication ].effectiveAppearance ;
86- }
87-
88- NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames: @[NSAppearanceNameDarkAqua , NSAppearanceNameAqua ]];
89-
90- if ([appearanceName isEqualToString: NSAppearanceNameDarkAqua ]) {
91- [self .script callWebScriptMethod: @" setAppearance" withArguments: @[@" DARK" ]];
92- } else {
93- [self .script callWebScriptMethod: @" setAppearance" withArguments: @[@" LIGHT" ]];
94- }
95- }
84+ NSString *mode = [NSApp isDarkMode ] ? @" DARK" : @" LIGHT" ;
85+ [self .script callWebScriptMethod: @" setAppearance" withArguments: @[mode]];
9686}
9787
9888- (void )closeView
@@ -124,7 +114,7 @@ - (void) webView:(id) v didFinishLoadForFrame:(id) frame
124114 finishedLoading = YES ;
125115 if ([self respondsToSelector: @selector (didLoad )])
126116 [self performSelector: @selector (didLoad )];
127- [self setWebAppearance :nil ];
117+ [self effectiveAppearanceDidChange :nil ];
128118}
129119
130120- (void )webView : (WebView *)webView addMessageToConsole : (NSDictionary *)dictionary
0 commit comments