fmt
This commit is contained in:
parent
d2cd4f2251
commit
8d5cfd7ade
4 changed files with 42 additions and 46 deletions
|
|
@ -5,6 +5,7 @@ use pop_launcher_toolkit::plugins;
|
|||
use pop_launcher_toolkit::service;
|
||||
|
||||
use mimalloc::MiMalloc;
|
||||
use tracing::info;
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: MiMalloc = MiMalloc;
|
||||
|
|
@ -17,6 +18,8 @@ async fn main() {
|
|||
|
||||
init_logging(cmd);
|
||||
|
||||
info!("starting {}", cmd);
|
||||
|
||||
match cmd {
|
||||
"calc" => plugins::calc::main().await,
|
||||
"desktop-entries" => plugins::desktop_entries::main().await,
|
||||
|
|
@ -38,7 +41,8 @@ async fn main() {
|
|||
}
|
||||
|
||||
fn init_logging(cmd: &str) {
|
||||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::{fmt, EnvFilter};
|
||||
|
||||
let logdir = match dirs::state_dir() {
|
||||
Some(dir) => dir.join("pop-launcher/"),
|
||||
|
|
@ -61,24 +65,25 @@ fn init_logging(cmd: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
let fmt_layer = tracing_subscriber::fmt::layer()
|
||||
.with_target(false)
|
||||
.with_timer(fmt::time::ChronoLocal::new("%T".into()))
|
||||
.with_writer(file);
|
||||
|
||||
let filter_layer = EnvFilter::try_from_default_env()
|
||||
.or_else(|_| EnvFilter::try_new("warn"))
|
||||
.unwrap();
|
||||
|
||||
let fmt_layer = fmt::layer().with_target(false).with_writer(file);
|
||||
let registry = tracing_subscriber::registry()
|
||||
.with(fmt_layer)
|
||||
.with(filter_layer);
|
||||
|
||||
// would be nice to implement this tracing issue
|
||||
// for journald https://github.com/tokio-rs/tracing/issues/2348
|
||||
if let Ok(journal_layer) = tracing_journald::layer() {
|
||||
tracing_subscriber::registry()
|
||||
.with(journal_layer)
|
||||
.with(filter_layer)
|
||||
.init();
|
||||
if let Ok(journald_layer) = tracing_journald::layer() {
|
||||
registry.with(journald_layer).init();
|
||||
} else {
|
||||
tracing_subscriber::registry()
|
||||
.with(fmt_layer)
|
||||
.with(filter_layer)
|
||||
.init();
|
||||
registry.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ use cctk::{cosmic_protocols, sctk::reexports::calloop, toplevel_info::ToplevelIn
|
|||
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
|
||||
use fde::DesktopEntry;
|
||||
use freedesktop_desktop_entry as fde;
|
||||
use tracing::{debug, info};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
use crate::desktop_entries::utils::get_description;
|
||||
use crate::desktop_entries::utils::{get_description, is_session_cosmic};
|
||||
use crate::send;
|
||||
use futures::{
|
||||
channel::mpsc,
|
||||
|
|
@ -27,11 +27,9 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
|
|||
use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
|
||||
|
||||
pub async fn main() {
|
||||
info!("starting cosmic-toplevel");
|
||||
|
||||
let mut tx = async_stdout();
|
||||
|
||||
if !session_is_cosmic() {
|
||||
if !is_session_cosmic() {
|
||||
send(&mut tx, PluginResponse::Deactivate).await;
|
||||
return;
|
||||
}
|
||||
|
|
@ -50,12 +48,12 @@ pub async fn main() {
|
|||
match request {
|
||||
Ok(request) => match request {
|
||||
Request::Activate(id) => {
|
||||
tracing::info!("activating {id}");
|
||||
debug!("activating {id}");
|
||||
app.activate(id);
|
||||
}
|
||||
Request::Quit(id) => app.quit(id),
|
||||
Request::Search(query) => {
|
||||
tracing::info!("searching {query}");
|
||||
debug!("searching {query}");
|
||||
app.search(&query).await;
|
||||
// clear the ids to ignore, as all just sent are valid
|
||||
app.ids_to_ignore.clear();
|
||||
|
|
@ -64,7 +62,7 @@ pub async fn main() {
|
|||
_ => (),
|
||||
},
|
||||
Err(why) => {
|
||||
tracing::error!("malformed JSON request: {}", why);
|
||||
error!("malformed JSON request: {}", why);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -74,7 +72,7 @@ pub async fn main() {
|
|||
|
||||
match event {
|
||||
ToplevelEvent::Add(handle, info) => {
|
||||
tracing::info!("add {}", &info.app_id);
|
||||
debug!("add {}", &info.app_id);
|
||||
app.toplevels.retain(|t| t.0 != handle);
|
||||
app.toplevels.push_front((handle, info));
|
||||
}
|
||||
|
|
@ -84,7 +82,7 @@ pub async fn main() {
|
|||
// ignore requests for this id until after the next search
|
||||
app.ids_to_ignore.push(handle.id().protocol_id());
|
||||
} else {
|
||||
tracing::warn!("ToplevelEvent::Remove, no toplevel found");
|
||||
warn!("ToplevelEvent::Remove, no toplevel found");
|
||||
}
|
||||
}
|
||||
ToplevelEvent::Update(handle, info) => {
|
||||
|
|
@ -93,14 +91,14 @@ pub async fn main() {
|
|||
|
||||
if let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
|
||||
if info.state.contains(&State::Activated) {
|
||||
tracing::debug!("Update {:?}: push front", &info.app_id);
|
||||
debug!("Update {:?}: push front", &info.app_id);
|
||||
app.toplevels.remove(pos);
|
||||
app.toplevels.push_front((handle, info));
|
||||
} else {
|
||||
app.toplevels[pos].1 = info;
|
||||
}
|
||||
} else {
|
||||
tracing::warn!("ToplevelEvent::Update, no toplevel found");
|
||||
warn!("ToplevelEvent::Update, no toplevel found");
|
||||
app.toplevels.push_front((handle, info));
|
||||
}
|
||||
}
|
||||
|
|
@ -115,7 +113,7 @@ struct App<W> {
|
|||
locales: Vec<String>,
|
||||
desktop_entries: Vec<DesktopEntry<'static>>,
|
||||
ids_to_ignore: Vec<u32>,
|
||||
// XXX: use LinkedList?
|
||||
// XXX: use LinkedList, and Box the tuple because it will be re ordered a lot?
|
||||
toplevels: VecDeque<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
|
||||
calloop_tx: calloop::channel::Sender<ToplevelAction>,
|
||||
tx: W,
|
||||
|
|
@ -149,7 +147,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
|||
}
|
||||
|
||||
fn activate(&mut self, id: u32) {
|
||||
tracing::info!("requested to activate: {id}");
|
||||
info!("requested to activate: {id}");
|
||||
if self.ids_to_ignore.contains(&id) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -160,7 +158,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
|||
None
|
||||
}
|
||||
}) {
|
||||
tracing::info!("activating: {id}");
|
||||
info!("activating: {id}");
|
||||
let _res = self.calloop_tx.send(ToplevelAction::Activate(handle));
|
||||
}
|
||||
}
|
||||
|
|
@ -240,12 +238,3 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
|||
let _ = self.tx.flush().await;
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn session_is_cosmic() -> bool {
|
||||
if let Ok(var) = std::env::var("XDG_CURRENT_DESKTOP") {
|
||||
return var.contains("COSMIC");
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,11 @@ use futures::StreamExt;
|
|||
use pop_launcher::*;
|
||||
use std::borrow::Cow;
|
||||
use tokio::io::AsyncWrite;
|
||||
use tracing::info;
|
||||
use utils::get_description;
|
||||
use utils::{get_description, is_session_cosmic};
|
||||
|
||||
pub(crate) mod utils;
|
||||
|
||||
pub async fn main() {
|
||||
info!("starting desktop entries");
|
||||
let mut app = App::new(async_stdout());
|
||||
app.reload().await;
|
||||
|
||||
|
|
@ -53,13 +51,9 @@ struct App<W> {
|
|||
|
||||
impl<W: AsyncWrite + Unpin> App<W> {
|
||||
fn new(tx: W) -> Self {
|
||||
let current_desktop = fde::current_desktop();
|
||||
Self {
|
||||
current_desktop: fde::current_desktop(),
|
||||
is_desktop_cosmic: current_desktop
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.any(|e| e == "cosmic"),
|
||||
is_desktop_cosmic: is_session_cosmic(),
|
||||
desktop_entries: Vec::new(),
|
||||
locales: fde::get_languages_from_env(),
|
||||
tx,
|
||||
|
|
@ -88,9 +82,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
|||
// placing a modified copy in ~/.local/share/applications/
|
||||
deduplicator.insert(appid.to_owned());
|
||||
|
||||
if de.name(&self.locales).is_none() {
|
||||
return None;
|
||||
}
|
||||
de.name(&self.locales)?;
|
||||
|
||||
match de.exec() {
|
||||
Some(exec) => match exec.split_ascii_whitespace().next() {
|
||||
|
|
|
|||
|
|
@ -36,3 +36,13 @@ pub fn get_description<'a>(de: &'a DesktopEntry<'a>, locales: &[String]) -> Stri
|
|||
None => desc_source,
|
||||
}
|
||||
}
|
||||
|
||||
// todo: cache
|
||||
#[must_use]
|
||||
pub fn is_session_cosmic() -> bool {
|
||||
if let Ok(var) = std::env::var("XDG_CURRENT_DESKTOP") {
|
||||
return var.contains("COSMIC");
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue