feat: send notifications and panel Fds

This commit is contained in:
Ashley Wulber 2023-06-27 15:26:52 -04:00 committed by Ashley Wulber
parent f8bb451f68
commit 4c9557f42b
4 changed files with 406 additions and 263 deletions

616
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -26,3 +26,4 @@ tracing = "0.1"
tracing-journald = "0.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
zbus = { version = "2", default-features = false, features = ["tokio"] }
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications"}

View file

@ -3,12 +3,16 @@
extern crate tracing;
mod comp;
mod notifications;
mod process;
mod service;
mod systemd;
use std::os::fd::AsRawFd;
use async_signals::Signals;
use color_eyre::{eyre::WrapErr, Result};
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
use futures_util::StreamExt;
use launch_pad::{process::Process, ProcessManager};
use tokio::{
@ -62,15 +66,29 @@ async fn main() -> Result<()> {
.collect::<Vec<_>>();
info!("got environmental variables: {:?}", env_vars);
let (panel_notifications_fd, daemon_notifications_fd) =
notifications::create_socket().expect("Failed to create notification socket");
let mut panel_env_vars = env_vars.clone();
panel_env_vars.push((
PANEL_NOTIFICATIONS_FD.to_string(),
panel_notifications_fd.as_raw_fd().to_string(),
));
process_manager
.start(
Process::new()
.with_executable("cosmic-panel")
.with_env(env_vars.clone()),
.with_env(panel_env_vars.clone()),
)
.await
.expect("failed to start panel");
let mut daemon_env_vars = env_vars.clone();
daemon_env_vars.push((
DAEMON_NOTIFICATIONS_FD.to_string(),
daemon_notifications_fd.as_raw_fd().to_string(),
));
let span = info_span!(parent: None, "cosmic-notifications");
start_component("cosmic-notifications", span, &process_manager, &env_vars).await;

32
src/notifications.rs Normal file
View file

@ -0,0 +1,32 @@
use color_eyre::eyre::Context;
use color_eyre::Result;
use std::os::fd::OwnedFd;
use tokio::net::UnixStream;
pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
// Create a new pair of unnamed Unix sockets
let (sock_1, sock_2) = UnixStream::pair().wrap_err("failed to create socket pair")?;
// Turn the other socket into a non-blocking fd, which we can pass to the child
// process
let fd_1 = {
let std_stream = sock_1
.into_std()
.wrap_err("failed to convert client socket to std socket")?;
std_stream
.set_nonblocking(false)
.wrap_err("failed to mark client socket as blocking")?;
OwnedFd::from(std_stream)
};
let fd_2 = {
let std_stream = sock_2
.into_std()
.wrap_err("failed to convert client socket to std socket")?;
std_stream
.set_nonblocking(false)
.wrap_err("failed to mark client socket as blocking")?;
OwnedFd::from(std_stream)
};
Ok((fd_1, fd_2))
}