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 pop_launcher_toolkit::service;
|
||||||
|
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL: MiMalloc = MiMalloc;
|
static GLOBAL: MiMalloc = MiMalloc;
|
||||||
|
|
@ -17,6 +18,8 @@ async fn main() {
|
||||||
|
|
||||||
init_logging(cmd);
|
init_logging(cmd);
|
||||||
|
|
||||||
|
info!("starting {}", cmd);
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
"calc" => plugins::calc::main().await,
|
"calc" => plugins::calc::main().await,
|
||||||
"desktop-entries" => plugins::desktop_entries::main().await,
|
"desktop-entries" => plugins::desktop_entries::main().await,
|
||||||
|
|
@ -38,7 +41,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_logging(cmd: &str) {
|
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() {
|
let logdir = match dirs::state_dir() {
|
||||||
Some(dir) => dir.join("pop-launcher/"),
|
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()
|
let filter_layer = EnvFilter::try_from_default_env()
|
||||||
.or_else(|_| EnvFilter::try_new("warn"))
|
.or_else(|_| EnvFilter::try_new("warn"))
|
||||||
.unwrap();
|
.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
|
// would be nice to implement this tracing issue
|
||||||
// for journald https://github.com/tokio-rs/tracing/issues/2348
|
// for journald https://github.com/tokio-rs/tracing/issues/2348
|
||||||
if let Ok(journal_layer) = tracing_journald::layer() {
|
if let Ok(journald_layer) = tracing_journald::layer() {
|
||||||
tracing_subscriber::registry()
|
registry.with(journald_layer).init();
|
||||||
.with(journal_layer)
|
|
||||||
.with(filter_layer)
|
|
||||||
.init();
|
|
||||||
} else {
|
} else {
|
||||||
tracing_subscriber::registry()
|
registry.init();
|
||||||
.with(fmt_layer)
|
|
||||||
.with(filter_layer)
|
|
||||||
.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 cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
|
||||||
use fde::DesktopEntry;
|
use fde::DesktopEntry;
|
||||||
use freedesktop_desktop_entry as fde;
|
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 crate::send;
|
||||||
use futures::{
|
use futures::{
|
||||||
channel::mpsc,
|
channel::mpsc,
|
||||||
|
|
@ -27,11 +27,9 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
|
use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
|
||||||
|
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
info!("starting cosmic-toplevel");
|
|
||||||
|
|
||||||
let mut tx = async_stdout();
|
let mut tx = async_stdout();
|
||||||
|
|
||||||
if !session_is_cosmic() {
|
if !is_session_cosmic() {
|
||||||
send(&mut tx, PluginResponse::Deactivate).await;
|
send(&mut tx, PluginResponse::Deactivate).await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -50,12 +48,12 @@ pub async fn main() {
|
||||||
match request {
|
match request {
|
||||||
Ok(request) => match request {
|
Ok(request) => match request {
|
||||||
Request::Activate(id) => {
|
Request::Activate(id) => {
|
||||||
tracing::info!("activating {id}");
|
debug!("activating {id}");
|
||||||
app.activate(id);
|
app.activate(id);
|
||||||
}
|
}
|
||||||
Request::Quit(id) => app.quit(id),
|
Request::Quit(id) => app.quit(id),
|
||||||
Request::Search(query) => {
|
Request::Search(query) => {
|
||||||
tracing::info!("searching {query}");
|
debug!("searching {query}");
|
||||||
app.search(&query).await;
|
app.search(&query).await;
|
||||||
// clear the ids to ignore, as all just sent are valid
|
// clear the ids to ignore, as all just sent are valid
|
||||||
app.ids_to_ignore.clear();
|
app.ids_to_ignore.clear();
|
||||||
|
|
@ -64,7 +62,7 @@ pub async fn main() {
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
tracing::error!("malformed JSON request: {}", why);
|
error!("malformed JSON request: {}", why);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +72,7 @@ pub async fn main() {
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
ToplevelEvent::Add(handle, info) => {
|
ToplevelEvent::Add(handle, info) => {
|
||||||
tracing::info!("add {}", &info.app_id);
|
debug!("add {}", &info.app_id);
|
||||||
app.toplevels.retain(|t| t.0 != handle);
|
app.toplevels.retain(|t| t.0 != handle);
|
||||||
app.toplevels.push_front((handle, info));
|
app.toplevels.push_front((handle, info));
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +82,7 @@ pub async fn main() {
|
||||||
// ignore requests for this id until after the next search
|
// ignore requests for this id until after the next search
|
||||||
app.ids_to_ignore.push(handle.id().protocol_id());
|
app.ids_to_ignore.push(handle.id().protocol_id());
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("ToplevelEvent::Remove, no toplevel found");
|
warn!("ToplevelEvent::Remove, no toplevel found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToplevelEvent::Update(handle, info) => {
|
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 let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
|
||||||
if info.state.contains(&State::Activated) {
|
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.remove(pos);
|
||||||
app.toplevels.push_front((handle, info));
|
app.toplevels.push_front((handle, info));
|
||||||
} else {
|
} else {
|
||||||
app.toplevels[pos].1 = info;
|
app.toplevels[pos].1 = info;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("ToplevelEvent::Update, no toplevel found");
|
warn!("ToplevelEvent::Update, no toplevel found");
|
||||||
app.toplevels.push_front((handle, info));
|
app.toplevels.push_front((handle, info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +113,7 @@ struct App<W> {
|
||||||
locales: Vec<String>,
|
locales: Vec<String>,
|
||||||
desktop_entries: Vec<DesktopEntry<'static>>,
|
desktop_entries: Vec<DesktopEntry<'static>>,
|
||||||
ids_to_ignore: Vec<u32>,
|
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)>,
|
toplevels: VecDeque<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
|
||||||
calloop_tx: calloop::channel::Sender<ToplevelAction>,
|
calloop_tx: calloop::channel::Sender<ToplevelAction>,
|
||||||
tx: W,
|
tx: W,
|
||||||
|
|
@ -149,7 +147,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(&mut self, id: u32) {
|
fn activate(&mut self, id: u32) {
|
||||||
tracing::info!("requested to activate: {id}");
|
info!("requested to activate: {id}");
|
||||||
if self.ids_to_ignore.contains(&id) {
|
if self.ids_to_ignore.contains(&id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +158,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
tracing::info!("activating: {id}");
|
info!("activating: {id}");
|
||||||
let _res = self.calloop_tx.send(ToplevelAction::Activate(handle));
|
let _res = self.calloop_tx.send(ToplevelAction::Activate(handle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,12 +238,3 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
||||||
let _ = self.tx.flush().await;
|
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 pop_launcher::*;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use tokio::io::AsyncWrite;
|
use tokio::io::AsyncWrite;
|
||||||
use tracing::info;
|
use utils::{get_description, is_session_cosmic};
|
||||||
use utils::get_description;
|
|
||||||
|
|
||||||
pub(crate) mod utils;
|
pub(crate) mod utils;
|
||||||
|
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
info!("starting desktop entries");
|
|
||||||
let mut app = App::new(async_stdout());
|
let mut app = App::new(async_stdout());
|
||||||
app.reload().await;
|
app.reload().await;
|
||||||
|
|
||||||
|
|
@ -53,13 +51,9 @@ struct App<W> {
|
||||||
|
|
||||||
impl<W: AsyncWrite + Unpin> App<W> {
|
impl<W: AsyncWrite + Unpin> App<W> {
|
||||||
fn new(tx: W) -> Self {
|
fn new(tx: W) -> Self {
|
||||||
let current_desktop = fde::current_desktop();
|
|
||||||
Self {
|
Self {
|
||||||
current_desktop: fde::current_desktop(),
|
current_desktop: fde::current_desktop(),
|
||||||
is_desktop_cosmic: current_desktop
|
is_desktop_cosmic: is_session_cosmic(),
|
||||||
.unwrap_or_default()
|
|
||||||
.iter()
|
|
||||||
.any(|e| e == "cosmic"),
|
|
||||||
desktop_entries: Vec::new(),
|
desktop_entries: Vec::new(),
|
||||||
locales: fde::get_languages_from_env(),
|
locales: fde::get_languages_from_env(),
|
||||||
tx,
|
tx,
|
||||||
|
|
@ -88,9 +82,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
||||||
// placing a modified copy in ~/.local/share/applications/
|
// placing a modified copy in ~/.local/share/applications/
|
||||||
deduplicator.insert(appid.to_owned());
|
deduplicator.insert(appid.to_owned());
|
||||||
|
|
||||||
if de.name(&self.locales).is_none() {
|
de.name(&self.locales)?;
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
match de.exec() {
|
match de.exec() {
|
||||||
Some(exec) => match exec.split_ascii_whitespace().next() {
|
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,
|
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