Fix screenshot finalize behavior for plugin
Merge request reports
Activity
assigned to @andreldm
mentioned in issue #96 (closed)
@Tamaranch could you please review? I'm not entirely happy with my solution, I've tried to use GTasks but they can only be completed once, meaning I would need to be instaciating and unrefing. Suggestions are very welcome
Sorry, I should have provided some context: originally the plugin button was correctly made insensitive and sensitive when the screenshot was done, over the years I changed
screenshooter_take_screenshot
to be non blocking to fix some nasty bugs (I don't remember what). Now what was requested is to store the last unused save directory, it would be super easy if that function was still blocking.For GTask yes the idea is to instantiate one per task, how is that a problem?
I think I would be abusing it for this scenario and would need to keep track of their lifecycle (risk of leaks). I also considered GClosure but it needed a marshaller, I couldn't figure out how to make it work.
In the end what I really wanted was a simple callback, which is different for the main application and plugin, while the latter needs a reference to a struct (PluginData), in C++ that could be a capturing lambda.
I don't see why you should care about the lifecycle of the GTask, if you use it like this normally you don't need to worry about it:
cancellable = g_cancellable_new (); task = g_task_new (object, cancellable, callback, data); g_task_run_in_thread (task, task_func); g_object_unref (task); g_object_unref (cancellable);
That said the current change produces understandable code so if it works properly there may be no need to do otherwise :)