Resolve warnings in screenplay

This commit is contained in:
Savanni D'Gerinel 2025-01-19 12:53:31 -05:00
parent cc4f8c1515
commit 35abcfcf28
3 changed files with 20 additions and 8 deletions

1
Cargo.lock generated
View File

@ -3540,6 +3540,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
name = "screenplay" name = "screenplay"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-std",
"glib", "glib",
"gtk4", "gtk4",
] ]

View File

@ -7,5 +7,6 @@ license = "GPL-3.0-only"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
async-std = "1.13.0"
glib = { version = "0.18" } glib = { version = "0.18" }
gtk = { version = "0.7", package = "gtk4" } gtk = { version = "0.7", package = "gtk4" }

View File

@ -67,7 +67,7 @@ impl Screenplay {
pub fn new(gtk_app: &gtk::Application, screens: Vec<Screen>) -> Result<Self, Error> { pub fn new(gtk_app: &gtk::Application, screens: Vec<Screen>) -> Result<Self, Error> {
let window = gtk::ApplicationWindow::new(gtk_app); let window = gtk::ApplicationWindow::new(gtk_app);
let (sender, receiver) = gtk::glib::MainContext::channel(gtk::glib::Priority::DEFAULT); let (sender, receiver) = async_std::channel::unbounded();
let layout = gtk::Box::builder() let layout = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal) .orientation(gtk::Orientation::Horizontal)
@ -89,11 +89,15 @@ impl Screenplay {
layout.append(&frame); layout.append(&frame);
listbox.connect_row_activated(move |_, row| { listbox.connect_row_activated(move |_, row| {
match row.index() { let sender = sender.clone();
-1 => sender.send(Action::Deselect), let row = row.clone();
idx => sender.send(Action::SelectPage(idx as usize)), glib::spawn_future_local(async move {
} match row.index() {
.unwrap() -1 => sender.send(Action::Deselect).await,
idx => sender.send(Action::SelectPage(idx as usize)).await,
}
.unwrap()
});
}); });
screens.iter().for_each(|Screen { title, .. }| { screens.iter().for_each(|Screen { title, .. }| {
@ -107,8 +111,14 @@ impl Screenplay {
let storybook = Self { frame, screens }; let storybook = Self { frame, screens };
{ {
let mut storybook = storybook.clone(); glib::spawn_future_local({
receiver.attach(None, move |message| storybook.process_action(message)); let mut storybook = storybook.clone();
async move {
while let Ok(msg) = receiver.recv().await {
storybook.process_action(msg);
}
}
});
} }
Ok(storybook) Ok(storybook)