qrcode: fix for dark mode

Use white background for qrcode, when in dark mode.

Change-Id: I22f09ee00b3764ab10a259499c702c5e7f1be52f
diff --git a/src/RingWindowController.mm b/src/RingWindowController.mm
index 8e0fbc1..df2199d 100644
--- a/src/RingWindowController.mm
+++ b/src/RingWindowController.mm
@@ -98,10 +98,16 @@
         self.behaviorController = behaviorController;
         self.avModel = avModel;
         self.avModel->useAVFrame(YES);
+        [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
     }
     return self;
 }
 
+-(void) deinit {
+    [NSDistributedNotificationCenter.defaultCenter removeObserver:self];
+
+}
+
 - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
 {
     return (NSApplicationPresentationFullScreen |
@@ -171,6 +177,7 @@
 - (void)windowDidLoad {
     [super windowDidLoad];
     [self.window setMovableByWindowBackground:YES];
+    [qrcodeView setWantsLayer: YES];
 
     self.window.titleVisibility = NSWindowTitleHidden;
     self.window.titlebarAppearsTransparent = true;
@@ -467,6 +474,7 @@
  */
 - (void) showQRCode:(BOOL) show
 {
+    [self updateQRCodeBackground];
     static const NSInteger offset = 110;
     [NSAnimationContext beginGrouping];
     NSAnimationContext.currentContext.duration = 0.5;
@@ -477,6 +485,23 @@
     [NSAnimationContext endGrouping];
 }
 
+-(void)themeChanged:(NSNotification *) notification {
+    if (qrcodeView.animator.alphaValue == 1) {
+        [self updateQRCodeBackground];
+    }
+}
+
+-(void)updateQRCodeBackground {
+    if (@available(*, macOS 10.14)) {
+        NSString *interfaceStyle = [NSUserDefaults.standardUserDefaults valueForKey:@"AppleInterfaceStyle"];
+        if ([interfaceStyle isEqualToString:@"Dark"]) {
+            qrcodeView.layer.backgroundColor = [[NSColor whiteColor] CGColor];
+        } else {
+            qrcodeView.layer.backgroundColor = [[NSColor clearColor] CGColor];
+        }
+    }
+}
+
 - (IBAction)openPreferences:(id)sender
 {
     if (preferencesWC) {