The Write.as desktop (GUI) app for macOS.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

  1. //
  2. // AppDelegate.swift
  3. // writeas
  4. //
  5. // Created by Matt Baer on 12/29/15.
  6. // Copyright © 2015 A Bunch Tell. All rights reserved.
  7. //
  8. import Cocoa
  9. @NSApplicationMain
  10. class AppDelegate: NSObject, NSApplicationDelegate {
  11. var vc: ViewController?
  12. @IBOutlet weak var nightModeItem: NSMenuItem!
  13. func applicationDidFinishLaunching(_ aNotification: Notification) {
  14. nightModeItem.state = Int(UserDefaults.standard.string(forKey: "night_mode_state") ?? String(NSOffState))!
  15. if nightModeItem.state == NSOnState {
  16. vc?.toggle(isNight: true)
  17. }
  18. }
  19. func applicationWillTerminate(_ aNotification: Notification) {
  20. // Insert code here to tear down your application
  21. }
  22. func applicationDidBecomeActive(_ notification: Notification) {
  23. if vc == nil {
  24. vc = NSApplication.shared().mainWindow?.contentViewController as! ViewController
  25. }
  26. }
  27. @IBAction func toggleNightMode(_ sender: NSMenuItem) {
  28. let isOff = sender.state == NSOffState
  29. vc?.toggle(isNight: isOff)
  30. sender.state = isOff ? NSOnState : NSOffState
  31. UserDefaults.standard.set(String(sender.state), forKey: "night_mode_state")
  32. }
  33. @IBAction func saveDocument(_ sender: AnyObject) {
  34. vc?.saveDocument()
  35. }
  36. }