feat(ipc): connect GUI to daemon via D-Bus reload and live status detection

This commit is contained in:
2026-10-02 18:00:29 +03:00
parent 5ba2cea3d8
commit 9e44bd4b32
5 changed files with 72 additions and 10 deletions
+23 -9
View File
@@ -123,7 +123,14 @@ fn main() -> ExitCode {
if let Ok(backend) = blocker_platform_linux::kwin::KwinBackend::connect() {
println!("backend: kwin — native Wayland windows are visible");
let _keep_connection = watcher_conn;
run_loop(&rx, &schedules, &usage, &context, blocker_platform_linux::Enforcement::Freeze);
run_loop(
&rx,
&schedules,
&usage,
&context,
blocker_platform_linux::Enforcement::Freeze,
&path,
);
backend.shutdown();
return ExitCode::SUCCESS;
}
@@ -188,25 +195,32 @@ fn main() -> ExitCode {
/// charge, and this consumes it. Two blocked threads and no CPU between events.
fn run_loop(
rx: &std::sync::mpsc::Receiver<blocker_platform_linux::FocusEvent>,
schedules: &[blocker_core::model::Schedule],
schedules_initial: &[blocker_core::model::Schedule],
usage: &blocker_core::engine::UsageSnapshot,
context: &blocker_core::engine::PlatformContext,
enforcement: blocker_platform_linux::Enforcement,
db_path: &std::path::Path,
) {
let ctx = runner::LoopContext {
schedules,
usage,
platform_context: context,
boot_id: boot::current_boot_id(),
enforcement,
};
let mut current_schedules = schedules_initial.to_vec();
let clock = blocker_platform_linux::SystemMonotonic;
println!("enforcement: {enforcement:?}; entering the event loop");
'events: loop {
let ctx = runner::LoopContext {
schedules: &current_schedules,
usage,
platform_context: context,
boot_id: boot::current_boot_id(),
enforcement,
};
let (action, blocked, _) = runner::step(rx, &ctx, &clock, time::now());
if blocked > 0 {
println!("blocked an app ({action:?})");
}
if let Ok(store) = blocker_storage::Store::open(db_path) {
if let Ok(reloaded) = store.load_schedules() {
current_schedules = reloaded;
}
}
if action == runner::Action::Idle {
break 'events;
}
+2
View File
@@ -108,11 +108,13 @@ pub fn step(
let action = match &event {
FocusEvent::Activated(_) => Action::Focused,
FocusEvent::Cleared => Action::Unfocused,
FocusEvent::ReloadSchedules => Action::Idle,
};
let blocked = match &event {
FocusEvent::Activated(window) => enforce_if_blocked(window, ctx, clock, wall),
FocusEvent::Cleared => 0,
FocusEvent::ReloadSchedules => 0,
};
(action, blocked, wait)