Browse Source

Merge branch 'master' of https://github.com/n0shake/Clocker

pull/92/head
Abhishek 6 years ago
parent
commit
5e10f04687
  1. 4
      Clocker/Clocker.xcodeproj/project.pbxproj
  2. 27
      Clocker/Preferences/General/PreferencesViewController.swift
  3. 34
      Clocker/Preferences/StartupManager.swift

4
Clocker/Clocker.xcodeproj/project.pbxproj

@ -103,6 +103,7 @@
9A7547DC1F184DC3004705EF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9A7547DB1F184DC3004705EF /* Assets.xcassets */; }; 9A7547DC1F184DC3004705EF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9A7547DB1F184DC3004705EF /* Assets.xcassets */; };
9A7547DF1F184DC3004705EF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A7547DD1F184DC3004705EF /* Main.storyboard */; }; 9A7547DF1F184DC3004705EF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A7547DD1F184DC3004705EF /* Main.storyboard */; };
9A7547E51F184E3F004705EF /* ClockerHelper.app in Login Item Helper */ = {isa = PBXBuildFile; fileRef = 9A7547D01F184DC3004705EF /* ClockerHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 9A7547E51F184E3F004705EF /* ClockerHelper.app in Login Item Helper */ = {isa = PBXBuildFile; fileRef = 9A7547D01F184DC3004705EF /* ClockerHelper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
9A7CDC1B22BEC2170035902D /* StartupManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A7CDC1A22BEC2170035902D /* StartupManager.swift */; };
9A8605AE1BEC148400A810A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A8605AD1BEC148400A810A4 /* main.m */; }; 9A8605AE1BEC148400A810A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A8605AD1BEC148400A810A4 /* main.m */; };
9A9E87621C1FEDB500A7A2DF /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A9E87611C1FEDB500A7A2DF /* CFNetwork.framework */; }; 9A9E87621C1FEDB500A7A2DF /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A9E87611C1FEDB500A7A2DF /* CFNetwork.framework */; };
9A9E876A1C1FEDDB00A7A2DF /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A9E87691C1FEDDB00A7A2DF /* SystemConfiguration.framework */; }; 9A9E876A1C1FEDDB00A7A2DF /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A9E87691C1FEDDB00A7A2DF /* SystemConfiguration.framework */; };
@ -313,6 +314,7 @@
9A7547DB1F184DC3004705EF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 9A7547DB1F184DC3004705EF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
9A7547DE1F184DC3004705EF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; 9A7547DE1F184DC3004705EF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
9A7547E01F184DC3004705EF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9A7547E01F184DC3004705EF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9A7CDC1A22BEC2170035902D /* StartupManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartupManager.swift; sourceTree = "<group>"; };
9A8605AD1BEC148400A810A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Clocker/main.m; sourceTree = "<group>"; }; 9A8605AD1BEC148400A810A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Clocker/main.m; sourceTree = "<group>"; };
9A8605C31BEC155B00A810A4 /* Clocker-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Clocker-Info.plist"; path = "Clocker/Clocker-Info.plist"; sourceTree = "<group>"; }; 9A8605C31BEC155B00A810A4 /* Clocker-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Clocker-Info.plist"; path = "Clocker/Clocker-Info.plist"; sourceTree = "<group>"; };
9A8605CC1BEC155B00A810A4 /* Clocker-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Clocker-Prefix.pch"; path = "Clocker/Clocker-Prefix.pch"; sourceTree = "<group>"; }; 9A8605CC1BEC155B00A810A4 /* Clocker-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Clocker-Prefix.pch"; path = "Clocker/Clocker-Prefix.pch"; sourceTree = "<group>"; };
@ -472,6 +474,7 @@
35C36F1E22596253002FA5C6 /* OneWindowController.swift */, 35C36F1E22596253002FA5C6 /* OneWindowController.swift */,
9AB6F1632259D1B800A44663 /* ParentViewController.swift */, 9AB6F1632259D1B800A44663 /* ParentViewController.swift */,
35C36F902259EAF4002FA5C6 /* Preferences.storyboard */, 35C36F902259EAF4002FA5C6 /* Preferences.storyboard */,
9A7CDC1A22BEC2170035902D /* StartupManager.swift */,
); );
path = Preferences; path = Preferences;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1171,6 +1174,7 @@
35C36F5A2259DD8A002FA5C6 /* Panelr.swift in Sources */, 35C36F5A2259DD8A002FA5C6 /* Panelr.swift in Sources */,
35C36F712259E185002FA5C6 /* NoTimezoneView.swift in Sources */, 35C36F712259E185002FA5C6 /* NoTimezoneView.swift in Sources */,
35C36F2B2259D6FA002FA5C6 /* ParentPanelController.swift in Sources */, 35C36F2B2259D6FA002FA5C6 /* ParentPanelController.swift in Sources */,
9A7CDC1B22BEC2170035902D /* StartupManager.swift in Sources */,
35C36F582259DD8A002FA5C6 /* PanelTableView.swift in Sources */, 35C36F582259DD8A002FA5C6 /* PanelTableView.swift in Sources */,
35C36F0F225961DA002FA5C6 /* TimePeriodCollection.swift in Sources */, 35C36F0F225961DA002FA5C6 /* TimePeriodCollection.swift in Sources */,
35C36F18225961DA002FA5C6 /* Date+Comparators.swift in Sources */, 35C36F18225961DA002FA5C6 /* Date+Comparators.swift in Sources */,

