Skip to content

Commit

Permalink
Check if app-bundle-id parameter is empty for ignore/unignore url
Browse files Browse the repository at this point in the history
  • Loading branch information
rxhanson committed Nov 13, 2024
1 parent 1304d0a commit d1c7b04
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Rectangle/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -552,18 +552,23 @@ extension AppDelegate {
prevActiveApp?.activate()
}
DispatchQueue.main.async {

func getUrlName(_ name: String) -> String {
return name.map { $0.isUppercase ? "-" + $0.lowercased() : String($0) }.joined()
}
func getAppBundleId(_ components: URLComponents) -> String? {
let appBundleId = (components.queryItems?.first { $0.name == "app-bundle-id" })?.value
Logger.log("The app Bundle id : \(appBundleId ?? "")")
return if appBundleId != nil && appBundleId!.isEmpty {
appBundleId
} else {
ApplicationToggle.frontAppId

func extractBundleIdParameter(fromComponents components: URLComponents) -> String? {
(components.queryItems?.first { $0.name == "app-bundle-id" })?.value
}

func isValidParameter(bundleId: String?) -> Bool {
let isValid = bundleId?.isEmpty != true
if !isValid {
Logger.log("Received an empty app-bundle-id parameter. Either pass a valid app bundle id or remove the parameter.")
}
return isValid
}

for url in urls {
guard
let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
Expand All @@ -578,9 +583,13 @@ extension AppDelegate {
let action = (WindowAction.active.first { getUrlName($0.name) == name })
action?.postUrl()
case ("execute-task", "ignore-app"):
self.applicationToggle.disableApp(appBundleId: getAppBundleId(components))
let bundleId = extractBundleIdParameter(fromComponents: components)
guard isValidParameter(bundleId: bundleId) else { continue }
self.applicationToggle.disableApp(appBundleId: bundleId)
case ("execute-task", "unignore-app"):
self.applicationToggle.enableApp(appBundleId: getAppBundleId(components))
let bundleId = extractBundleIdParameter(fromComponents: components)
guard isValidParameter(bundleId: bundleId) else { continue }
self.applicationToggle.enableApp(appBundleId: bundleId)
default:
continue
}
Expand Down

0 comments on commit d1c7b04

Please sign in to comment.