Running a task to its completion

Hi

I’m using iced to manage my GUI in association with rfd to show error message, and file dialog.
Sadly, on Windows, the rfd windows do not appear in foreground but in background. It seems to come from the fact that I did not pass a WindowHandle as parent.

So I tried to find a way to get the windowHandle of the focused iced window, using subscription, I got its ID.

And it seems that the only way to obtain the WindowHandle from here is to use the run_with_handle function. But this function returns a task, so I would need a way to run this Task to its completion to get the result of the call I made.

Is there any way to perform something similar ?

Thank you for any help

Yeah. The only way that I know of is using run_with_handle.

But to shorten the process of using it, you can use then on task so you wont have to create an extra message for that.

Does a task need to be registered to be run to its completion or just creating it is enough?

Just create it and return it from your update method once. Then it runs until it ends.

Is there any other way to schedule a task ?

Because currently I use it in a call similar to expect to show an error message before kill the app.

What would be the effect that you want?

My function is like that

fn custom_expect(self: Result<T, Err>, msg: &str) -> T {
    if let Err(e) = self {
       let dialog = // Create the dialog box with red
       run_with_hadle(
          ID, // global car defined as the last focused window 
         |handle| dialog.set_parent(handle).show(),
       )
    }
    self.expect(msg)
}

The idea is to show a reason why the program crashed to a user that wouldn’t be using a console

Because on Linux the dialog is shown in foreground automatically if it doesn’t have a parents
But it seems that the focus stealing prevention on windows, puts the error message in background, so the user has the impression that the software just crashed.

You will need to find a way to return the command, that you get returned from run_with_handle, from your application level update method.

I don’t know if it’s possible in the current version of iced
But it seems interesting to run a task in a blocking way, when you can’t abide to have something delayed

From the description of Task I assume there won’t be a way in the future to run it as blocking.

A set of concurrent actions to be performed by the iced runtime.

If you want to block your state from mutating while waiting on the task, you could have a boolean field in your state that keeps track of that.