mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
startup: Add spinloop until deamon is ready
This commit is contained in:
parent
918bf9c70a
commit
dcc9de9230
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -968,9 +968,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reset_daemon"
|
name = "reset_daemon"
|
||||||
version = "2.1.0"
|
version = "2.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/Xetibo/ReSet-Daemon?branch=dev#ea5e866068fa991a1ca05c42c0707b93f8701413"
|
||||||
checksum = "8cf329c1f14918f24d8d8f1674a16f5103208682f97b5d2bf1621b09c563c9cb"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
"dbus",
|
"dbus",
|
||||||
|
|
|
@ -7,7 +7,8 @@ repository = "https://github.com/Xetibo/ReSet"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
|
||||||
[dependencies]
|
[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 = "5.2.1"
|
||||||
# re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" }
|
# re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" }
|
||||||
adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] }
|
adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] }
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -24,7 +24,11 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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")
|
gio::resources_register_include!("src.templates.gresource")
|
||||||
.expect("Failed to register resources.");
|
.expect("Failed to register resources.");
|
||||||
gio::resources_register_include!("src.icons.gresource").expect("Failed to register resources.");
|
gio::resources_register_include!("src.icons.gresource").expect("Failed to register resources.");
|
||||||
|
@ -67,19 +71,15 @@ fn shutdown(_: &Application) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn daemon_check() {
|
async fn daemon_check(ready: Arc<AtomicBool>) {
|
||||||
let handle = thread::spawn(|| {
|
let handle = thread::spawn(move || {
|
||||||
let conn = Connection::new_session().unwrap();
|
let conn = Connection::new_session().unwrap();
|
||||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(100));
|
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(100));
|
||||||
let res: Result<(), Error> = proxy.method_call(BASE, "RegisterClient", ("ReSet",));
|
let res: Result<(), Error> = proxy.method_call(BASE, "RegisterClient", ("ReSet",));
|
||||||
res
|
res
|
||||||
});
|
});
|
||||||
let ready = Arc::new(AtomicBool::new(false));
|
|
||||||
let res = handle.join();
|
let res = handle.join();
|
||||||
if res.unwrap().is_err() {
|
if res.unwrap().is_err() {
|
||||||
run_daemon(Some(ready.clone())).await;
|
run_daemon(Some(ready)).await;
|
||||||
}
|
|
||||||
while !ready.load(std::sync::atomic::Ordering::SeqCst) {
|
|
||||||
hint::spin_loop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
src/tests.rs
15
src/tests.rs
|
@ -4,15 +4,22 @@ async fn test_plugins() {
|
||||||
use crate::daemon_check;
|
use crate::daemon_check;
|
||||||
use re_set_lib::utils::plugin::plugin_tests;
|
use re_set_lib::utils::plugin::plugin_tests;
|
||||||
use re_set_lib::utils::plugin_setup::FRONTEND_PLUGINS;
|
use re_set_lib::utils::plugin_setup::FRONTEND_PLUGINS;
|
||||||
use std::thread;
|
use std::hint;
|
||||||
use std::time::Duration;
|
use std::sync::atomic::AtomicBool;
|
||||||
tokio::task::spawn(daemon_check());
|
use std::sync::Arc;
|
||||||
thread::sleep(Duration::from_millis(2000));
|
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 {
|
unsafe {
|
||||||
|
println!("pang");
|
||||||
for plugin in FRONTEND_PLUGINS.iter() {
|
for plugin in FRONTEND_PLUGINS.iter() {
|
||||||
let name = (plugin.frontend_name)();
|
let name = (plugin.frontend_name)();
|
||||||
let tests = (plugin.frontend_tests)();
|
let tests = (plugin.frontend_tests)();
|
||||||
plugin_tests(name, tests);
|
plugin_tests(name, tests);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rc.shutdown_background();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue