keep join handles to everything
This commit is contained in:
parent
226c8073d4
commit
88962c629c
4 changed files with 81 additions and 56 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -222,6 +222,7 @@ dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"chrono",
|
"chrono",
|
||||||
"event-listener",
|
"event-listener",
|
||||||
|
"futures",
|
||||||
"gettext-rs",
|
"gettext-rs",
|
||||||
"glib-build-tools",
|
"glib-build-tools",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
|
@ -634,6 +635,21 @@ dependencies = [
|
||||||
"percent-encoding",
|
"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]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.31"
|
version = "0.3.31"
|
||||||
|
@ -641,6 +657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -708,6 +725,7 @@ version = "0.3.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-macro",
|
"futures-macro",
|
||||||
|
|
|
@ -9,6 +9,7 @@ async-channel = "2.3.1"
|
||||||
base16ct = { version = "0.2.0", features = ["std"] }
|
base16ct = { version = "0.2.0", features = ["std"] }
|
||||||
chrono = { version = "0.4.38", features = ["serde"] }
|
chrono = { version = "0.4.38", features = ["serde"] }
|
||||||
event-listener = "5.3.1"
|
event-listener = "5.3.1"
|
||||||
|
futures = "0.3.31"
|
||||||
gettext-rs = { version = "0.7.2", features = ["gettext-system"] }
|
gettext-rs = { version = "0.7.2", features = ["gettext-system"] }
|
||||||
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_16"] }
|
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_16"] }
|
||||||
md-5 = { version = "0.10.6", features = ["asm"] }
|
md-5 = { version = "0.10.6", features = ["asm"] }
|
||||||
|
|
|
@ -139,42 +139,36 @@ impl Default for Setup {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Setup {
|
impl Setup {
|
||||||
pub fn load(&self) {
|
pub async fn load(&self) {
|
||||||
glib::spawn_future_local(glib::clone!(
|
self.set_server_url("");
|
||||||
#[weak(rename_to = self_)]
|
self.set_username("");
|
||||||
self,
|
self.set_password("");
|
||||||
async move {
|
self.set_authn_can_edit(false);
|
||||||
self_.set_server_url("");
|
self.set_authn_can_validate(false);
|
||||||
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
|
// TODO remove unwraps, make sure authn_can_edit is set back to true
|
||||||
let keyring = oo7::Keyring::new().await.unwrap();
|
let keyring = oo7::Keyring::new().await.unwrap();
|
||||||
let attributes = vec![("xdg:schema", crate::APP_ID)];
|
let attributes = vec![("xdg:schema", crate::APP_ID)];
|
||||||
let items = keyring.search_items(&attributes).await.unwrap();
|
let items = keyring.search_items(&attributes).await.unwrap();
|
||||||
|
|
||||||
if items.is_empty() {
|
if items.is_empty() {
|
||||||
// didn't find shit, leave all empty
|
// didn't find shit, leave all empty
|
||||||
// TODO: onboarding
|
// TODO: onboarding
|
||||||
self_.set_authn_can_edit(true);
|
self.set_authn_can_edit(true);
|
||||||
self_.set_authn_can_validate(true);
|
self.set_authn_can_validate(true);
|
||||||
} else {
|
} else {
|
||||||
let item = &items[0];
|
let item = &items[0];
|
||||||
let attributes = item.attributes().await.unwrap();
|
let attributes = item.attributes().await.unwrap();
|
||||||
|
|
||||||
self_.set_server_url(attributes["server-url"].clone());
|
self.set_server_url(attributes["server-url"].clone());
|
||||||
self_.set_username(attributes["username"].clone());
|
self.set_username(attributes["username"].clone());
|
||||||
// strip non-utf8 elements from the pw, i guess
|
// strip non-utf8 elements from the pw, i guess
|
||||||
self_.set_password(String::from_utf8_lossy(&item.secret().await.unwrap()));
|
self.set_password(String::from_utf8_lossy(&item.secret().await.unwrap()));
|
||||||
|
|
||||||
// first connection
|
// first connection
|
||||||
self_.set_authn_can_edit(true); // act as if the user had inputted this
|
self.set_authn_can_edit(true); // act as if the user had inputted this
|
||||||
self_.set_authn_can_validate(true);
|
self.set_authn_can_validate(true);
|
||||||
self_.imp().on_authn_validate_activated().await;
|
self.imp().on_authn_validate_activated().await;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ mod imp {
|
||||||
|
|
||||||
pub(super) queued_seek: Cell<Option<f64>>,
|
pub(super) queued_seek: Cell<Option<f64>>,
|
||||||
|
|
||||||
|
pub(crate) initial_setup_handle: RefCell<Option<JoinHandle<()>>>,
|
||||||
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
|
mpv_event_loop_handle: RefCell<Option<JoinHandle<()>>>, // really !, not ()
|
||||||
zbus_executor_loop_handle: RefCell<Option<JoinHandle<()>>>, // same
|
zbus_executor_loop_handle: RefCell<Option<JoinHandle<()>>>, // same
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,7 @@ mod imp {
|
||||||
|
|
||||||
queued_seek: Cell::new(None),
|
queued_seek: Cell::new(None),
|
||||||
|
|
||||||
|
initial_setup_handle: Default::default(),
|
||||||
mpv_event_loop_handle: Default::default(),
|
mpv_event_loop_handle: Default::default(),
|
||||||
zbus_executor_loop_handle: Default::default(),
|
zbus_executor_loop_handle: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -288,7 +290,8 @@ mod imp {
|
||||||
listener.await;
|
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
|
// set up mpris
|
||||||
let window = self.obj().clone();
|
let window = self.obj().clone();
|
||||||
|
@ -300,30 +303,32 @@ mod imp {
|
||||||
.await
|
.await
|
||||||
.expect("could not build connection to the session bus");
|
.expect("could not build connection to the session bus");
|
||||||
|
|
||||||
glib::spawn_future_local(glib::clone!(
|
futures::join!(
|
||||||
#[strong]
|
glib::clone!(
|
||||||
conn,
|
#[strong]
|
||||||
async move {
|
conn,
|
||||||
crate::Mpris::setup(conn.object_server(), &window)
|
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
|
.await
|
||||||
.expect("could not serve mpris");
|
.expect("could not serve mpris player");
|
||||||
/*
|
FIXME */
|
||||||
crate::mpris::Player::setup(conn.object_server(), &window.imp().playbin)
|
|
||||||
.await
|
|
||||||
.expect("could not serve mpris player");
|
|
||||||
FIXME */
|
|
||||||
|
|
||||||
// always set up handlers before requesting service name
|
// always set up handlers before requesting service name
|
||||||
conn.request_name("org.mpris.MediaPlayer2.audrey")
|
conn.request_name("org.mpris.MediaPlayer2.audrey")
|
||||||
.await
|
.await
|
||||||
.expect("could not register name in session bus");
|
.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
|
self.zbus_executor_loop_handle
|
||||||
.replace(Some(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();
|
let window: Self = glib::Object::builder().property("application", app).build();
|
||||||
|
|
||||||
window.imp().setup.set_window(&window);
|
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
|
window
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue