Skip to content

Commit 16cb0f1

Browse files
committed
Add Stream button for media files
1 parent 5dd99bf commit 16cb0f1

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

data/resources/ui/download_page.blp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ template DownloadPage: Gtk.Box {
2828
wrap: true;
2929
}
3030
Gtk.Label label_downloaded {
31+
styles ["numeric"]
3132
label: "0KB";
3233
xalign: 0.0;
3334
}
@@ -39,10 +40,11 @@ template DownloadPage: Gtk.Box {
3940
}
4041
}
4142
Gtk.Button open_btn {
42-
styles ["suggested-action", "pill"]
43-
label: "Open File";
43+
styles ["pill"]
44+
label: "Stream (alpha)";
4445
margin-top: 8;
4546
margin-bottom: 8;
4647
opacity: 0;
48+
halign: center;
4749
}
4850
}

src/common/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ should remove bookmarks.
5252
## Custom bookmarks:
5353
";
5454

55+
pub const STREAMABLE_EXTS: [&str; 8] = [
56+
"mp3",
57+
"mp4",
58+
"webm",
59+
"opus",
60+
"wav",
61+
"ogg",
62+
"mkv",
63+
"flac",
64+
];
65+
5566
pub fn bookmarks_url() -> Url {
5667
Url::parse(&format!("file://{}", BOOKMARK_FILE_PATH.to_str().unwrap())).unwrap()
5768
}

src/tab.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,17 @@ impl Tab {
556556
imp.stack.add_child(&page);
557557
imp.stack.set_visible_child(&page);
558558

559+
let downloaded_file_url = format!("file://{}", d_path.as_os_str().to_str().unwrap());
560+
info!("Downloading to {}", downloaded_file_url);
561+
page.imp().open_btn.connect_clicked(move |_| {
562+
gtk::show_uri(None::<&gtk::Window>, &downloaded_file_url, 0);
563+
});
564+
559565

566+
let ext = file_name.split(".").last();
567+
if let Some(true) = ext.map(|ext| crate::common::STREAMABLE_EXTS.contains(&ext)) {
568+
page.imp().open_btn.set_opacity(1.0);
569+
}
560570

561571
let mut buffer = Vec::with_capacity(8192);
562572
buffer.extend_from_slice(&[0; 8192]);
@@ -576,7 +586,7 @@ impl Tab {
576586
let t = glib::real_time();
577587
if t - last_update_time > THROTTLE_TIME {
578588
page.imp().progress_bar.pulse();
579-
page.imp().label_downloaded.set_text(&format!("{}KB", read / 1000));
589+
page.imp().label_downloaded.set_text(&format!("{:.2}KB", read as f64 / 1000.0));
580590
last_update_time = t;
581591
}
582592
}
@@ -586,14 +596,11 @@ impl Tab {
586596
Err(e) => return Err(e.into()),
587597
}
588598
}
589-
page.imp().label_downloaded.set_text(&format!("{}KB", read / 1000));
599+
page.imp().label_downloaded.set_text(&format!("{:.2}KB", read as f64 / 1000.0));
590600
page.imp().progress_bar.set_fraction(1.0);
591601
page.imp().open_btn.set_opacity(1.0);
592-
593-
let downloaded_file_url = format!("file://{}", d_path.as_os_str().to_str().unwrap());
594-
page.imp().open_btn.connect_clicked(move |_| {
595-
gtk::show_uri(None::<&gtk::Window>, &downloaded_file_url, 0);
596-
});
602+
page.imp().open_btn.set_label("Open");
603+
page.imp().open_btn.add_css_class("suggested-action");
597604

598605
Ok(())
599606
}

0 commit comments

Comments
 (0)