2022-07-22 11:48:03 -04:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2023-10-31 11:38:33 -04:00
|
|
|
use tokio::sync::mpsc;
|
2024-06-20 14:32:09 -04:00
|
|
|
use zbus::interface;
|
2022-07-22 11:48:03 -04:00
|
|
|
|
2023-10-31 11:38:33 -04:00
|
|
|
pub enum SessionRequest {
|
|
|
|
|
Exit,
|
|
|
|
|
Restart,
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 11:48:03 -04:00
|
|
|
pub struct SessionService {
|
2023-10-31 11:38:33 -04:00
|
|
|
pub session_tx: mpsc::Sender<SessionRequest>,
|
2022-07-22 11:48:03 -04:00
|
|
|
}
|
|
|
|
|
|
2024-06-20 14:32:09 -04:00
|
|
|
#[interface(name = "com.system76.CosmicSession")]
|
2022-07-22 11:48:03 -04:00
|
|
|
impl SessionService {
|
2023-10-31 11:38:33 -04:00
|
|
|
async fn exit(&mut self) {
|
|
|
|
|
warn!("exiting session");
|
|
|
|
|
_ = self.session_tx.send(SessionRequest::Exit).await;
|
2022-07-22 11:48:03 -04:00
|
|
|
}
|
2022-07-25 12:34:21 -04:00
|
|
|
|
2023-10-31 11:38:33 -04:00
|
|
|
async fn restart(&self) {
|
2022-07-25 12:34:21 -04:00
|
|
|
warn!("restarting session");
|
2023-10-31 11:38:33 -04:00
|
|
|
_ = self.session_tx.send(SessionRequest::Restart).await;
|
2022-07-25 12:34:21 -04:00
|
|
|
}
|
2022-07-22 11:48:03 -04:00
|
|
|
}
|