mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-31 04:58:11 +00:00
fix: trigger scheduler automation permission prompt
This commit is contained in:
@@ -65,6 +65,8 @@ cat > "$CONTENTS_DIR/Info.plist" <<PLIST
|
|||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSAppleEventsUsageDescription</key>
|
||||||
|
<string>Firelink needs permission to control Finder so it can sleep, restart, or shut down your Mac after scheduled downloads finish.</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
PLIST
|
PLIST
|
||||||
|
|||||||
@@ -200,7 +200,36 @@ final class SchedulerController: ObservableObject {
|
|||||||
|
|
||||||
func requestAutomationPermission() {
|
func requestAutomationPermission() {
|
||||||
let target = NSAppleEventDescriptor(bundleIdentifier: "com.apple.finder")
|
let target = NSAppleEventDescriptor(bundleIdentifier: "com.apple.finder")
|
||||||
_ = AEDeterminePermissionToAutomateTarget(target.aeDesc, typeWildCard, typeWildCard, true)
|
let status = AEDeterminePermissionToAutomateTarget(target.aeDesc, typeWildCard, typeWildCard, true)
|
||||||
|
|
||||||
|
if status != noErr {
|
||||||
|
triggerAutomationConsentPrompt()
|
||||||
|
}
|
||||||
|
|
||||||
checkAutomationPermission()
|
checkAutomationPermission()
|
||||||
|
|
||||||
|
if !hasAutomationPermission {
|
||||||
|
openAutomationPermissionSettings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func openAutomationPermissionSettings() {
|
||||||
|
guard let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Automation") else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
NSWorkspace.shared.open(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func triggerAutomationConsentPrompt() {
|
||||||
|
let scriptCode = "tell application \"Finder\" to get name"
|
||||||
|
|
||||||
|
var error: NSDictionary?
|
||||||
|
if let script = NSAppleScript(source: scriptCode) {
|
||||||
|
script.executeAndReturnError(&error)
|
||||||
|
if let error {
|
||||||
|
print("Failed to trigger Automation permission prompt: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,13 @@ struct SchedulerView: View {
|
|||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
VStack(alignment: .leading, spacing: 24) {
|
VStack(alignment: .leading, spacing: 24) {
|
||||||
timeSelectionSection
|
VStack(alignment: .leading, spacing: 24) {
|
||||||
queueSelectionSection
|
timeSelectionSection
|
||||||
postActionSection
|
queueSelectionSection
|
||||||
|
postActionSection
|
||||||
|
}
|
||||||
|
.opacity(isEnabled ? 1.0 : 0.5)
|
||||||
|
.disabled(!isEnabled)
|
||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
permissionsSection
|
permissionsSection
|
||||||
@@ -30,8 +34,6 @@ struct SchedulerView: View {
|
|||||||
.padding(24)
|
.padding(24)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
.opacity(isEnabled ? 1.0 : 0.5)
|
|
||||||
.disabled(!isEnabled)
|
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
loadState()
|
loadState()
|
||||||
@@ -153,16 +155,14 @@ struct SchedulerView: View {
|
|||||||
Text("System Permissions")
|
Text("System Permissions")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
|
||||||
Text("Firelink needs permission to control System Events in order to automatically sleep, restart, or shut down your Mac after downloads finish.")
|
Text("Firelink needs Automation permission to control Finder in order to automatically sleep, restart, or shut down your Mac after downloads finish.")
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
|
|
||||||
if schedulerController.hasAutomationPermission {
|
if schedulerController.hasAutomationPermission {
|
||||||
Button("Revoke Permission") {
|
Button("Revoke Permissions") {
|
||||||
if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Automation") {
|
schedulerController.openAutomationPermissionSettings()
|
||||||
NSWorkspace.shared.open(url)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.buttonStyle(.bordered)
|
.buttonStyle(.bordered)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user