summaryrefslogtreecommitdiffstats
path: root/macosx/HBUtilities.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2019-06-08 17:46:01 +0200
committerDamiano Galassi <[email protected]>2019-06-08 17:46:01 +0200
commit727dc9879454c0aea3b2cf4aecbd54d95d8ae45b (patch)
treedcb787647dde0e6a520e8c834021eceba95999ad /macosx/HBUtilities.m
parentfd2c883de4cea7094c08fed7ea22418ec3472281 (diff)
MacGui: fix queue sleep and shutdown on 10.14 and under sandbox.
Diffstat (limited to 'macosx/HBUtilities.m')
-rw-r--r--macosx/HBUtilities.m48
1 files changed, 48 insertions, 0 deletions
diff --git a/macosx/HBUtilities.m b/macosx/HBUtilities.m
index 7e95f007a..9a627bf5a 100644
--- a/macosx/HBUtilities.m
+++ b/macosx/HBUtilities.m
@@ -383,4 +383,52 @@ static NSDateFormatter *_releaseDateFormatter = nil;
return @"Unknown";
}
+#if __MAC_OS_X_VERSION_MIN_REQUIRED <= __MAC_10_14
+enum {
+ errAEEventWouldRequireUserConsent = -1744,
+};
+#endif
+
++ (HBPrivacyConsentState)determinePermissionToAutomateTarget:(NSString *)bundleIdentifier promptIfNeeded:(BOOL)promptIfNeeded
+{
+ if (@available(macOS 10.14, *))
+ {
+ const char *identifierCString = bundleIdentifier.UTF8String;
+ AEAddressDesc addressDesc;
+ OSErr descResult = AECreateDesc(typeApplicationBundleID, identifierCString, strlen(identifierCString), &addressDesc);
+
+ if (descResult == noErr)
+ {
+ OSStatus permission = AEDeterminePermissionToAutomateTarget(&addressDesc, typeWildCard, typeWildCard, promptIfNeeded);
+ AEDisposeDesc(&addressDesc);
+
+ HBPrivacyConsentState result;
+
+ switch (permission)
+ {
+ case errAEEventWouldRequireUserConsent:
+ [HBUtilities writeToActivityLog:"Request user consent for %s.", bundleIdentifier.UTF8String];
+ result = HBPrivacyConsentStateUnknown;
+ break;
+ case noErr:
+ [HBUtilities writeToActivityLog:"Permission granted for %s.", bundleIdentifier.UTF8String];
+ result = HBPrivacyConsentStateGranted;
+ break;
+ case errAEEventNotPermitted:
+ [HBUtilities writeToActivityLog:"Permission not granted for %s.", bundleIdentifier.UTF8String];
+ result = HBPrivacyConsentStateDenied;
+ break;
+ case procNotFound:
+ default:
+ [HBUtilities writeToActivityLog:"Permission unknown."];
+ result = HBPrivacyConsentStateUnknown;
+ break;
+ }
+ return result;
+ }
+ }
+
+ return HBPrivacyConsentStateGranted;
+}
+
@end