27
Clocker/Preferences/General/PreferencesViewController.swift

@ -1,7 +1,6 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
import Cocoa import Cocoa
import ServiceManagement
struct PreferencesConstants { struct PreferencesConstants {
static let timezoneNameIdentifier = "formattedAddress" static let timezoneNameIdentifier = "formattedAddress"
@ -30,6 +29,7 @@ class PreferencesViewController: ParentViewController {
return DataStore.shared().timezones() return DataStore.shared().timezones()
} }
private lazy var startupManager = StartupManager()
private var filteredArray: [Any] = [] private var filteredArray: [Any] = []
private var timezoneArray: [String] = [] private var timezoneArray: [String] = []
private var timezoneFilteredArray: [String] = [] private var timezoneFilteredArray: [String] = []
@ -1028,30 +1028,7 @@ extension PreferencesViewController {
extension PreferencesViewController { extension PreferencesViewController {
@IBAction func loginPreferenceChanged(_ sender: NSButton) { @IBAction func loginPreferenceChanged(_ sender: NSButton) {
if !SMLoginItemSetEnabled("com.abhishek.ClockerHelper" as CFString, sender.state == .on) { startupManager.toggleLogin(sender)
Logger.log(object: ["Successful": "NO"], for: "Start Clocker Login")
addClockerToLoginItemsManually()
} else {
Logger.log(object: ["Successful": "YES"], for: "Start Clocker Login")
}
}
private func addClockerToLoginItemsManually() {
NSApplication.shared.activate(ignoringOtherApps: true)
let alert = NSAlert()
alert.messageText = "Clocker is unable to set to start at login. 😅"
alert.informativeText = "You can manually set it to start at startup by adding Clocker to your login items."
alert.addButton(withTitle: "Add Manually")
alert.addButton(withTitle: "Cancel")
let response = alert.runModal()
if response.rawValue == 1000 {
OperationQueue.main.addOperation {
let prefPane = "/System/Library/PreferencePanes/Accounts.prefPane"
NSWorkspace.shared.openFile(prefPane)
}
}
} }
} }

34
Clocker/Preferences/StartupManager.swift

@ -0,0 +1,34 @@
// Copyright © 2015 Abhishek Banthia
import Cocoa
import ServiceManagement
struct StartupManager {
func toggleLogin(_ sender: NSButton) {
if !SMLoginItemSetEnabled("com.abhishek.ClockerHelper" as CFString, sender.state == .on) {
Logger.log(object: ["Successful": "NO"], for: "Start Clocker Login")
addClockerToLoginItemsManually()
} else {
Logger.log(object: ["Successful": "YES"], for: "Start Clocker Login")
}
}
private func addClockerToLoginItemsManually() {
NSApplication.shared.activate(ignoringOtherApps: true)
let alert = NSAlert()
alert.messageText = "Clocker is unable to set to start at login. 😅"
alert.informativeText = "You can manually set it to start at startup by adding Clocker to your login items."
alert.addButton(withTitle: "Add Manually")
alert.addButton(withTitle: "Cancel")
let response = alert.runModal()
if response.rawValue == 1000 {
OperationQueue.main.addOperation {
let prefPane = "/System/Library/PreferencePanes/Accounts.prefPane"
NSWorkspace.shared.openFile(prefPane)
}
}
}
}
Loading…
Cancel
Save