2022-04-27 20:08:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2024-04-24 09:34:46 -07:00
|
|
|
use crate::state::Common;
|
2025-10-16 18:53:57 +02:00
|
|
|
use libsystemd::daemon::{NotifyState, booted, notify};
|
2022-04-27 20:08:05 +02:00
|
|
|
use std::process::Command;
|
2023-02-24 17:41:52 +01:00
|
|
|
use tracing::{error, warn};
|
2022-04-27 20:08:05 +02:00
|
|
|
|
2024-04-24 09:34:46 -07:00
|
|
|
pub fn ready(common: &Common) {
|
2022-04-27 20:08:05 +02:00
|
|
|
if booted() {
|
|
|
|
|
match Command::new("systemctl")
|
2023-01-24 18:08:52 +01:00
|
|
|
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
|
2024-04-24 09:34:46 -07:00
|
|
|
.env("WAYLAND_DISPLAY", &common.socket)
|
2023-01-24 18:08:52 +01:00
|
|
|
.env(
|
|
|
|
|
"DISPLAY",
|
2025-10-16 13:50:32 +02:00
|
|
|
common
|
2023-01-24 18:08:52 +01:00
|
|
|
.xwayland_state
|
2023-03-07 20:28:41 +01:00
|
|
|
.as_ref()
|
2023-01-25 13:20:17 +01:00
|
|
|
.map(|s| format!(":{}", s.display))
|
2025-10-16 13:50:32 +02:00
|
|
|
.unwrap_or_default(),
|
2023-01-24 18:08:52 +01:00
|
|
|
)
|
2022-04-27 20:08:05 +02:00
|
|
|
.status()
|
|
|
|
|
{
|
2022-05-03 13:37:51 +02:00
|
|
|
Ok(x) if x.success() => {}
|
2023-02-24 17:41:52 +01:00
|
|
|
Ok(x) => warn!(
|
|
|
|
|
exit_code = ?x.code(),
|
|
|
|
|
"Failed to import WAYLAND_DISPLAY/DISPLAY into systemd",
|
2022-05-03 13:37:51 +02:00
|
|
|
),
|
2023-02-24 17:41:52 +01:00
|
|
|
Err(err) => error!(?err, "Failed to run systemctl although booted with systemd",),
|
2022-04-27 20:08:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Err(err) = notify(false, &[NotifyState::Ready]) {
|
2023-02-24 17:41:52 +01:00
|
|
|
error!(?err, "Failed to notify systemd");
|
2022-04-27 20:08:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-05-03 13:37:51 +02:00
|
|
|
}
|