Skip to content

Commit 8d5cfd7

Browse files
wiiznokeswash2
authored andcommitted
fmt
1 parent d2cd4f2 commit 8d5cfd7

File tree

4 files changed

+42
-46
lines changed

4 files changed

+42
-46
lines changed

bin/src/main.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use pop_launcher_toolkit::plugins;
55
use pop_launcher_toolkit::service;
66

77
use mimalloc::MiMalloc;
8+
use tracing::info;
89

910
#[global_allocator]
1011
static GLOBAL: MiMalloc = MiMalloc;
@@ -17,6 +18,8 @@ async fn main() {
1718

1819
init_logging(cmd);
1920

21+
info!("starting {}", cmd);
22+
2023
match cmd {
2124
"calc" => plugins::calc::main().await,
2225
"desktop-entries" => plugins::desktop_entries::main().await,
@@ -38,7 +41,8 @@ async fn main() {
3841
}
3942

4043
fn init_logging(cmd: &str) {
41-
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
44+
use tracing_subscriber::prelude::*;
45+
use tracing_subscriber::{fmt, EnvFilter};
4246

4347
let logdir = match dirs::state_dir() {
4448
Some(dir) => dir.join("pop-launcher/"),
@@ -61,24 +65,25 @@ fn init_logging(cmd: &str) {
6165
}
6266
}
6367

68+
let fmt_layer = tracing_subscriber::fmt::layer()
69+
.with_target(false)
70+
.with_timer(fmt::time::ChronoLocal::new("%T".into()))
71+
.with_writer(file);
72+
6473
let filter_layer = EnvFilter::try_from_default_env()
6574
.or_else(|_| EnvFilter::try_new("warn"))
6675
.unwrap();
6776

68-
let fmt_layer = fmt::layer().with_target(false).with_writer(file);
77+
let registry = tracing_subscriber::registry()
78+
.with(fmt_layer)
79+
.with(filter_layer);
6980

7081
// would be nice to implement this tracing issue
7182
// for journald https://github.com/tokio-rs/tracing/issues/2348
72-
if let Ok(journal_layer) = tracing_journald::layer() {
73-
tracing_subscriber::registry()
74-
.with(journal_layer)
75-
.with(filter_layer)
76-
.init();
83+
if let Ok(journald_layer) = tracing_journald::layer() {
84+
registry.with(journald_layer).init();
7785
} else {
78-
tracing_subscriber::registry()
79-
.with(fmt_layer)
80-
.with(filter_layer)
81-
.init();
86+
registry.init();
8287
}
8388
}
8489
}

plugins/src/cosmic_toplevel/mod.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use cctk::{cosmic_protocols, sctk::reexports::calloop, toplevel_info::ToplevelIn
66
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
77
use fde::DesktopEntry;
88
use freedesktop_desktop_entry as fde;
9-
use tracing::{debug, info};
9+
use tracing::{debug, error, info, warn};
1010

11-
use crate::desktop_entries::utils::get_description;
11+
use crate::desktop_entries::utils::{get_description, is_session_cosmic};
1212
use crate::send;
1313
use futures::{
1414
channel::mpsc,
@@ -27,11 +27,9 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
2727
use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
2828

2929
pub async fn main() {
30-
info!("starting cosmic-toplevel");
31-
3230
let mut tx = async_stdout();
3331

34-
if !session_is_cosmic() {
32+
if !is_session_cosmic() {
3533
send(&mut tx, PluginResponse::Deactivate).await;
3634
return;
3735
}
@@ -50,12 +48,12 @@ pub async fn main() {
5048
match request {
5149
Ok(request) => match request {
5250
Request::Activate(id) => {
53-
tracing::info!("activating {id}");
51+
debug!("activating {id}");
5452
app.activate(id);
5553
}
5654
Request::Quit(id) => app.quit(id),
5755
Request::Search(query) => {
58-
tracing::info!("searching {query}");
56+
debug!("searching {query}");
5957
app.search(&query).await;
6058
// clear the ids to ignore, as all just sent are valid
6159
app.ids_to_ignore.clear();
@@ -64,7 +62,7 @@ pub async fn main() {
6462
_ => (),
6563
},
6664
Err(why) => {
67-
tracing::error!("malformed JSON request: {}", why);
65+
error!("malformed JSON request: {}", why);
6866
}
6967
};
7068
}
@@ -74,7 +72,7 @@ pub async fn main() {
7472

7573
match event {
7674
ToplevelEvent::Add(handle, info) => {
77-
tracing::info!("add {}", &info.app_id);
75+
debug!("add {}", &info.app_id);
7876
app.toplevels.retain(|t| t.0 != handle);
7977
app.toplevels.push_front((handle, info));
8078
}
@@ -84,7 +82,7 @@ pub async fn main() {
8482
// ignore requests for this id until after the next search
8583
app.ids_to_ignore.push(handle.id().protocol_id());
8684
} else {
87-
tracing::warn!("ToplevelEvent::Remove, no toplevel found");
85+
warn!("ToplevelEvent::Remove, no toplevel found");
8886
}
8987
}
9088
ToplevelEvent::Update(handle, info) => {
@@ -93,14 +91,14 @@ pub async fn main() {
9391

9492
if let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
9593
if info.state.contains(&State::Activated) {
96-
tracing::debug!("Update {:?}: push front", &info.app_id);
94+
debug!("Update {:?}: push front", &info.app_id);
9795
app.toplevels.remove(pos);
9896
app.toplevels.push_front((handle, info));
9997
} else {
10098
app.toplevels[pos].1 = info;
10199
}
102100
} else {
103-
tracing::warn!("ToplevelEvent::Update, no toplevel found");
101+
warn!("ToplevelEvent::Update, no toplevel found");
104102
app.toplevels.push_front((handle, info));
105103
}
106104
}
@@ -115,7 +113,7 @@ struct App<W> {
115113
locales: Vec<String>,
116114
desktop_entries: Vec<DesktopEntry<'static>>,
117115
ids_to_ignore: Vec<u32>,
118-
// XXX: use LinkedList?
116+
// XXX: use LinkedList, and Box the tuple because it will be re ordered a lot?
119117
toplevels: VecDeque<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
120118
calloop_tx: calloop::channel::Sender<ToplevelAction>,
121119
tx: W,
@@ -149,7 +147,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
149147
}
150148

151149
fn activate(&mut self, id: u32) {
152-
tracing::info!("requested to activate: {id}");
150+
info!("requested to activate: {id}");
153151
if self.ids_to_ignore.contains(&id) {
154152
return;
155153
}
@@ -160,7 +158,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
160158
None
161159
}
162160
}) {
163-
tracing::info!("activating: {id}");
161+
info!("activating: {id}");
164162
let _res = self.calloop_tx.send(ToplevelAction::Activate(handle));
165163
}
166164
}
@@ -240,12 +238,3 @@ impl<W: AsyncWrite + Unpin> App<W> {
240238
let _ = self.tx.flush().await;
241239
}
242240
}
243-
244-
#[must_use]
245-
fn session_is_cosmic() -> bool {
246-
if let Ok(var) = std::env::var("XDG_CURRENT_DESKTOP") {
247-
return var.contains("COSMIC");
248-
}
249-
250-
false
251-
}

plugins/src/desktop_entries/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ use futures::StreamExt;
99
use pop_launcher::*;
1010
use std::borrow::Cow;
1111
use tokio::io::AsyncWrite;
12-
use tracing::info;
13-
use utils::get_description;
12+
use utils::{get_description, is_session_cosmic};
1413

1514
pub(crate) mod utils;
1615

1716
pub async fn main() {
18-
info!("starting desktop entries");
1917
let mut app = App::new(async_stdout());
2018
app.reload().await;
2119

@@ -53,13 +51,9 @@ struct App<W> {
5351

5452
impl<W: AsyncWrite + Unpin> App<W> {
5553
fn new(tx: W) -> Self {
56-
let current_desktop = fde::current_desktop();
5754
Self {
5855
current_desktop: fde::current_desktop(),
59-
is_desktop_cosmic: current_desktop
60-
.unwrap_or_default()
61-
.iter()
62-
.any(|e| e == "cosmic"),
56+
is_desktop_cosmic: is_session_cosmic(),
6357
desktop_entries: Vec::new(),
6458
locales: fde::get_languages_from_env(),
6559
tx,
@@ -88,9 +82,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
8882
// placing a modified copy in ~/.local/share/applications/
8983
deduplicator.insert(appid.to_owned());
9084

91-
if de.name(&self.locales).is_none() {
92-
return None;
93-
}
85+
de.name(&self.locales)?;
9486

9587
match de.exec() {
9688
Some(exec) => match exec.split_ascii_whitespace().next() {

plugins/src/desktop_entries/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ pub fn get_description<'a>(de: &'a DesktopEntry<'a>, locales: &[String]) -> Stri
3636
None => desc_source,
3737
}
3838
}
39+
40+
// todo: cache
41+
#[must_use]
42+
pub fn is_session_cosmic() -> bool {
43+
if let Ok(var) = std::env::var("XDG_CURRENT_DESKTOP") {
44+
return var.contains("COSMIC");
45+
}
46+
47+
false
48+
}

0 commit comments

Comments
 (0)