-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
External Command or Message to update the UI? #230
Comments
I believe @Songtronix has a similar use case in In any case, you should be able to model this properly using a You will need to implement the Then, you can obtain a Finally, you should return this subscription in The |
I bet this use case will happen quite often. Anything against adding an example? I would greatly do so 😄 |
@Songtronix I think it could be a great example. We'll need to decide what kind of file to download and what do we do with it to prove it has been downloaded correctly. We could also fake the download in the Up to you! Nothing against it for sure. I'd love a PR with a nice example of this. |
Great! Thanks @hecrj @Songtronix . |
I got everything else so far but damn fiddling with streams is quite a pain if you never have worked with them. Can't wait for generators to land in rust. |
Hey @Songtronix. Which HTTP client are you using in your example? |
Yes. It's really awesome they provide these metrics but it doesn't work that nicely with iced. I currently tick manually to update the screen but also any mouse movement will trigger the update too which looks kinda funny if the download progress smoothes out while moving your mouse ^^ Funny thing is you need to watch out to not call the metrics too often. It will slow down the download in my experience. |
Initial implementation is here: #232 |
@Songtronix Great job! Thanks again! |
@hecrj Cool, I already adopt this pattern and it works charmingly in my Iced project. 👍 |
Awesome! We can close this then :) |
However, I got two new questions.
I have tried to support the second one, but it not working. Only the first task updates its progress UI, the rest tasks don't. Here is part of my code: #[derive(Debug)]
enum Main {
Loading,
Loaded(State),
}
#[derive(Debug, Clone, Default)]
struct State {
download_urls: Vec<String>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
enum Message {
StartDownload(String),
DownloadProgressed((String, Progress)),
}
impl Application for Main {
type Executor = iced::executor::Default;
type Message = Message;
fn subscription(&self) -> Subscription<Self::Message> {
match self {
Main::Loading => Subscription::none(),
Main::Loaded(State { download_urls, .. }) => {
Subscription::batch(download_urls.iter().map(|url| {
Subscription::from_recipe(Download {
url: url.to_string(),
})
.map(Message::DownloadProgressed)
}))
}
}
}
} Any idea on those topics? |
Yes, simply stop returning the
Also yes. The current example has a bug in the |
So cool! Thanks, @hecrj . |
I'm a newbie to Iced and don't familiar with The Elm Architecture neither. I found a scenario that is hard even infeasible for the current architecture to achieve. (Maybe I'm wrong or something I missed?)
Here is the scenario:
We have a
Download
button, the on-press event is to trigger an async download task. In the meanwhile, when the download task started, theDownload
button should display the percent progress ( 0% -> 1% ->... -> 100%).Below is the download function, which takes a
progress_callback
to notify the current progress.Use
Subscription
or CustomWidget
? Well, I really have no idea how to achieve this. Does it mean we need a kind of externalCommand
orMessage
to support this?The text was updated successfully, but these errors were encountered: