2022-04-27 20:08:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2022-05-03 13:37:51 +02:00
|
|
|
use crate::state::State;
|
2022-04-27 20:08:05 +02:00
|
|
|
use libsystemd::daemon::{booted, notify, NotifyState};
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
pub fn ready(state: &State) {
|
|
|
|
|
if booted() {
|
|
|
|
|
match Command::new("systemctl")
|
2023-01-24 18:08:52 +01:00
|
|
|
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
|
2022-04-27 20:08:05 +02:00
|
|
|
.env("WAYLAND_DISPLAY", &state.common.socket)
|
2023-01-24 18:08:52 +01:00
|
|
|
.env(
|
|
|
|
|
"DISPLAY",
|
|
|
|
|
&state
|
|
|
|
|
.common
|
|
|
|
|
.xwayland_state
|
|
|
|
|
.values()
|
|
|
|
|
.find_map(|s| s.display.map(|v| format!(":{}", v)))
|
|
|
|
|
.unwrap_or(String::new()),
|
|
|
|
|
)
|
2022-04-27 20:08:05 +02:00
|
|
|
.status()
|
|
|
|
|
{
|
2022-05-03 13:37:51 +02:00
|
|
|
Ok(x) if x.success() => {}
|
|
|
|
|
Ok(x) => slog_scope::warn!(
|
2023-01-24 18:08:52 +01:00
|
|
|
"Failed to import WAYLAND_DISPLAY/DISPLAY into systemd (exit code {:?})",
|
2022-05-03 13:37:51 +02:00
|
|
|
x.code()
|
|
|
|
|
),
|
|
|
|
|
Err(err) => slog_scope::error!(
|
|
|
|
|
"Failed to run systemctl although booted with systemd: {}",
|
|
|
|
|
err
|
|
|
|
|
),
|
2022-04-27 20:08:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Err(err) = notify(false, &[NotifyState::Ready]) {
|
|
|
|
|
slog_scope::error!("Failed to notify systemd: {}", err);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-03 13:37:51 +02:00
|
|
|
}
|