feat: send notifications and panel Fds
This commit is contained in:
parent
f8bb451f68
commit
4c9557f42b
4 changed files with 406 additions and 263 deletions
616
Cargo.lock
generated
616
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -26,3 +26,4 @@ tracing = "0.1"
|
||||||
tracing-journald = "0.3"
|
tracing-journald = "0.3"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
zbus = { version = "2", default-features = false, features = ["tokio"] }
|
zbus = { version = "2", default-features = false, features = ["tokio"] }
|
||||||
|
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications"}
|
||||||
|
|
|
||||||
20
src/main.rs
20
src/main.rs
|
|
@ -3,12 +3,16 @@
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
mod comp;
|
mod comp;
|
||||||
|
mod notifications;
|
||||||
mod process;
|
mod process;
|
||||||
mod service;
|
mod service;
|
||||||
mod systemd;
|
mod systemd;
|
||||||
|
|
||||||
|
use std::os::fd::AsRawFd;
|
||||||
|
|
||||||
use async_signals::Signals;
|
use async_signals::Signals;
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{eyre::WrapErr, Result};
|
||||||
|
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use launch_pad::{process::Process, ProcessManager};
|
use launch_pad::{process::Process, ProcessManager};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
|
|
@ -62,15 +66,29 @@ async fn main() -> Result<()> {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
info!("got environmental variables: {:?}", env_vars);
|
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
|
process_manager
|
||||||
.start(
|
.start(
|
||||||
Process::new()
|
Process::new()
|
||||||
.with_executable("cosmic-panel")
|
.with_executable("cosmic-panel")
|
||||||
.with_env(env_vars.clone()),
|
.with_env(panel_env_vars.clone()),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to start panel");
|
.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");
|
let span = info_span!(parent: None, "cosmic-notifications");
|
||||||
start_component("cosmic-notifications", span, &process_manager, &env_vars).await;
|
start_component("cosmic-notifications", span, &process_manager, &env_vars).await;
|
||||||
|
|
||||||
|
|
|
||||||
32
src/notifications.rs
Normal file
32
src/notifications.rs
Normal 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))
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue