Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ target := if debug == '1' { 'debug' } else { 'release' }
vendor_args := if vendor == '1' { '--frozen --offline' } else { '' }
debug_args := if debug == '1' { '' } else { '--release' }
cargo_args := vendor_args + ' ' + debug_args
xdp_cosmic := '/usr/libexec/xdg-desktop-portal-cosmic'
orca := '/usr/bin/orca'
cosmic_dconf_profile := prefix + '/share/dconf/profile/cosmic'

Expand All @@ -21,7 +20,7 @@ applicationdir := rootdir / prefix + '/share/applications'
all: _extract_vendor build

build:
XDP_COSMIC={{xdp_cosmic}} ORCA={{orca}} cargo build {{cargo_args}}
ORCA={{orca}} cargo build {{cargo_args}}

# Installs files into the system
install:
Expand Down
142 changes: 31 additions & 111 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use color_eyre::{Result, eyre::WrapErr};
use comp::create_privileged_socket;
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
use futures_util::StreamExt;
use futures_util::stream::FuturesUnordered;
#[cfg(feature = "autostart")]
use itertools::Itertools;
use launch_pad::{ProcessManager, process::Process};
Expand All @@ -32,6 +33,7 @@ use std::{
};
#[cfg(feature = "systemd")]
use systemd::{get_systemd_env, is_systemd_used, spawn_scope};
use tokio::sync::mpsc::UnboundedSender;
use tokio::{
net::UnixStream,
sync::{
Expand All @@ -46,7 +48,6 @@ use tracing::{Instrument, metadata::LevelFilter};
use tracing_subscriber::{EnvFilter, fmt, prelude::*};

use crate::notifications::notifications_process;
const XDP_COSMIC: Option<&'static str> = option_env!("XDP_COSMIC");
#[cfg(feature = "autostart")]
const AUTOSTART_DIR: &'static str = "autostart";
#[cfg(feature = "autostart")]
Expand Down Expand Up @@ -339,116 +340,7 @@ async fn start(
);
drop(guard);

let span = info_span!(parent: None, "cosmic-app-library");
start_component(
"cosmic-app-library",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-launcher");
start_component(
"cosmic-launcher",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-workspaces");
start_component(
"cosmic-workspaces",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-osd");
start_component(
"cosmic-osd",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-bg");
start_component(
"cosmic-bg",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-greeter");
start_component(
"cosmic-greeter",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-files-applet");
start_component(
"cosmic-files-applet",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

let span = info_span!(parent: None, "cosmic-idle");
start_component(
"cosmic-idle",
span,
&process_manager,
&env_vars,
&socket_tx,
Vec::new(),
)
.await;

if env::var("XDG_CURRENT_DESKTOP").as_deref() == Ok("COSMIC") {
let span = info_span!(parent: None, "xdg-desktop-portal-cosmic");
let mut sockets = Vec::with_capacity(1);
let extra_env = Vec::with_capacity(1);
let portal_extras =
if let Ok((mut env, fd)) = create_privileged_socket(&mut sockets, &extra_env) {
let mut env = env.remove(0);
env.0 = "PORTAL_WAYLAND_SOCKET".to_string();
vec![(fd, env, sockets.remove(0))]
} else {
Vec::new()
};
start_component(
XDP_COSMIC.unwrap_or("/usr/libexec/xdg-desktop-portal-cosmic"),
span,
&process_manager,
&env_vars,
&socket_tx,
portal_extras,
)
.await;
}
spawn_components(&process_manager, &env_vars, &socket_tx).await;

#[cfg(feature = "autostart")]
if !*is_systemd_used() {
Expand Down Expand Up @@ -600,6 +492,34 @@ async fn start(
Ok(status)
}

/// Spawn desktop components concurrently with the process manager.
async fn spawn_components(
process_manager: &ProcessManager,
env_vars: &[(String, String)],
socket_tx: &UnboundedSender<Vec<UnixStream>>,
) {
let components = [
"cosmic-app-library",
"cosmic-bg",
"cosmic-files-applet",
"cosmic-greeter",
"cosmic-idle",
"cosmic-launcher",
"cosmic-osd",
"cosmic-workspaces",
];

components
.into_iter()
.map(|name| async move {
let span = info_span!(parent: None, "{}", name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does creating an info_span! in a loop like this work properly?

https://docs.rs/tracing/0.1.41/tracing/struct.Span.html takes &'static Metadata<'static> , and macro_rules! span in https://github.com/tokio-rs/tracing/blob/main/tracing/src/macros.rs includes a definition of a static.

start_component(name, span, process_manager, env_vars, socket_tx, Vec::new()).await;
})
.collect::<FuturesUnordered<_>>()
.collect::<Vec<()>>()
.await;
}

async fn start_component(
cmd: impl Into<Cow<'static, str>>,
span: tracing::Span,
Expand Down