Rename downloader
module to download
This commit is contained in:
parent
30c7db3f25
commit
b92e1f9574
@ -2,17 +2,17 @@ use iced_futures::futures;
|
|||||||
|
|
||||||
// Just a little utility function
|
// Just a little utility function
|
||||||
pub fn file<T: ToString>(url: T) -> iced::Subscription<Progress> {
|
pub fn file<T: ToString>(url: T) -> iced::Subscription<Progress> {
|
||||||
iced::Subscription::from_recipe(Downloader {
|
iced::Subscription::from_recipe(Download {
|
||||||
url: url.to_string(),
|
url: url.to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Downloader {
|
pub struct Download {
|
||||||
url: String,
|
url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure iced can use our download stream
|
// Make sure iced can use our download stream
|
||||||
impl<H, I> iced_native::subscription::Recipe<H, I> for Downloader
|
impl<H, I> iced_native::subscription::Recipe<H, I> for Download
|
||||||
where
|
where
|
||||||
H: std::hash::Hasher,
|
H: std::hash::Hasher,
|
||||||
{
|
{
|
@ -3,7 +3,7 @@ use iced::{
|
|||||||
Element, Length, ProgressBar, Settings, Subscription, Text,
|
Element, Length, ProgressBar, Settings, Subscription, Text,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod downloader;
|
mod download;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
Example::run(Settings::default())
|
Example::run(Settings::default())
|
||||||
@ -18,7 +18,7 @@ enum Example {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
DownloadProgressed(downloader::Progress),
|
DownloadProgressed(download::Progress),
|
||||||
Download,
|
Download,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +49,13 @@ impl Application for Example {
|
|||||||
},
|
},
|
||||||
Message::DownloadProgressed(message) => match self {
|
Message::DownloadProgressed(message) => match self {
|
||||||
Example::Downloading { progress } => match message {
|
Example::Downloading { progress } => match message {
|
||||||
downloader::Progress::Started => {
|
download::Progress::Started => {
|
||||||
*progress = 0.0;
|
*progress = 0.0;
|
||||||
}
|
}
|
||||||
downloader::Progress::Advanced(percentage) => {
|
download::Progress::Advanced(percentage) => {
|
||||||
*progress = percentage;
|
*progress = percentage;
|
||||||
}
|
}
|
||||||
downloader::Progress::Finished => {
|
download::Progress::Finished => {
|
||||||
*self = Example::Finished {
|
*self = Example::Finished {
|
||||||
button: button::State::new(),
|
button: button::State::new(),
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ impl Application for Example {
|
|||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
match self {
|
match self {
|
||||||
Example::Downloading { .. } => {
|
Example::Downloading { .. } => {
|
||||||
downloader::file("https://speed.hetzner.de/100MB.bin")
|
download::file("https://speed.hetzner.de/100MB.bin")
|
||||||
.map(Message::DownloadProgressed)
|
.map(Message::DownloadProgressed)
|
||||||
}
|
}
|
||||||
_ => Subscription::none(),
|
_ => Subscription::none(),
|
||||||
|
Loading…
Reference in New Issue
Block a user