MacGui: fix queue sleep and shutdown on 10.14 and under sandbox.
This commit is contained in:
parent
fd2c883de4
commit
727dc98794
@ -1073,7 +1073,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext;
|
||||
// Sleep
|
||||
NSDictionary *errorDict;
|
||||
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:
|
||||
@"tell application \"Finder\" to sleep"];
|
||||
@"tell application \"System Events\" to sleep"];
|
||||
[scriptObject executeAndReturnError: &errorDict];
|
||||
}
|
||||
// If Shutdown has been selected
|
||||
@ -1081,7 +1081,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext;
|
||||
{
|
||||
// Shut Down
|
||||
NSDictionary *errorDict;
|
||||
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:@"tell application \"Finder\" to shut down"];
|
||||
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to shut down"];
|
||||
[scriptObject executeAndReturnError: &errorDict];
|
||||
}
|
||||
}
|
||||
@ -1219,6 +1219,8 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext;
|
||||
{
|
||||
[self.delegate showPreferencesWindow:nil];
|
||||
}
|
||||
|
||||
[self promptForAppleEventAuthorization];
|
||||
}
|
||||
else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"HBAlertWhenDone"] == HBDoneActionShutDown)
|
||||
{
|
||||
@ -1237,6 +1239,17 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext;
|
||||
{
|
||||
[self.delegate showPreferencesWindow:nil];
|
||||
}
|
||||
|
||||
[self promptForAppleEventAuthorization];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)promptForAppleEventAuthorization
|
||||
{
|
||||
HBPrivacyConsentState result = [HBUtilities determinePermissionToAutomateTarget:@"com.apple.systemevents" promptIfNeeded:YES];
|
||||
if (result != HBPrivacyConsentStateGranted)
|
||||
{
|
||||
[HBUtilities writeToActivityLog:"Failed to get permission to automate system events"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,14 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
+ (NSString *)iso6392CodeFor:(NSString *)language;
|
||||
+ (NSString *)languageCodeForIso6392Code:(NSString *)language;
|
||||
|
||||
typedef NS_ENUM(NSUInteger, HBPrivacyConsentState) {
|
||||
HBPrivacyConsentStateUnknown,
|
||||
HBPrivacyConsentStateDenied,
|
||||
HBPrivacyConsentStateGranted,
|
||||
};
|
||||
|
||||
+ (HBPrivacyConsentState)determinePermissionToAutomateTarget:(NSString *)bundleIdentifier promptIfNeeded:(BOOL)promptIfNeeded;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@ -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
|
||||
|
@ -14,6 +14,10 @@
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-write</key>
|
||||
<true/>
|
||||
<key>com.apple.security.temporary-exception.apple-events</key>
|
||||
<array>
|
||||
<string>com.apple.systemevents</string>
|
||||
</array>
|
||||
<key>com.apple.security.temporary-exception.files.absolute-path.read-only</key>
|
||||
<array>
|
||||
<string>/usr/local/</string>
|
||||
|
@ -72,5 +72,9 @@ GPLv2 license.</string>
|
||||
<false/>
|
||||
<key>NSUserNotificationAlertStyle</key>
|
||||
<string>alert</string>
|
||||
<key>NSAppleEventsUsageDescription</key>
|
||||
<string>HandBrake needs access to shut down or put the computer to sleep</string>
|
||||
<key>NSAppleScriptEnabled</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
Loading…
x
Reference in New Issue
Block a user