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

Made LaunchConfiguration asynchronous at the language level #1019

Merged

Conversation

Lehonti
Copy link
Contributor

@Lehonti Lehonti commented Oct 3, 2024

Refactoring AsyncEffectRenderer properly is currently hard because it's hard to track when exactly things are happening.

For instance, methods where configuration dialogs are created return void and rely on event handlers for the dialog's asynchronous tasks, most importantly what happens when the user clicks either Ok or Cancel. This leaves these dialogs 'hanging'.

The above is what I'm addressing in this pull request, but there are many other things that I plan to address in future pull requests.

@Lehonti Lehonti changed the title Made LaunchConfiguration asynchronous Made LaunchConfiguration asynchronous at the language level Oct 3, 2024
Copy link
Member

@cameronwhite cameronwhite left a comment

Choose a reason for hiding this comment

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

I think this is the right approach. The API actually used to return a bool back in the GTK3 days when the dialog was blocking, but then these event handlers were introduced in the GTK4 port (ef0466d) which happened before we got the synchronization contexts and async methods working properly

/// The localizer for the effect add-in. This is used to fetch translations for the
/// strings in the dialog.
/// </param>
protected void LaunchSimpleEffectDialog (AddinLocalizer localizer)
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this signature (or some equivalent way of doing this) is still needed for addins, since this wrapper translates the Mono.Addins.AddinLocalizer into the IAddinLocalizer interface
Addins can't create an AddinLocalizerWrapper manually either since that's an internal class.

e.g. https://github.com/PintaProject/NightVisionEffect/blob/a9ac90a38373cec4c5f69d042998c4ffe35e6438/NightVisionAddin/NightVisionEffect.cs#L53
and
168115e

Copy link
Contributor Author

@Lehonti Lehonti Oct 3, 2024

Choose a reason for hiding this comment

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

Thank you. I've re-added it, but the return type is a Task<bool>. Is that fine?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah changing the return type to Task<bool> is fine - all the demo add-ins will need to be updated for any API changes before release

Copy link
Contributor Author

@Lehonti Lehonti Oct 3, 2024

Choose a reason for hiding this comment

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

@cameronwhite I know that you are referring to API changes and demos in general (in all the extensible parts of Pinta). With that being said, is there another demo effect besides the night vision one?

Copy link
Member

Choose a reason for hiding this comment

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

No, I think that's the only demo for an effect

@@ -84,35 +84,12 @@ public abstract class BaseEffect
/// Launches the configuration dialog for this effect/adjustment.
/// If IsConfigurable is true, the ConfigDialogResponse event will be invoked when the user accepts or cancels the dialog.
/// </summary>
public virtual void LaunchConfiguration ()
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about making the return type a Task<bool>, or some wrapper around a bool to make the meaning more clear, sort of like the ConfigDialogResponseEventArgs from before?

My main thoughts are

  • Gtk.ResponseType has a lot of values in the enum, so it's less clear which values we care about or are possible to have to deal with. It's really just success / failure that matter
  • Ideally the effect API should be as independent as possible from UI stuff like GTK. Using the ResponseType enum probably doesn't cause anything bad like forcing GTK libraries to be loaded / initialized for the unit tests, but it does mean that any API changes when upgrading to future GTK versions have more of an impact on the effects

Copy link
Contributor Author

@Lehonti Lehonti Oct 3, 2024

Choose a reason for hiding this comment

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

I think Task<bool> is good for now while the API is being defined. I just changed it

@Lehonti
Copy link
Contributor Author

Lehonti commented Oct 3, 2024

I addressed your points @cameronwhite

I was about to change the signature of other methods that show a dialog, too, but it got the compiler to show a lot of warnings, so I reverted those commits and decided to address those issues in some future pull request.

@cameronwhite
Copy link
Member

Thanks, yeah I think limiting this PR to the effect dialog changes makes sense.
For changing other dialogs, note that we do have a RunAsync() extension method for Adw.MessageDialog so that could be more widely used

@cameronwhite cameronwhite merged commit 4ee6dfb into PintaProject:master Oct 3, 2024
5 checks passed
@Lehonti Lehonti deleted the refactoring/effect_config_async branch October 3, 2024 22:04
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