fix: lock upload button when uploading
This commit is contained in:
parent
09b4829281
commit
e757a1474c
1 changed files with 29 additions and 17 deletions
46
src/main.rs
46
src/main.rs
|
@ -43,12 +43,14 @@ impl Config {
|
||||||
enum Message {
|
enum Message {
|
||||||
OpenFilePicker,
|
OpenFilePicker,
|
||||||
SetFolder(ZiplineFolder),
|
SetFolder(ZiplineFolder),
|
||||||
|
LockAndStart,
|
||||||
StartTheProcess,
|
StartTheProcess,
|
||||||
Nothing,
|
Nothing,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Tyrolienne {
|
struct Tyrolienne {
|
||||||
config: Config,
|
config: Config,
|
||||||
|
locked: bool,
|
||||||
video_path: Option<PathBuf>,
|
video_path: Option<PathBuf>,
|
||||||
folder: Option<ZiplineFolder>,
|
folder: Option<ZiplineFolder>,
|
||||||
dialog: Controller<Dialog>,
|
dialog: Controller<Dialog>,
|
||||||
|
@ -118,10 +120,11 @@ impl AsyncComponent for Tyrolienne {
|
||||||
},
|
},
|
||||||
|
|
||||||
gtk::Button {
|
gtk::Button {
|
||||||
set_label: "Send",
|
|
||||||
#[watch]
|
#[watch]
|
||||||
set_sensitive: model.video_path.is_some(),
|
set_label: if model.locked { "Uploading..." } else { "Send" },
|
||||||
connect_clicked => Message::StartTheProcess,
|
#[watch]
|
||||||
|
set_sensitive: !model.locked && model.video_path.is_some(),
|
||||||
|
connect_clicked => Message::LockAndStart,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +138,7 @@ impl AsyncComponent for Tyrolienne {
|
||||||
) -> AsyncComponentParts<Self> {
|
) -> AsyncComponentParts<Self> {
|
||||||
let model = Tyrolienne {
|
let model = Tyrolienne {
|
||||||
config,
|
config,
|
||||||
|
locked: false,
|
||||||
video_path: None,
|
video_path: None,
|
||||||
folder: None,
|
folder: None,
|
||||||
dialog: Dialog::builder()
|
dialog: Dialog::builder()
|
||||||
|
@ -177,7 +181,7 @@ impl AsyncComponent for Tyrolienne {
|
||||||
async fn update(
|
async fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
message: Self::Input,
|
message: Self::Input,
|
||||||
_sender: relm4::AsyncComponentSender<Self>,
|
sender: relm4::AsyncComponentSender<Self>,
|
||||||
_root: &Self::Root,
|
_root: &Self::Root,
|
||||||
) {
|
) {
|
||||||
match message {
|
match message {
|
||||||
|
@ -185,13 +189,6 @@ impl AsyncComponent for Tyrolienne {
|
||||||
Message::SetFolder(folder) => {
|
Message::SetFolder(folder) => {
|
||||||
self.folder = (folder.id != GtkZiplineFolder::NONE_ID).then_some(folder)
|
self.folder = (folder.id != GtkZiplineFolder::NONE_ID).then_some(folder)
|
||||||
}
|
}
|
||||||
Message::StartTheProcess => match the_process(self).await {
|
|
||||||
Ok(url) => tracing::info!("{url}"),
|
|
||||||
Err(e) => self.dialog.emit(DialogInput::Show {
|
|
||||||
heading: "An error occurred".into(),
|
|
||||||
body: e.to_string(),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
Message::OpenFilePicker => {
|
Message::OpenFilePicker => {
|
||||||
let file = rfd::AsyncFileDialog::new()
|
let file = rfd::AsyncFileDialog::new()
|
||||||
.add_filter("Video file", &["mp4", "mkv", "webm"])
|
.add_filter("Video file", &["mp4", "mkv", "webm"])
|
||||||
|
@ -202,6 +199,22 @@ impl AsyncComponent for Tyrolienne {
|
||||||
self.video_path = Some(file.path().to_owned());
|
self.video_path = Some(file.path().to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::LockAndStart => {
|
||||||
|
// a little bit convoluted, but i don't really know how to force a view update
|
||||||
|
// before starting the "long" process
|
||||||
|
self.locked = true;
|
||||||
|
sender.input(Message::StartTheProcess);
|
||||||
|
}
|
||||||
|
Message::StartTheProcess => {
|
||||||
|
match the_process(self).await {
|
||||||
|
Ok(url) => tracing::info!("{url}"),
|
||||||
|
Err(e) => self.dialog.emit(DialogInput::Show {
|
||||||
|
heading: "An error occurred".into(),
|
||||||
|
body: e.to_string(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
self.locked = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,12 +271,11 @@ async fn the_process(app: &Tyrolienne) -> Result<String> {
|
||||||
tracing::info!("uploading video...");
|
tracing::info!("uploading video...");
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = zipline::upload_file(
|
let Some(ref video_path) = app.video_path else {
|
||||||
&app.config,
|
bail!("No video given!");
|
||||||
app.folder.as_ref(),
|
};
|
||||||
app.video_path.as_ref().unwrap(),
|
|
||||||
)
|
let res = zipline::upload_file(&app.config, app.folder.as_ref(), video_path).await?;
|
||||||
.await?;
|
|
||||||
let zp_file = &res.files[0];
|
let zp_file = &res.files[0];
|
||||||
|
|
||||||
tracing::info!("recalculating thumbnails...");
|
tracing::info!("recalculating thumbnails...");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue