diff --git a/Click2Minimize/AppDelegate.swift b/Click2Minimize/AppDelegate.swift index 55a4109..3478ff5 100644 --- a/Click2Minimize/AppDelegate.swift +++ b/Click2Minimize/AppDelegate.swift @@ -16,10 +16,10 @@ struct Click2MinimizeApp: App { Divider() // New button to open System Preferences for Accessibility - Button(action: appDelegate.openAccessibilityPreferences, label: { Text("Accessibility Preferences") }) + Button(action: { appDelegate.openPreferences(for: "Accessibility") }, label: { Text("Accessibility Preferences") }) // New button to open System Preferences for Automation - Button(action: appDelegate.openAutomationPreferences, label: { Text("Automation Preferences") }) + Button(action: { appDelegate.openPreferences(for: "Automation") }, label: { Text("Automation Preferences") }) Divider() Button(action: appDelegate.quitApp, label: { Text("Quit") }) @@ -359,7 +359,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let response = alert.runModal() if response == .alertFirstButtonReturn { - openAccessibilityPreferences() + openPreferences(for: "Accessibility") // Quit the application as it won't work without permission // Delay termination by 1 second DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { @@ -368,13 +368,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } - func openAccessibilityPreferences() { - let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")! - NSWorkspace.shared.open(url) - } - - func openAutomationPreferences() { - let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Automation")! + func openPreferences(for pane: String) { + let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_\(pane)")! NSWorkspace.shared.open(url) } diff --git a/pr_description.md b/pr_description.md new file mode 100644 index 0000000..ff7cc52 --- /dev/null +++ b/pr_description.md @@ -0,0 +1,6 @@ +๐Ÿงน [Refactor openPreferences methods to reduce duplication] + +๐ŸŽฏ **What:** The code health issue addressed was the duplication of the methods `openAccessibilityPreferences` and `openAutomationPreferences` in `AppDelegate.swift`. +๐Ÿ’ก **Why:** Combining these into a single method `openPreferences(for: String)` improves maintainability and readability by eliminating duplicated logic and creating a reusable pattern for opening other preference panes in the future. +โœ… **Verification:** I verified the change by manually inspecting all usages and making sure they correctly supply "Accessibility" or "Automation" as the pane string argument to the new method. Note: The environment does not have macOS build tools like `swift` or `xcodebuild`, so actual compilation couldn't be done, but a static code review confirmed correctness and absence of syntax errors. +โœจ **Result:** The codebase is cleaner, shorter, and more DRY (Don't Repeat Yourself), without changing existing behavior.