Skip to content

Commit 593e397

Browse files
wiiznokeswash2
authored andcommitted
suport long lived plugin, and sort top level manually
1 parent fca3b25 commit 593e397

File tree

12 files changed

+123
-21
lines changed

12 files changed

+123
-21
lines changed

Cargo.lock

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
1616
"env-filter",
1717
"chrono",
1818
] }
19+
tracing-journald = "0.3.0"
1920
dirs.workspace = true
2021
mimalloc = "0.1.43"
2122

bin/src/main.rs

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

77
use mimalloc::MiMalloc;
8-
use tracing_subscriber::layer::SubscriberExt;
9-
use tracing_subscriber::EnvFilter;
108

119
#[global_allocator]
1210
static GLOBAL: MiMalloc = MiMalloc;
@@ -41,7 +39,7 @@ async fn main() {
4139

4240
// todo: support journald once this issue is resolved: https://github.com/tokio-rs/tracing/issues/2348
4341
fn init_logging(cmd: &str) {
44-
use tracing_subscriber::{fmt, Registry};
42+
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
4543

4644
let logdir = match dirs::state_dir() {
4745
Some(dir) => dir.join("pop-launcher/"),
@@ -59,7 +57,7 @@ fn init_logging(cmd: &str) {
5957

6058
if let Ok(file) = logfile {
6159
if let Ok(meta) = file.metadata() {
62-
if meta.len() > 1000 {
60+
if meta.len() > 10000 {
6361
let _ = file.set_len(0);
6462
}
6563
}
@@ -68,13 +66,18 @@ fn init_logging(cmd: &str) {
6866
.or_else(|_| EnvFilter::try_new("warn"))
6967
.unwrap();
7068

71-
let fmt_layer = fmt::layer()
72-
.with_target(false)
73-
.with_timer(fmt::time::ChronoLocal::new("%T".into()))
74-
.with_writer(file);
69+
let fmt_layer = fmt::layer().with_target(false).with_writer(file);
7570

76-
let subscriber = Registry::default().with(filter_layer).with(fmt_layer);
77-
78-
tracing::subscriber::set_global_default(subscriber).expect("Failed to set subscriber");
71+
if let Ok(journal_layer) = tracing_journald::layer() {
72+
tracing_subscriber::registry()
73+
.with(journal_layer)
74+
.with(filter_layer)
75+
.init();
76+
} else {
77+
tracing_subscriber::registry()
78+
.with(fmt_layer)
79+
.with(filter_layer)
80+
.init();
81+
}
7982
}
8083
}

plugins/src/cosmic_toplevel/mod.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
mod toplevel_handler;
22

3+
use cctk::cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State;
34
use cctk::wayland_client::Proxy;
45
use cctk::{cosmic_protocols, sctk::reexports::calloop, toplevel_info::ToplevelInfo};
56
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1;
67
use fde::DesktopEntry;
78
use freedesktop_desktop_entry as fde;
9+
use tracing::{debug, info};
810

911
use crate::desktop_entries::utils::get_description;
1012
use crate::send;
@@ -19,12 +21,13 @@ use pop_launcher::{
1921
};
2022
use std::borrow::Cow;
2123
use std::iter;
24+
use std::collections::VecDeque;
2225
use tokio::io::{AsyncWrite, AsyncWriteExt};
2326

2427
use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent};
2528

2629
pub async fn main() {
27-
tracing::info!("starting cosmic-toplevel");
30+
info!("starting cosmic-toplevel");
2831

2932
let mut tx = async_stdout();
3033

@@ -68,20 +71,37 @@ pub async fn main() {
6871
Either::Right((Some(event), second_to_next_request)) => {
6972
next_event = toplevel_rx.next();
7073
next_request = second_to_next_request;
74+
7175
match event {
7276
ToplevelEvent::Add(handle, info) => {
73-
tracing::info!("{}", &info.app_id);
77+
tracing::info!("add {}", &info.app_id);
7478
app.toplevels.retain(|t| t.0 != handle);
75-
app.toplevels.push((handle, info));
79+
app.toplevels.push_front((handle, info));
7680
}
7781
ToplevelEvent::Remove(handle) => {
78-
app.toplevels.retain(|t| t.0 != handle);
79-
// ignore requests for this id until after the next search
80-
app.ids_to_ignore.push(handle.id().protocol_id());
82+
if let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
83+
app.toplevels.remove(pos);
84+
// ignore requests for this id until after the next search
85+
app.ids_to_ignore.push(handle.id().protocol_id());
86+
} else {
87+
tracing::warn!("ToplevelEvent::Remove, no toplevel found");
88+
}
8189
}
8290
ToplevelEvent::Update(handle, info) => {
83-
if let Some(t) = app.toplevels.iter_mut().find(|t| t.0 == handle) {
84-
t.1 = info;
91+
debug!("Update {}", &info.app_id);
92+
debug!("Update {:?}", &info.state);
93+
94+
if let Some(pos) = app.toplevels.iter().position(|t| t.0 == handle) {
95+
if info.state.contains(&State::Activated) {
96+
tracing::warn!("Update {:?}: push front", &info.app_id);
97+
app.toplevels.remove(pos);
98+
app.toplevels.push_front((handle, info));
99+
} else {
100+
app.toplevels[pos].1 = info;
101+
}
102+
} else {
103+
tracing::warn!("ToplevelEvent::Update, no toplevel found");
104+
app.toplevels.push_front((handle, info));
85105
}
86106
}
87107
}
@@ -95,7 +115,8 @@ struct App<W> {
95115
locales: Vec<String>,
96116
desktop_entries: Vec<DesktopEntry<'static>>,
97117
ids_to_ignore: Vec<u32>,
98-
toplevels: Vec<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
118+
// XXX: use LinkedList?
119+
toplevels: VecDeque<(ZcosmicToplevelHandleV1, ToplevelInfo)>,
99120
calloop_tx: calloop::channel::Sender<ToplevelAction>,
100121
tx: W,
101122
}
@@ -119,7 +140,7 @@ impl<W: AsyncWrite + Unpin> App<W> {
119140
locales,
120141
desktop_entries,
121142
ids_to_ignore: Vec::new(),
122-
toplevels: Vec::new(),
143+
toplevels: VecDeque::new(),
123144
calloop_tx,
124145
tx,
125146
},

plugins/src/cosmic_toplevel/plugin.ron

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
query: (persistent: true, priority: High),
55
bin: (path: "cosmic-toplevel"),
66
icon: Name("focus-windows-symbolic"),
7+
long_lived: true,
78
)

plugins/src/desktop_entries/mod.rs

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

1415
pub(crate) mod utils;
1516

1617
pub async fn main() {
18+
info!("starting desktop entries");
1719
let mut app = App::new(async_stdout());
1820
app.reload().await;
1921

service/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
201201

202202
break;
203203
}
204+
Request::Close => {
205+
for (_key, plugin) in self.plugins.iter_mut() {
206+
if !plugin.config.long_lived {
207+
let tx = plugin.sender_exec();
208+
_ = tx.send_async(Request::Exit).await;
209+
plugin.sender_drop();
210+
}
211+
}
212+
}
204213
}
205214
}
206215

@@ -465,6 +474,8 @@ impl<O: futures::Sink<Response> + Unpin> Service<O> {
465474
}
466475
}
467476
} else {
477+
self.no_sort = query.is_empty();
478+
468479
for plugin_id in query_queue {
469480
if let Some(plugin) = self.plugins.get_mut(plugin_id) {
470481
if plugin

service/src/plugins/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub struct PluginConfig {
3030

3131
#[serde(default)]
3232
pub history: bool,
33+
34+
#[serde(default)]
35+
pub long_lived: bool,
3336
}
3437

3538
#[derive(Debug, Default, Deserialize, Clone)]

service/src/plugins/help.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub const CONFIG: PluginConfig = PluginConfig {
2424
},
2525
icon: Some(IconSource::Name(Cow::Borrowed("system-help-symbolic"))),
2626
history: false,
27+
long_lived: false,
2728
};
2829
pub struct HelpPlugin {
2930
pub id: usize,

service/src/plugins/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ where
6060
self.exit();
6161
break;
6262
}
63+
Request::Close => {
64+
self.exit();
65+
}
6366
}
6467
}
6568

0 commit comments

Comments
 (0)