Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions Rectangle/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@IBAction func ignoreFrontMostApp(_ sender: NSMenuItem) {
if sender.state == .on {
applicationToggle.enableFrontApp()
applicationToggle.enableApp()
} else {
applicationToggle.disableFrontApp()
applicationToggle.disableApp()
}
}

Expand Down Expand Up @@ -552,20 +552,47 @@ extension AppDelegate {
prevActiveApp?.activate()
}
DispatchQueue.main.async {

func getUrlName(_ name: String) -> String {
return name.map { $0.isUppercase ? "-" + $0.lowercased() : String($0) }.joined()
}

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
guard
let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
components.host == "execute-action",
components.path.isEmpty,
let name = (components.queryItems?.first { $0.name == "name" })?.value,
let action = (WindowAction.active.first { getUrlName($0.name) == name })
components.path.isEmpty
else {
continue
}
action.postUrl()

let name = (components.queryItems?.first { $0.name == "name" })?.value
switch (components.host, name) {
case ("execute-action", _):
let action = (WindowAction.active.first { getUrlName($0.name) == name })
action?.postUrl()
case ("execute-task", "ignore-app"):
let bundleId = extractBundleIdParameter(fromComponents: components)
guard isValidParameter(bundleId: bundleId) else { continue }
self.applicationToggle.disableApp(appBundleId: bundleId)
case ("execute-task", "unignore-app"):
let bundleId = extractBundleIdParameter(fromComponents: components)
guard isValidParameter(bundleId: bundleId) else { continue }
self.applicationToggle.enableApp(appBundleId: bundleId)
default:
continue
}
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions Rectangle/ApplicationToggle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ class ApplicationToggle: NSObject {
}
}

public func disableFrontApp() {
if let frontAppId = Self.frontAppId {
disabledApps.insert(frontAppId)
public func disableApp(appBundleId: String? = frontAppId) {
if let appBundleId {
disabledApps.insert(appBundleId)
saveDisabledApps()
disableShortcuts()
}
}

public func enableFrontApp() {
if let frontAppId = Self.frontAppId {
disabledApps.remove(frontAppId)
public func enableApp(appBundleId: String? = frontAppId) {
if let appBundleId {
disabledApps.remove(appBundleId)
saveDisabledApps()
enableShortcuts()
}
Expand Down Expand Up @@ -118,7 +118,6 @@ class ApplicationToggle: NSObject {
}
}
}

}

// todo mode
Expand Down