Skip to content

Commit

Permalink
startup: Add spinloop until deamon is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Jun 4, 2024
1 parent 918bf9c commit dcc9de9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ repository = "https://github.com/Xetibo/ReSet"
license = "GPL-3.0-or-later"

[dependencies]
reset_daemon = "2.1.0"
# reset_daemon = "2.1.1"
reset_daemon = { git = "https://github.com/Xetibo/ReSet-Daemon", branch = "dev" }
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"] }
Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[tokio::main]
async fn main() {
tokio::task::spawn(daemon_check());
let ready = Arc::new(AtomicBool::new(false));
tokio::task::spawn(daemon_check(ready.clone()));
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
hint::spin_loop();
}
gio::resources_register_include!("src.templates.gresource")
.expect("Failed to register resources.");
gio::resources_register_include!("src.icons.gresource").expect("Failed to register resources.");
Expand Down Expand Up @@ -67,19 +71,15 @@ fn shutdown(_: &Application) {
});
}

async fn daemon_check() {
let handle = thread::spawn(|| {
async fn daemon_check(ready: Arc<AtomicBool>) {
let handle = thread::spawn(move || {
let conn = Connection::new_session().unwrap();
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(100));
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(Some(ready.clone())).await;
}
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
hint::spin_loop();
run_daemon(Some(ready)).await;
}
}
15 changes: 11 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ async fn test_plugins() {
use crate::daemon_check;
use re_set_lib::utils::plugin::plugin_tests;
use re_set_lib::utils::plugin_setup::FRONTEND_PLUGINS;
use std::thread;
use std::time::Duration;
tokio::task::spawn(daemon_check());
thread::sleep(Duration::from_millis(2000));
use std::hint;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
let ready = Arc::new(AtomicBool::new(false));
let rc = tokio::runtime::Runtime::new().expect("Failed to create runtime");
rc.spawn(daemon_check(ready.clone()));
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
hint::spin_loop();
}
unsafe {
println!("pang");
for plugin in FRONTEND_PLUGINS.iter() {
let name = (plugin.frontend_name)();
let tests = (plugin.frontend_tests)();
plugin_tests(name, tests);
}
}
rc.shutdown_background();
}

0 comments on commit dcc9de9

Please sign in to comment.