refactor: fully restart after the compositor exits

This commit is contained in:
Ashley Wulber 2023-10-31 11:38:33 -04:00 committed by Ashley Wulber
parent 9a94c8f516
commit fcb16e29c1
3 changed files with 103 additions and 65 deletions

View file

@ -1,25 +1,25 @@
// SPDX-License-Identifier: GPL-3.0-only
use tokio::sync::oneshot;
use tokio::sync::mpsc;
use zbus::dbus_interface;
pub enum SessionRequest {
Exit,
Restart,
}
pub struct SessionService {
pub exit_tx: Option<oneshot::Sender<()>>,
pub session_tx: mpsc::Sender<SessionRequest>,
}
#[dbus_interface(name = "com.system76.CosmicSession")]
impl SessionService {
fn exit(&mut self) {
match self.exit_tx.take() {
Some(tx) => {
tx.send(()).ok();
}
None => {
warn!("previously failed to properly exit session");
}
}
async fn exit(&mut self) {
warn!("exiting session");
_ = self.session_tx.send(SessionRequest::Exit).await;
}
fn restart(&self) {
async fn restart(&self) {
warn!("restarting session");
_ = self.session_tx.send(SessionRequest::Restart).await;
}
}