mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-06-02 03:19:54 +02:00
improve gui
This commit is contained in:
parent
16ad213ae4
commit
bd8f1409bd
|
@ -1,3 +1,5 @@
|
|||
use std::{cell::Cell, rc::Rc, thread::JoinHandle};
|
||||
|
||||
use gtk4::prelude::*;
|
||||
|
||||
use crate::start_streamlink;
|
||||
|
@ -9,12 +11,22 @@ pub struct GuiInitData {
|
|||
}
|
||||
|
||||
pub fn run_gui(init: GuiInitData) {
|
||||
let streamlink_handle = Rc::new(Cell::new(None));
|
||||
let app = gtk4::Application::new(Some("de.mzte.playtwitch"), Default::default());
|
||||
app.connect_activate(move |app| build_ui(app, &init));
|
||||
let streamlink_handle_ = streamlink_handle.clone();
|
||||
app.connect_activate(move |app| build_ui(app, &init, streamlink_handle_.clone()));
|
||||
app.run();
|
||||
|
||||
if let Some(handle) = streamlink_handle.take() {
|
||||
handle.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn build_ui(app: >k4::Application, init: &GuiInitData) {
|
||||
fn build_ui(
|
||||
app: >k4::Application,
|
||||
init: &GuiInitData,
|
||||
streamlink_handle_out: Rc<Cell<Option<JoinHandle<()>>>>,
|
||||
) {
|
||||
let win = gtk4::ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.title("Pick a stream!")
|
||||
|
@ -32,8 +44,45 @@ fn build_ui(app: >k4::Application, init: &GuiInitData) {
|
|||
quality_entry.set_hexpand(true);
|
||||
quality_entry.set_text(&init.quality);
|
||||
|
||||
let other_channel = gtk4::Entry::builder()
|
||||
.placeholder_text("Other Channel...")
|
||||
.hexpand(true)
|
||||
.build();
|
||||
vbox.append(&other_channel);
|
||||
|
||||
// focus other channel initially
|
||||
vbox.set_focus_child(Some(&other_channel));
|
||||
|
||||
let app_ = app.clone();
|
||||
let quality_entry_ = quality_entry.clone();
|
||||
let streamlink_handle_out_ = streamlink_handle_out.clone();
|
||||
other_channel.connect_activate(move |this| {
|
||||
let channel = this.text().to_string();
|
||||
let quality = quality_entry_.text().to_string();
|
||||
|
||||
streamlink_handle_out_.set(Some(std::thread::spawn(move || {
|
||||
if let Err(e) = start_streamlink(&channel, &quality) {
|
||||
eprintln!("Streamlink Error: {:?}", e);
|
||||
}
|
||||
})));
|
||||
|
||||
app_.quit();
|
||||
});
|
||||
|
||||
let list = gtk4::ListBox::new();
|
||||
vbox.append(&list);
|
||||
vbox.append(
|
||||
>k4::Frame::builder()
|
||||
.child(
|
||||
>k4::ScrolledWindow::builder()
|
||||
.child(&list)
|
||||
.vexpand(true)
|
||||
.vscrollbar_policy(gtk4::PolicyType::Always)
|
||||
.hscrollbar_policy(gtk4::PolicyType::Automatic)
|
||||
.build(),
|
||||
)
|
||||
.label("Quick Channels")
|
||||
.build(),
|
||||
);
|
||||
|
||||
for channel in init.channels.iter() {
|
||||
let entry = gtk4::ListBoxRow::new();
|
||||
|
@ -53,11 +102,11 @@ fn build_ui(app: >k4::Application, init: &GuiInitData) {
|
|||
let quality = quality_entry.text().to_string();
|
||||
let channel = label.text().to_string();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
streamlink_handle_out.set(Some(std::thread::spawn(move || {
|
||||
if let Err(e) = start_streamlink(&channel, &quality) {
|
||||
eprintln!("Streamlink Error: {:?}", e);
|
||||
}
|
||||
});
|
||||
})));
|
||||
|
||||
app_.quit();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue