Skip to content

Commit

Permalink
Fixed Dark Mode not changing when Mac's on sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
planecore committed Feb 2, 2019
1 parent f23c7af commit b0827d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Auto Dark/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.3</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>7</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
6 changes: 3 additions & 3 deletions Auto Dark/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import CoreLocation

class LocationManager: NSObject, CLLocationManagerDelegate, DarkManager {

private var locationManager: CLLocationManager!
var locationManager: CLLocationManager!
var delegate: ViewControllerDelegate?
var next: DarkDate?
var pref: ScheduleMode
Expand Down Expand Up @@ -64,10 +64,10 @@ class LocationManager: NSObject, CLLocationManagerDelegate, DarkManager {
} else {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
locationManager.requestLocation()
if pref == .location, CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
locationManager.startMonitoringSignificantLocationChanges()
} else {
self.delegate?.setInformationLabel(string: "Authorize Auto Dark to detect your location in System Preferences.")
}
Expand Down
5 changes: 5 additions & 0 deletions Auto Dark/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class ViewController: NSObject, ViewControllerDelegate {

func setDarkManager() {
timer?.invalidate()
if let manager = darkManager as? LocationManager, manager.locationManager != nil {
manager.locationManager.stopMonitoringSignificantLocationChanges()
}
if let stringMode = UserDefaults.standard.string(forKey: "mode") {
mode = ScheduleMode(rawValue: stringMode)!
}
Expand All @@ -125,6 +128,8 @@ class ViewController: NSObject, ViewControllerDelegate {
if let date = self.date?.date, Date() > date {
DarkMode.toggle(force: self.date!.dark)
self.darkManager?.calculateNextDate()
} else if self.date?.dark == DarkMode.isEnabled {
DarkMode.toggle(force: !self.date!.dark)
}
}
RunLoop.main.add(timer!, forMode: .common)
Expand Down

0 comments on commit b0827d7

Please sign in to comment.