azalea_shell/service/dbus/login/
mod.rs

1pub mod proxy;
2
3use proxy::LoginManagerProxy;
4use tokio::sync::broadcast;
5
6#[derive(azalea_derive::StaticServiceManager)]
7pub struct Service {
8    #[allow(dead_code)]
9    proxy: LoginManagerProxy<'static>,
10}
11
12#[derive(Default, Clone)]
13pub struct Init {
14    pub dbus_connection: Option<zbus::Connection>,
15}
16
17#[derive(Clone, Debug)]
18pub enum Input {
19    PowerOff,
20    Reboot,
21    Suspend,
22    Hibernate,
23}
24
25pub enum Event {}
26
27#[derive(Clone, Debug)]
28pub enum Output {}
29
30impl azalea_service::Service for Service {
31    type Init = Init;
32    type Input = Input;
33    type Event = Event;
34    type Output = Output;
35
36    const DISABLE_EVENTS: bool = true;
37
38    async fn new(
39        init: Self::Init,
40        _input: flume::Sender<Self::Input>,
41        _: broadcast::Sender<Self::Output>,
42    ) -> Self {
43        let connection = init
44            .dbus_connection
45            .unwrap_or(zbus::Connection::system().await.unwrap());
46
47        let proxy = LoginManagerProxy::new(&connection).await.unwrap();
48
49        Self { proxy }
50    }
51
52    async fn message(
53        &mut self,
54        input: Self::Input,
55        _output_sender: &broadcast::Sender<Self::Output>,
56    ) {
57        match input {
58            Input::PowerOff => drop(self.proxy.power_off(true).await),
59            Input::Reboot => drop(self.proxy.reboot(true).await),
60            Input::Suspend => drop(self.proxy.suspend(true).await),
61            Input::Hibernate => drop(self.proxy.hibernate(true).await),
62        }
63    }
64}