From 71a7fa47eb12b4509a8c31d7f3c9d15f61a76c90 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 26 Jul 2017 19:36:35 -0400 Subject: [PATCH] Remember Night Mode preference --- writeas/AppDelegate.swift | 10 ++++++++-- writeas/Base.lproj/Main.storyboard | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/writeas/AppDelegate.swift b/writeas/AppDelegate.swift index 8e6fc95..49b2eef 100644 --- a/writeas/AppDelegate.swift +++ b/writeas/AppDelegate.swift @@ -13,8 +13,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { var vc: ViewController? - func applicationDidFinishLaunching(aNotification: NSNotification) { - // Insert code here to initialize your application + @IBOutlet weak var nightModeItem: NSMenuItem! + + func applicationDidFinishLaunching(_ aNotification: Notification) { + nightModeItem.state = Int(UserDefaults.standard.string(forKey: "night_mode_state") ?? String(NSOffState))! + if nightModeItem.state == NSOnState { + vc?.toggle(isNight: true) + } } func applicationWillTerminate(_ aNotification: Notification) { @@ -31,6 +36,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let isOff = sender.state == NSOffState vc?.toggle(isNight: isOff) sender.state = isOff ? NSOnState : NSOffState + UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state") } @IBAction func saveDocument(_ sender: AnyObject) { diff --git a/writeas/Base.lproj/Main.storyboard b/writeas/Base.lproj/Main.storyboard index ff74376..3ff0d6a 100644 --- a/writeas/Base.lproj/Main.storyboard +++ b/writeas/Base.lproj/Main.storyboard @@ -281,7 +281,11 @@ - + + + + +