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

Action config #2423

Merged
merged 8 commits into from Mar 6, 2018
Merged

Action config #2423

merged 8 commits into from Mar 6, 2018

Conversation

skurfer
Copy link
Member

@skurfer skurfer commented Feb 5, 2018

Allow more things to be defined for actions. Basically because I needed some of this for the new Audio plug-in.

I could have just created 12 actions by hand in less time than it took to figure out the block stuff, but I think it’s worth it. For an actual use-case, see https://github.com/quicksilver/Audio-qsplugin/blob/master/Audio/AudioAction.m#L31

Another place it can be used is Remote Hosts where many of the actions are just opening a URL with a different scheme.

tiennou
tiennou previously requested changes Feb 8, 2018
Copy link
Member

@tiennou tiennou left a comment

Choose a reason for hiding this comment

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

I mostly like it. I'm just a little concerned about generating actions programmatically — I can't remember seeing it done anywhere, and I fear it might not interact well with the "normal" plist registration mechanism…

* return nil;
* };
*/
- (BOOL)setActionUisngBlock:(QSObject *(^)(id, QSObject *))actionBlock selectorName:(NSString *)selName;
Copy link
Member

Choose a reason for hiding this comment

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

Uisng

Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason you're using NSString * instead of SEL ? I'd prefer the latter (as well as a selector: parameter).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Because strings are “normal” and easy to create, while selectors are “weird” and difficult to create. “Difficult” meaning I had to look it up. I didn’t say it was a good reason. 😄 I was just trying to make it as simple as possible on the calling end.

Are you saying it should keep the string but also require you to create and pass in a SEL? Or drop the string?

Copy link
Member

Choose a reason for hiding this comment

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

I'd use -setActionUsingBlock:(…)block selector:(SEL)aSelector.

Take for example -mySelector:. If you mistype "mySelectr:" you will get a "missing method" at runtime. If you use @selector(mySelectr:), you willl/should get a compiler warning that it doesn't know about that particular selector.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, but the only time you ever type the name is during creation. It can be misspelled and still work. Also, I don’t think the compiler is aware of these methods even if you spell them correctly, so you’ll always get a warning. (I haven’t tested that today, but I think I was seeing such warnings during early attempts.)

IMP actionFunction = imp_implementationWithBlock(actionBlock);
SEL actionSelector = NSSelectorFromString(selName);
BOOL actionDefined = class_addMethod([[self provider] class], actionSelector, actionFunction, "@@:@");
[self setAction:actionSelector];
Copy link
Member

Choose a reason for hiding this comment

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

Maybe logging the failure and returning NO if the method couldn't be added would be more fool-proof 😉.

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ve made this a little better.

- (BOOL)setActionUisngBlock:(QSObject *(^)(id, QSObject *))actionBlock selectorName:(NSString *)selName
{
if (![self provider]) {
NSLog(@"define provider before setting a block as the action");
Copy link
Member

Choose a reason for hiding this comment

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

I'd be tempted to NSAssert that, but maybe I'm being too paranoid…

Copy link
Member Author

Choose a reason for hiding this comment

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

It’s mostly there so a developer will catch it during the plug-in’s creation. Wouldn’t an assert crash QS if the mythical developer doesn’t fix things, potentially punishing end users?

Copy link
Member

Choose a reason for hiding this comment

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

Well, if the mythical lets a crashing assert come up in the wild, isn't the mythical to blame for its sloppiness 😉 ?

NSLogs can and will be ignored by the developer, and by the user. Exceptions will not. I'd say document that "It is a programming error to use this method if the action doesn't have a provider".

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, if the mythical lets a crashing assert come up in the wild, isn't the mythical to blame for its sloppiness 😉 ?

Of course, but it’s the user that’ll feel the pain. Not the developer. The creators of all these plug-ins aren’t exactly jumping on issues they day they get reported. Or even the year they get reported.

NSLogs can and will be ignored by the developer, and by the user.

I don’t expect the log message to be what gets their attention. But when they realize their new action doesn’t exist, the message will explain why.

If we’re assuming they’re going to fix the issue during development one way or another, I suppose an exception gets the job done. I’ll change it.

@skurfer
Copy link
Member Author

skurfer commented Feb 8, 2018

I'm just a little concerned about generating actions programmatically — I can't remember seeing it done anywhere

Services Menu Plugin.

I’ll address the other stuff later. Thanks!

and skip trying to set a failed action
@skurfer
Copy link
Member Author

skurfer commented Feb 9, 2018

And it did occur to me after I added all those setters that I could have just used +[QSAction actionWithDictionary:]. 🤦‍♂️ I’ll probably update the plug-in to do that. But the block stuff was necessary. (It ended up how it is now because I started by copying what the Services plug-in does.)

@skurfer
Copy link
Member Author

skurfer commented Mar 3, 2018

I think I addressed everything you asked about @tiennou. Anything else? I’ll wait 72 hours for objections, then merge.

@skurfer skurfer dismissed tiennou’s stale review March 6, 2018 13:46

There’s a working precedent for creating actions.

@skurfer skurfer merged commit 5932f60 into master Mar 6, 2018
@skurfer skurfer deleted the action-config branch March 6, 2018 13:46
skurfer added a commit that referenced this pull request Mar 6, 2018
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.

None yet

2 participants