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

Add a "ShortcutReader" interface #2025

Merged
merged 3 commits into from
Aug 22, 2019

Conversation

madoar
Copy link
Collaborator

@madoar madoar commented Jun 30, 2019

This PR adds a ShortcutReader interface for type safety reasons

*
* @param shortcut The shortcut
*/
void of(ShortcutDTO shortcut);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm still thinking whether it is better to add the functionality of this method to the constructor.

Changing the constructor to have the signature:

public ShortcutReader(ShortcutDTO shortcut)

has the benefit that the object usage is cleaner. In addition it has the disadvantage that we can't add the constructor requirement to the interface.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it is part of the constructor, it cannot be defined in the interface, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly

@madoar
Copy link
Collaborator Author

madoar commented Jun 30, 2019

I'm also thinking about whether it makes sense to move the WineShortcutReader implementation to a new file.

This leads me to a second question, why do we have both a WineShortcutReader and a ShortcutReader class with the same method signatures? In theory we could call the WineShortcutReader directly if we know that the shortcut is for a wine container.

@plata
Copy link
Collaborator

plata commented Jul 1, 2019

I can't really answer this because this functionality has been there before I joined. So this is a question for @qparis. However, I would agree that implementing the ShortcutReader for each engine should be sufficient.

@madoar
Copy link
Collaborator Author

madoar commented Jul 7, 2019

I have just created #2033, PhoenicisOrg/scripts#1068 and PhoenicisOrg/scripts#1069 to continue the open discussions.

I think we can merge this as is, and work on the created issues separately.

@madoar madoar requested a review from qparis July 29, 2019 14:28
@madoar
Copy link
Collaborator Author

madoar commented Aug 10, 2019

Any news on this? It would be nice if we could merge this before #2050

@@ -43,24 +43,30 @@ public void run(ShortcutDTO shortcutDTO, List<String> arguments, Consumer<Except
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();

interactiveScriptSession.eval("include(\"engines.wine.shortcuts.reader\");",
ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final Value shortcutReader = (Value) output;
result -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code is the same everywhere. Can we extract it to a separate method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My idea was to do this later on in a centralized method in PhoenicisScriptEngine:

public interface PhoenicisScriptEngine {
    <E> E evalAndReturn(String script, Class<E> type);
    
    <E> void eval(String script, Class<E> type, Consumer<E> onSuccess, Consumer<Exception> onError);
}

See also our documentation.

For now I would suggest to retain the redundancy and fix this later for all script types (i.e. engines, installers, plugins, shortcuts, verbs etc.) at once.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with that.

@plata
Copy link
Collaborator

plata commented Aug 11, 2019

You need to resolve some conflicts.

@madoar
Copy link
Collaborator Author

madoar commented Aug 22, 2019

@plata the conflicts are resolved. I would like to merge this soon because this PR blocks other useful changes to the script engine.

@madoar madoar merged commit 2ea8552 into PhoenicisOrg:master Aug 22, 2019
@madoar madoar deleted the add-shortcut-reader-interface branch August 22, 2019 18:32
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.

3 participants