diff --git a/Auto Dark/Info.plist b/Auto Dark/Info.plist index f3644da..03f6c53 100644 --- a/Auto Dark/Info.plist +++ b/Auto Dark/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.3 CFBundleVersion - 6 + 7 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement diff --git a/Auto Dark/LocationManager.swift b/Auto Dark/LocationManager.swift index 921bc87..a9cdd79 100644 --- a/Auto Dark/LocationManager.swift +++ b/Auto Dark/LocationManager.swift @@ -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 @@ -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.") } diff --git a/Auto Dark/ViewController.swift b/Auto Dark/ViewController.swift index b89f9a6..16d1621 100644 --- a/Auto Dark/ViewController.swift +++ b/Auto Dark/ViewController.swift @@ -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)! } @@ -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)