Remember Night Mode preference
This commit is contained in:
parent
f9ff961e9e
commit
71a7fa47eb
@ -13,8 +13,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
|
|
||||||
var vc: ViewController?
|
var vc: ViewController?
|
||||||
|
|
||||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
@IBOutlet weak var nightModeItem: NSMenuItem!
|
||||||
// Insert code here to initialize your application
|
|
||||||
|
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) {
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
@ -31,6 +36,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
let isOff = sender.state == NSOffState
|
let isOff = sender.state == NSOffState
|
||||||
vc?.toggle(isNight: isOff)
|
vc?.toggle(isNight: isOff)
|
||||||
sender.state = isOff ? NSOnState : NSOffState
|
sender.state = isOff ? NSOnState : NSOffState
|
||||||
|
UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state")
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func saveDocument(_ sender: AnyObject) {
|
@IBAction func saveDocument(_ sender: AnyObject) {
|
||||||
|
@ -281,7 +281,11 @@
|
|||||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
|
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
|
||||||
</connections>
|
</connections>
|
||||||
</application>
|
</application>
|
||||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Write_as" customModuleProvider="target"/>
|
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Write_as" customModuleProvider="target">
|
||||||
|
<connections>
|
||||||
|
<outlet property="nightModeItem" destination="jYO-0u-qN9" id="8xF-SV-B70"/>
|
||||||
|
</connections>
|
||||||
|
</customObject>
|
||||||
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
<point key="canvasLocation" x="67" y="-252"/>
|
<point key="canvasLocation" x="67" y="-252"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user