diff --git a/Assets/MenuScreenshot.png b/Assets/MenuScreenshot.png deleted file mode 100644 index 8da1682..0000000 Binary files a/Assets/MenuScreenshot.png and /dev/null differ diff --git a/Assets/Screenshot.png b/Assets/Screenshot.png new file mode 100644 index 0000000..74773ef Binary files /dev/null and b/Assets/Screenshot.png differ diff --git a/Auto Dark.xcodeproj/project.pbxproj b/Auto Dark.xcodeproj/project.pbxproj index 1a7a72f..24b3433 100644 --- a/Auto Dark.xcodeproj/project.pbxproj +++ b/Auto Dark.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 908230AF21F1FBB600FA2D36 /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = ""; }; 908230B121F20F6600FA2D36 /* PreferencesController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesController.swift; sourceTree = ""; }; 90D19C2321F35FF9001C410D /* ScheduleManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleManager.swift; sourceTree = ""; }; + 90FB494F22022444000D6510 /* LICENSE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -48,6 +49,7 @@ isa = PBXGroup; children = ( 905E4A8C21A31BCD00D1DBC7 /* README.md */, + 90FB494F22022444000D6510 /* LICENSE.md */, 905E4A7721A19E2500D1DBC7 /* Auto Dark */, 905E4A7621A19E2500D1DBC7 /* Products */, ); diff --git a/Auto Dark/AppDelegate.swift b/Auto Dark/AppDelegate.swift index 274eb11..e391b3b 100644 --- a/Auto Dark/AppDelegate.swift +++ b/Auto Dark/AppDelegate.swift @@ -32,11 +32,10 @@ var mode = ScheduleMode.location class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! - + func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application - if !UserDefaults.standard.contains(key: "new") { - UserDefaults.standard.set(true, forKey: "new") + if !UserDefaults.standard.contains(key: "mode") { UserDefaults.standard.set("Location", forKey: "mode") UserDefaults.standard.set("7:00", forKey: "sunrise") UserDefaults.standard.set("19:00", forKey: "sunset") diff --git a/Auto Dark/Info.plist b/Auto Dark/Info.plist index e7e83c5..f3644da 100644 --- a/Auto Dark/Info.plist +++ b/Auto Dark/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.3 CFBundleVersion - 5 + 6 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement diff --git a/Auto Dark/LocationManager.swift b/Auto Dark/LocationManager.swift index 6c342e2..921bc87 100644 --- a/Auto Dark/LocationManager.swift +++ b/Auto Dark/LocationManager.swift @@ -5,6 +5,24 @@ // Created by Matan Mashraki on 18/01/2019. // Copyright © 2019 Matan Mashraki. All rights reserved. // +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the “Software”), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// import Cocoa import CoreLocation @@ -51,15 +69,7 @@ class LocationManager: NSObject, CLLocationManagerDelegate, DarkManager { if pref == .location, CLLocationManager.locationServicesEnabled() { locationManager.startUpdatingLocation() } else { - let res = showAlert(title: "Location Services Aren't Available", subtitle: "Please turn on location services or set location manually.", button1: "I Enabled Location Services", button2: "Set Location Manually") - if res == .alertFirstButtonReturn { - determineCurrentLocation() - } else if res == .alertSecondButtonReturn { - pref = .manual - setManualLocation() - } else { - NSApplication.shared.terminate(self) - } + self.delegate?.setInformationLabel(string: "Authorize Auto Dark to detect your location in System Preferences.") } } } @@ -74,7 +84,7 @@ class LocationManager: NSObject, CLLocationManagerDelegate, DarkManager { self.calculateNextDate() self.delegate?.setLocationLabel(string: location) } else { - self.delegate?.setInformationLabel(string: "Can't calculate Dark Mode for your location.") + self.presentError(error: error as? CLError) } } } @@ -89,26 +99,28 @@ class LocationManager: NSObject, CLLocationManagerDelegate, DarkManager { self.delegate?.setLocationLabel(string: self.stringLocation!) self.calculateNextDate() } else { - self.delegate?.setInformationLabel(string: "Can't calculate Dark Mode for your location.") + self.delegate?.setLocationLabel(string: "Auto Dark") } } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { - print("Error Location: \(error)") - self.delegate?.setInformationLabel(string: "Can't detect your location.") + if currentLocation == nil { + presentError(error: error as? CLError) + } } - func showAlert(title: String, subtitle: String, button1: String, button2: String?) -> NSApplication.ModalResponse { - let msg = NSAlert() - msg.addButton(withTitle: button1) - if let b2 = button2 { - msg.addButton(withTitle: b2) + func presentError(error: CLError?) { + if let err = error { + var message = "" + switch err.code.rawValue { + case 0, 2: message = "There's no internet connection." + case 1: message = "Authorize Auto Dark to detect your location in System Preferences." + default: message = "Auto Dark can't detect your location" + } + self.delegate?.setLocationLabel(string: "Auto Dark") + self.delegate?.setInformationLabel(string: message) } - msg.addButton(withTitle: "Cancel") - msg.messageText = title - msg.informativeText = subtitle - return msg.runModal() } } diff --git a/Auto Dark/Preferences.storyboard b/Auto Dark/Preferences.storyboard index 5563ada..7735ec6 100644 --- a/Auto Dark/Preferences.storyboard +++ b/Auto Dark/Preferences.storyboard @@ -81,7 +81,7 @@