From 918bf9c70ae1711779fc6fcbeab9b8a9c9430328 Mon Sep 17 00:00:00 2001 From: DashieTM Date: Tue, 4 Jun 2024 23:37:15 +0200 Subject: [PATCH] startup: Add spinloop until daemon is ready --- .direnv/flake-profile | 2 +- .direnv/flake-profile-10-link | 1 - .direnv/flake-profile-11-link | 1 + Cargo.lock | 8 ++++---- Cargo.toml | 2 +- flake.nix | 2 ++ src/main.rs | 9 ++++++++- 7 files changed, 17 insertions(+), 8 deletions(-) delete mode 120000 .direnv/flake-profile-10-link create mode 120000 .direnv/flake-profile-11-link diff --git a/.direnv/flake-profile b/.direnv/flake-profile index b9f8d1a..c7ae88b 120000 --- a/.direnv/flake-profile +++ b/.direnv/flake-profile @@ -1 +1 @@ -flake-profile-10-link \ No newline at end of file +flake-profile-11-link \ No newline at end of file diff --git a/.direnv/flake-profile-10-link b/.direnv/flake-profile-10-link deleted file mode 120000 index 6da5055..0000000 --- a/.direnv/flake-profile-10-link +++ /dev/null @@ -1 +0,0 @@ -/nix/store/q1w89c69h80a7vwlbqnsa396203k6hff-nix-shell-env \ No newline at end of file diff --git a/.direnv/flake-profile-11-link b/.direnv/flake-profile-11-link new file mode 120000 index 0000000..52e7a78 --- /dev/null +++ b/.direnv/flake-profile-11-link @@ -0,0 +1 @@ +/nix/store/51yb1yhqssknlmxvvscvj0cqbvs0z915-nix-shell-env \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 9545054..1a5bc88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -926,9 +926,9 @@ dependencies = [ [[package]] name = "re_set-lib" -version = "5.2.1" +version = "5.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01fb110dc5087cdb0d8df799c3855c13e4ecb41f987e9691bf3d101c2dad1b3a" +checksum = "77b4e5846cc4e5f6c51b60b16c2d51f282b5c407238b2e7077f6a0352b65d6cf" dependencies = [ "dbus", "dbus-crossroads", @@ -968,9 +968,9 @@ dependencies = [ [[package]] name = "reset_daemon" -version = "1.5.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e555b347b8b0b67081aeb570096338eae68a8db4b877661254ce17c59e5134dd" +checksum = "8cf329c1f14918f24d8d8f1674a16f5103208682f97b5d2bf1621b09c563c9cb" dependencies = [ "crossbeam", "dbus", diff --git a/Cargo.toml b/Cargo.toml index 559d755..f3a9f30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/Xetibo/ReSet" license = "GPL-3.0-or-later" [dependencies] -reset_daemon = "1.5.0" +reset_daemon = "2.1.0" re_set-lib = "5.2.1" # re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" } adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] } diff --git a/flake.nix b/flake.nix index 0baa555..9b92f41 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,8 @@ # (rust-bin.selectLatestNightlyWith # (toolchain: toolchain.default)) rust-bin.nightly."2024-05-10".default + rust-analyzer + clippy ]; }; diff --git a/src/main.rs b/src/main.rs index 156b953..4b9cfdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +use std::hint::{self}; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; use std::thread; use std::time::Duration; @@ -71,8 +74,12 @@ async fn daemon_check() { let res: Result<(), Error> = proxy.method_call(BASE, "RegisterClient", ("ReSet",)); res }); + let ready = Arc::new(AtomicBool::new(false)); let res = handle.join(); if res.unwrap().is_err() { - run_daemon().await; + run_daemon(Some(ready.clone())).await; + } + while !ready.load(std::sync::atomic::Ordering::SeqCst) { + hint::spin_loop(); } }