forked from ZekeSnider/Jared
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ZekeSnider#40 from ZekeSnider/zeke.better-ui-permi…
…ssioning Improve UI permissioning
- Loading branch information
Showing
18 changed files
with
733 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// AutomationPermissionState.swift | ||
// Jared | ||
// | ||
// Created by Zeke Snider on 8/16/20. | ||
// Copyright © 2020 Zeke Snider. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum AutomationPermissionState: Int { | ||
case declined | ||
case authorized | ||
case notDetermined | ||
case notRunning | ||
case unknown | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// JaredConstants.swift | ||
// Jared | ||
// | ||
// Created by Zeke Snider on 8/16/20. | ||
// Copyright © 2020 Zeke Snider. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct JaredConstants { | ||
static let restApiIsDisabled = "RestApiIsDisabled" | ||
static let jaredIsDisabled = "JaredIsDisabled" | ||
static let contactsAccess = "ContactsAccess" | ||
static let sendMessageAccess = "SendMessageAccess" | ||
static let fullDiskAccess = "FullDiskAccess" | ||
static let fullDiskAcccessUrl = "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles" | ||
static let contactsAccessUrl = "x-apple.systempreferences:com.apple.preference.security?Privacy_Contacts" | ||
static let automationAccessUrl = "x-apple.systempreferences:com.apple.preference.security?Privacy_Automation" | ||
static let messagesUrl = "messages://" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// PermissionsHelper.swift | ||
// Jared | ||
// | ||
// Created by Zeke Snider on 8/16/20. | ||
// Copyright © 2020 Zeke Snider. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Contacts | ||
|
||
class PermissionsHelper { | ||
static func requestMessageAutomation() { | ||
let _ = canSendMessages(shouldPrompt: true) | ||
} | ||
|
||
static func canSendMessages(shouldPrompt: Bool = false) -> AutomationPermissionState { | ||
let target = NSAppleEventDescriptor(bundleIdentifier: "com.apple.iChat") | ||
if #available(OSX 10.14, *) { | ||
let permission = AEDeterminePermissionToAutomateTarget(target.aeDesc, typeWildCard, typeWildCard, shouldPrompt) | ||
var permissionEnum: AutomationPermissionState | ||
switch (permission) { | ||
case -1743: | ||
permissionEnum = .declined | ||
case -1744: | ||
permissionEnum = .notDetermined | ||
case 0: | ||
permissionEnum = .authorized | ||
case -600: | ||
permissionEnum = .notRunning | ||
default: | ||
permissionEnum = .unknown | ||
} | ||
|
||
UserDefaults.standard.set(permissionEnum.rawValue, forKey: JaredConstants.sendMessageAccess) | ||
return permissionEnum | ||
} else { | ||
UserDefaults.standard.set(AutomationPermissionState.authorized.rawValue, forKey: JaredConstants.sendMessageAccess) | ||
return .authorized | ||
} | ||
} | ||
|
||
static func getContactsStatus() -> CNAuthorizationStatus { | ||
let status = CNContactStore.authorizationStatus(for: CNEntityType.contacts) | ||
UserDefaults.standard.set(status.rawValue, forKey: JaredConstants.contactsAccess) | ||
return status | ||
} | ||
|
||
static func requestContactsAccess() { | ||
if(CNContactStore.authorizationStatus(for: CNEntityType.contacts) == .notDetermined) { | ||
CNContactStore().requestAccess(for: CNEntityType.contacts, completionHandler: {enabled, _ in | ||
let _ = getContactsStatus() | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.