Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ignore unignore URL actions #1505

Merged
merged 6 commits into from
Nov 14, 2024

Conversation

bric3
Copy link
Contributor

@bric3 bric3 commented Oct 28, 2024

Adds the support for

  • open -g "rectangle://execute-action?name=ignore-app"
  • open -g "rectangle://execute-action?name=unignore-app"

@rxhanson
Copy link
Owner

Thanks for looking to contribute.

Rather than adding these as window actions, I recommend adding a new url query parameter that will call applicationToggle.enableFrontApp() or applicationToggle.disableFrontApp(). That way your changes are only in AppDelegate. The url stuff is at the bottom of AppDelegate.

Maybe something like rectangle://execute-task?name=ignore-app?

@bric3
Copy link
Contributor Author

bric3 commented Oct 30, 2024

What about adding a query pram for the app bundle id, so that even if IntelliJ is in background for some reason it can execute this action without affecting another app.

@bric3 bric3 marked this pull request as ready for review October 30, 2024 12:10
@rxhanson
Copy link
Owner

Sure! This looks good to me, but I can hold off on merging if you wanted to add in the bundleId query param.

@bric3
Copy link
Contributor Author

bric3 commented Oct 30, 2024

OK I'll do it shortly.

@bric3
Copy link
Contributor Author

bric3 commented Oct 30, 2024

Added app-bundle-id param for both ignore/unignore.

Rectangle/AppDelegate.swift Outdated Show resolved Hide resolved
Rectangle/AppDelegate.swift Outdated Show resolved Hide resolved
Rectangle/WindowAction.swift Outdated Show resolved Hide resolved
Rectangle/AppDelegate.swift Outdated Show resolved Hide resolved
@@ -555,17 +555,34 @@ extension AppDelegate {
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
return if appBundleId == nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this change here. Sorry to beleaguer this, but I figure we might as well get this tidied up.

  • What we have now can also be rewritten as return appBundleId ?? ApplicationToggle.frontAppId (hence one of the reasons why you don't typically see if come after return)
  • However, this would still be the same as return appBundleId since once we get to ApplicationToggle, we would be providing the ApplicationToggle.frontAppId at that time in the case of appBundleId being nil.
  • If we want to account for app-bundle-id= in the URL, then we would have to check that appBundleId != nil && appBundleId.isEmpty (depending on if we do indeed get back an empty string in that case - I didn't test it).

I'm still ok either way on doing the empty string check, but it still makes the most sense to me to at the very least change this to return appBundleId here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I pushed a change in the train yesterday as a reflex, (if anything happen to the laptop).

I agree with your points; my original goal is indeed the third point.

@bric3 bric3 force-pushed the ignore-unignore-actions branch from 7c08e20 to 1304d0a Compare November 1, 2024 15:42
@rxhanson
Copy link
Owner

rxhanson commented Nov 8, 2024

I wanted to make sure that I'm not holding things up here - let me know when you're ready for me to take another look (no pressure or anything).

@bric3
Copy link
Contributor Author

bric3 commented Nov 8, 2024

@rxhanson Hi, I think I fixed the last open point. And yes I'd like another pass.

Thank you very much!

@rxhanson
Copy link
Owner

rxhanson commented Nov 13, 2024

Apologies for the delay. I hope you don't mind, but I proposed my expected change directly in your branch in the interest of moving this along. Your last change still allowed for an empty app-bundle-id to result in the frontmost app being ignore/unignored. Feel free to roll back my proposal and give this another go if I misunderstood the goal.

@bric3
Copy link
Contributor Author

bric3 commented Nov 13, 2024

Looks good. Thanks for looking into it.

I didn't write the validation because this empty value has no side effect as far as I know. It's just stored into the "hash set", and since no app can have an empty bundle id (I may be wrong here), this will never be looked up in this "hash set".
That said having correct data in this collection is better.

@rxhanson rxhanson merged commit f5f3448 into rxhanson:main Nov 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants