Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes jammy #200

Merged
merged 5 commits into from
Jan 19, 2024
Merged
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
769 changes: 340 additions & 429 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = fa
] }
zbus = { version = "3.14", default-features = false, features = ["tokio"] }
tracing = "0.1"
tracing-subscriber = "0.3.18"
tracing-log = "0.2.0"

[profile.release]
lto = "thin"
Expand All @@ -45,7 +47,7 @@ lto = "thin"
# [patch."https://github.com/pop-os/cosmic-time"]
# cosmic-time = { path = "../cosmic-time" }
# [patch."https://github.com/pop-os/libcosmic"]
# libcosmic = { path = "../libcosmic" }
# cosmic-config = { path = "../libcosmic/cosmic-config" }
# libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "refactor-config-watch" }
# cosmic-config = { git = "https://github.com/pop-os/libcosmic//", branch = "refactor-config-watch" }
[patch."https://github.com/Smithay/client-toolkit"]
sctk = { git = "https://github.com/smithay/client-toolkit//", package = "smithay-client-toolkit", rev = "e63ab5f" }
4 changes: 3 additions & 1 deletion cosmic-app-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ futures = "0.3"
futures-util = "0.3"
once_cell = "1.9"
xdg = "2.4"
pretty_env_logger = "0.5"
tracing-subscriber.workspace = true
tracing-log.workspace = true
tracing.workspace = true
nix = "0.26"
shlex = "1.1.0"
anyhow = "1.0"
Expand Down
29 changes: 13 additions & 16 deletions cosmic-app-list/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl cosmic::Application for CosmicAppList {
core: cosmic::app::Core,
_flags: Self::Flags,
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
let config = Config::new(APP_ID, 1)
let config = Config::new(APP_ID, AppListConfig::VERSION)
.ok()
.and_then(|c| AppListConfig::get_entry(&c).ok())
.unwrap_or_default();
Expand Down Expand Up @@ -485,14 +485,16 @@ impl cosmic::Application for CosmicAppList {
}

self.config
.add_favorite(id, &Config::new(APP_ID, 1).unwrap());
.add_favorite(id, &Config::new(APP_ID, AppListConfig::VERSION).unwrap());
if let Some((popup_id, _toplevel)) = self.popup.take() {
return destroy_popup(popup_id);
}
}
Message::UnFavorite(id) => {
self.config
.remove_favorite(id.clone(), &Config::new(APP_ID, 1).unwrap());
self.config.remove_favorite(
id.clone(),
&Config::new(APP_ID, AppListConfig::VERSION).unwrap(),
);
if let Some(i) = self
.favorite_list
.iter()
Expand Down Expand Up @@ -555,7 +557,7 @@ impl cosmic::Application for CosmicAppList {
let t = self.favorite_list.remove(pos);
self.config.remove_favorite(
t.desktop_info.id.clone(),
&Config::new(APP_ID, 1).unwrap(),
&Config::new(APP_ID, AppListConfig::VERSION).unwrap(),
);
Some((true, t))
} else {
Expand Down Expand Up @@ -706,7 +708,7 @@ impl cosmic::Application for CosmicAppList {
.iter()
.map(|dock_item| dock_item.desktop_info.id.clone())
.collect(),
&Config::new(APP_ID, 1).unwrap(),
&Config::new(APP_ID, AppListConfig::VERSION).unwrap(),
);
}
return finish_dnd();
Expand Down Expand Up @@ -1122,7 +1124,7 @@ impl cosmic::Application for CosmicAppList {

fn subscription(&self) -> Subscription<Message> {
Subscription::batch(vec![
wayland_subscription(self.subscription_ctr).map(Message::Wayland),
wayland_subscription().map(Message::Wayland),
listen_with(|e, _| match e {
cosmic::iced_runtime::core::Event::PlatformSpecific(
event::PlatformSpecific::Wayland(event::wayland::Event::Seat(e, seat)),
Expand Down Expand Up @@ -1158,16 +1160,11 @@ impl cosmic::Application for CosmicAppList {
_ => None,
}),
rectangle_tracker_subscription(0).map(|update| Message::Rectangle(update.1)),
cosmic_config::config_subscription(0, Cow::from(APP_ID), 1).map(|(_, config)| {
match config {
Ok(config) => Message::ConfigUpdated(config),
Err((errors, config)) => {
for error in errors {
log::error!("{:?}", error);
}
Message::ConfigUpdated(config)
}
self.core.watch_config(APP_ID).map(|u| {
for err in u.errors {
log::error!("Error watching config: {}", err);
}
Message::ConfigUpdated(u.config)
}),
])
}
Expand Down
2 changes: 1 addition & 1 deletion cosmic-app-list/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use cosmic::cosmic_config::{self, Config, CosmicConfigEntry};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
pub const APP_ID: &str = "com.system76.CosmicAppList";
pub const VERSION: &str = "0.1.0";

#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
pub enum TopLevelFilter {
Expand All @@ -13,6 +12,7 @@ pub enum TopLevelFilter {
}

#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq, CosmicConfigEntry)]
#[version = 1]
pub struct AppListConfig {
pub filter_top_levels: Option<TopLevelFilter>,
pub favorites: Vec<String>,
Expand Down
8 changes: 4 additions & 4 deletions cosmic-app-list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use log::info;

use localize::localize;

use crate::config::{APP_ID, VERSION};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

fn main() -> cosmic::iced::Result {
// Initialize logger
pretty_env_logger::init();
info!("Iced Workspaces Applet ({})", APP_ID);
info!("Version: {}", VERSION);
tracing_subscriber::fmt::init();
let _ = tracing_log::LogTracer::init();
info!("Iced Workspaces Applet ({VERSION})");
// Prepare i18n
localize();

Expand Down
64 changes: 33 additions & 31 deletions cosmic-app-list/src/wayland_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ use futures::{
channel::mpsc::{unbounded, UnboundedReceiver},
SinkExt, StreamExt,
};
use once_cell::sync::Lazy;
use std::{fmt::Debug, hash::Hash, thread::JoinHandle};
use tokio::sync::Mutex;

use crate::wayland_handler::wayland_handler;

pub fn wayland_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
id: I,
) -> iced::Subscription<WaylandUpdate> {
subscription::channel(id, 50, move |mut output| async move {
let mut state = State::Ready;
pub static WAYLAND_RX: Lazy<Mutex<Option<UnboundedReceiver<WaylandUpdate>>>> =
Lazy::new(|| Mutex::new(None));

loop {
state = start_listening(state, &mut output).await;
}
})
pub fn wayland_subscription() -> iced::Subscription<WaylandUpdate> {
subscription::channel(
std::any::TypeId::of::<WaylandUpdate>(),
50,
move |mut output| async move {
let mut state = State::Waiting;

loop {
state = start_listening(state, &mut output).await;
}
},
)
}

pub enum State {
Ready,
Waiting(
UnboundedReceiver<WaylandUpdate>,
calloop::channel::Sender<WaylandRequest>,
JoinHandle<()>,
),
Waiting,
Finished,
}

Expand All @@ -42,28 +44,28 @@ async fn start_listening(
output: &mut futures::channel::mpsc::Sender<WaylandUpdate>,
) -> State {
match state {
State::Ready => {
let (calloop_tx, calloop_rx) = calloop::channel::channel();
let (toplevel_tx, toplevel_rx) = unbounded();
let handle = std::thread::spawn(move || {
wayland_handler(toplevel_tx, calloop_rx);
});
let tx = calloop_tx.clone();
_ = output.send(WaylandUpdate::Init(tx)).await;
State::Waiting(toplevel_rx, calloop_tx, handle)
}
State::Waiting(mut rx, tx, handle) => {
if handle.is_finished() {
_ = output.send(WaylandUpdate::Finished).await;
return State::Finished;
}
State::Waiting => {
let mut guard = WAYLAND_RX.lock().await;
let rx = {
if guard.is_none() {
let (calloop_tx, calloop_rx) = calloop::channel::channel();
let (toplevel_tx, toplevel_rx) = unbounded();
let _ = std::thread::spawn(move || {
wayland_handler(toplevel_tx, calloop_rx);
});
*guard = Some(toplevel_rx);
_ = output.send(WaylandUpdate::Init(calloop_tx)).await;
}
guard.as_mut().unwrap()
};
match rx.next().await {
Some(u) => {
_ = output.send(u).await;
State::Waiting(rx, tx, handle)
State::Waiting
}
None => {
_ = output.send(WaylandUpdate::Finished).await;
tracing::error!("Wayland handler thread died");
State::Finished
}
}
Expand Down
10 changes: 5 additions & 5 deletions cosmic-applet-audio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "cosmic-applet-audio"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
icon-loader = { version = "0.3.6", features = ["gtk"] }
libpulse-binding = "2.26.0"
libpulse-glib-binding = "2.25.0"
libpulse-binding = "2.28.1"
libpulse-glib-binding = "2.28.1"
tokio = { version = "1.20.1", features=["full"] }
libcosmic.workspace = true
cosmic-time.workspace = true
tracing = "0.1.40"
pretty_env_logger = "0.4.0"
tracing-subscriber.workspace = true
tracing-log.workspace = true
# Application i18n
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6"
Expand Down
24 changes: 11 additions & 13 deletions cosmic-applet-audio/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@
mod config;
mod mpris_subscription;
mod pulse;

const VERSION: &str = env!("CARGO_PKG_VERSION");

pub fn main() -> cosmic::iced::Result {
pretty_env_logger::init();
tracing_subscriber::fmt::init();
let _ = tracing_log::LogTracer::init();

// Prepare i18n
localize();

tracing::info!("Starting audio applet with version {VERSION}");

cosmic::applet::run::<Audio>(true, ())
}

Expand Down Expand Up @@ -446,10 +452,10 @@
pulse::Event::Disconnected => {
self.pulse_state.disconnected();
if let Some(mut conn) = self.pulse_state.connection().cloned() {
_ = tokio::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(30)).await;
conn.send(pulse::Message::UpdateConnection);
});

Check warning on line 458 in cosmic-applet-audio/src/main.rs

View workflow job for this annotation

GitHub Actions / linting

non-binding `let` on a future

warning: non-binding `let` on a future --> cosmic-applet-audio/src/main.rs:455:25 | 455 | / _ = tokio::spawn(async move { 456 | | tokio::time::sleep(tokio::time::Duration::from_secs(30)).await; 457 | | conn.send(pulse::Message::UpdateConnection); 458 | | }); | |__________________________^ | = help: consider awaiting the future or dropping explicitly with `std::mem::drop` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_future = note: `#[warn(clippy::let_underscore_future)]` on by default
}
}
},
Expand Down Expand Up @@ -554,19 +560,11 @@
self.timeline
.as_subscription()
.map(|(_, now)| Message::Frame(now)),
cosmic::cosmic_config::config_subscription(
0,
Self::APP_ID.into(),
AudioAppletConfig::version(),
)
.map(|(_, res)| match res {
Ok(c) => Message::ConfigChanged(c),
Err((errs, c)) => {
for err in errs {
tracing::error!("Error loading config: {}", err);
}
Message::ConfigChanged(c)
self.core.watch_config(Self::APP_ID.into()).map(|u| {

Check warning on line 563 in cosmic-applet-audio/src/main.rs

View workflow job for this annotation

GitHub Actions / linting

useless conversion to the same type: `&str`

warning: useless conversion to the same type: `&str` --> cosmic-applet-audio/src/main.rs:563:36 | 563 | self.core.watch_config(Self::APP_ID.into()).map(|u| { | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `Self::APP_ID` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
for err in u.errors {
tracing::error!(?err, "Error watching config");
}
Message::ConfigChanged(u.config)
}),
mpris_subscription::mpris_subscription(0).map(Message::Mpris),
activation_token_subscription(0).map(Message::Token),
Expand Down
Loading
Loading