keep join handles to everything

This commit is contained in:
Erica Z 2024-11-05 11:12:03 +01:00
parent 226c8073d4
commit 88962c629c
4 changed files with 81 additions and 56 deletions

18
Cargo.lock generated
View file

@ -222,6 +222,7 @@ dependencies = [
"bindgen",
"chrono",
"event-listener",
"futures",
"gettext-rs",
"glib-build-tools",
"gtk4",
@ -634,6 +635,21 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "futures"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.31"
@ -641,6 +657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
@ -708,6 +725,7 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",

View file

@ -9,6 +9,7 @@ async-channel = "2.3.1"
base16ct = { version = "0.2.0", features = ["std"] }
chrono = { version = "0.4.38", features = ["serde"] }
event-listener = "5.3.1"
futures = "0.3.31"
gettext-rs = { version = "0.7.2", features = ["gettext-system"] }
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_16"] }
md-5 = { version = "0.10.6", features = ["asm"] }

View file

@ -139,42 +139,36 @@ impl Default for Setup {
}
impl Setup {
pub fn load(&self) {
glib::spawn_future_local(glib::clone!(
#[weak(rename_to = self_)]
self,
async move {
self_.set_server_url("");
self_.set_username("");
self_.set_password("");
self_.set_authn_can_edit(false);
self_.set_authn_can_validate(false);
pub async fn load(&self) {
self.set_server_url("");
self.set_username("");
self.set_password("");
self.set_authn_can_edit(false);
self.set_authn_can_validate(false);
// TODO remove unwraps, make sure authn_can_edit is set back to true
let keyring = oo7::Keyring::new().await.unwrap();
let attributes = vec![("xdg:schema", crate::APP_ID)];
let items = keyring.search_items(&attributes).await.unwrap();
// TODO remove unwraps, make sure authn_can_edit is set back to true
let keyring = oo7::Keyring::new().await.unwrap();
let attributes = vec![("xdg:schema", crate::APP_ID)];
let items = keyring.search_items(&attributes).await.unwrap();
if items.is_empty() {
// didn't find shit, leave all empty
// TODO: onboarding
self_.set_authn_can_edit(true);
self_.set_authn_can_validate(true);
} else {
let item = &items[0];
let attributes = item.attributes().await.unwrap();
if items.is_empty() {
// didn't find shit, leave all empty
// TODO: onboarding
self.set_authn_can_edit(true);
self.set_authn_can_validate(true);
} else {
let item = &items[0];
let attributes = item.attributes().await.unwrap();
self_.set_server_url(attributes["server-url"].clone());
self_.set_username(attributes["username"].clone());
// strip non-utf8 elements from the pw, i guess
self_.set_password(String::from_utf8_lossy(&item.secret().await.unwrap()));
self.set_server_url(attributes["server-url"].clone());
self.set_username(attributes["username"].clone());
// strip non-utf8 elements from the pw, i guess
self.set_password(String::from_utf8_lossy(&item.secret().await.unwrap()));
// first connection
self_.set_authn_can_edit(true); // act as if the user had inputted this
self_.set_authn_can_validate(true);
self_.imp().on_authn_validate_activated().await;
}
}
));
// first connection
self.set_authn_can_edit(true); // act as if the user had inputted this
self.set_authn_can_validate(true);
self.imp().on_authn_validate_activated().await;
}
}
}

View file

@ -56,6 +56,7 @@ mod imp {
pub(super) queued_seek: Cell<Option<f64>>,
pub(crate) initial_setup_handle: RefCell<Option<JoinHandle<()>>>,
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
zbus_executor_loop_handle: RefCell<Option<JoinHandle<()>>>, // same
}
@ -104,6 +105,7 @@ mod imp {
queued_seek: Cell::new(None),
initial_setup_handle: Default::default(),
mpv_event_loop_handle: Default::default(),
zbus_executor_loop_handle: Default::default(),
}
@ -288,7 +290,8 @@ mod imp {
listener.await;
}
});
self.mpv_event_loop_handle.replace(Some(mpv_event_loop_handle));
self.mpv_event_loop_handle
.replace(Some(mpv_event_loop_handle));
// set up mpris
let window = self.obj().clone();
@ -300,30 +303,32 @@ mod imp {
.await
.expect("could not build connection to the session bus");
glib::spawn_future_local(glib::clone!(
#[strong]
conn,
async move {
crate::Mpris::setup(conn.object_server(), &window)
futures::join!(
glib::clone!(
#[strong]
conn,
async move {
crate::Mpris::setup(conn.object_server(), &window)
.await
.expect("could not serve mpris");
/*
crate::mpris::Player::setup(conn.object_server(), &window.imp().playbin)
.await
.expect("could not serve mpris");
/*
crate::mpris::Player::setup(conn.object_server(), &window.imp().playbin)
.await
.expect("could not serve mpris player");
FIXME */
.expect("could not serve mpris player");
FIXME */
// always set up handlers before requesting service name
conn.request_name("org.mpris.MediaPlayer2.audrey")
.await
.expect("could not register name in session bus");
// always set up handlers before requesting service name
conn.request_name("org.mpris.MediaPlayer2.audrey")
.await
.expect("could not register name in session bus");
}
),
async {
loop {
conn.executor().tick().await;
}
}
));
// run this in glib's main loop
loop {
conn.executor().tick().await;
}
);
});
self.zbus_executor_loop_handle
.replace(Some(zbus_executor_loop_handle));
@ -502,7 +507,14 @@ impl Window {
let window: Self = glib::Object::builder().property("application", app).build();
window.imp().setup.set_window(&window);
window.imp().setup.load();
let initial_setup_handle = {
let setup = window.imp().setup.clone();
glib::spawn_future_local(async move { setup.load().await })
};
window
.imp()
.initial_setup_handle
.replace(Some(initial_setup_handle));
window
}