wip: update libcosmic (#93)

* wip: update libcosmic

* fix: damge issue resolved by updating iced

* fix: high cpu usage by time applet and app-list

* refactor subscriptions to produce fewer events

* refactor network applet to use less cpu

* fix: text size

* refactor: i18n for audio applet

* refactor: power applet i18n setup

* fix (battery): always send profile update

* fix (battery): set toggler width to layout correctly

* fix (app-list): backoff for restarts of toplevel subscription

* fix (network): alignment

* feat: ask for comfirmation before applying power applet actions

* wip: integrate cosmic-config

* update zbus

* feat: update to use latest libcosmic

* update iced

* udpate deps

* update deps

* refactor: move applet helpers to this repo, outside of libcosmic.

this should help alleviate some dependency hell

* chore update deps

* update deps

* cleanup
This commit is contained in:
Ashley Wulber 2023-06-01 12:23:12 -04:00 committed by GitHub
parent 8b46cc209f
commit 9ebd9b511a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 2841 additions and 1681 deletions

View file

@ -1,8 +1,8 @@
use cosmic::iced_native::subscription::{self, Subscription};
use std::cell::RefCell;
use std::{rc::Rc, thread};
extern crate libpulse_binding as pulse;
use cosmic::iced::{subscription, Subscription};
//use futures::channel::mpsc;
use libpulse_binding::{
callbacks::ListResult,
@ -15,71 +15,80 @@ use libpulse_binding::{
proplist::Proplist,
volume::ChannelVolumes,
};
pub fn connect() -> Subscription<Event> {
struct Connect;
subscription::unfold(
std::any::TypeId::of::<Connect>(),
State::Init,
|state| async move {
match state {
State::Init => {
let PulseHandle {
to_pulse,
from_pulse,
} = PulseHandle::new();
(
Some(Event::Init(Connection(to_pulse))),
State::Connecting(from_pulse),
)
}
// Waiting for Connection to succeed
// The GUI doesn't have to monitor this state, as it is never sent to the GUI
State::Connecting(mut from_pulse) => match from_pulse.recv().await {
Some(Message::Connected) => {
(Some(Event::Connected), State::Connected(from_pulse))
}
Some(Message::Disconnected) => {
(Some(Event::Disconnected), State::Connecting(from_pulse))
}
Some(m) => {
panic!("Unexpected message: {:?}", m);
}
None => {
panic!("Pulse Sender dropped, something has gone wrong!");
}
},
State::Connected(mut from_pulse) => {
// This is where we match messages from the pulse server to pass to the gui
match from_pulse.recv().await {
Some(Message::SetSinks(sinks)) => (
Some(Event::MessageReceived(Message::SetSinks(sinks))),
State::Connected(from_pulse),
),
Some(Message::SetSources(sources)) => (
Some(Event::MessageReceived(Message::SetSources(sources))),
State::Connected(from_pulse),
),
Some(Message::SetDefaultSink(sink)) => (
Some(Event::MessageReceived(Message::SetDefaultSink(sink))),
State::Connected(from_pulse),
),
Some(Message::SetDefaultSource(source)) => (
Some(Event::MessageReceived(Message::SetDefaultSource(source))),
State::Connected(from_pulse),
),
Some(Message::Disconnected) => {
(Some(Event::Disconnected), State::Connecting(from_pulse))
}
None => (Some(Event::Disconnected), State::Connecting(from_pulse)),
_ => (None, State::Connected(from_pulse)),
}
|mut state| async move {
loop {
let (update, new_state) = connection(state).await;
state = new_state;
if let Some(update) = update {
return (update, state);
}
}
},
)
}
async fn connection(state: State) -> (Option<Event>, State) {
match state {
State::Init => {
let PulseHandle {
to_pulse,
from_pulse,
} = PulseHandle::new();
(
Some(Event::Init(Connection(to_pulse))),
State::Connecting(from_pulse),
)
}
// Waiting for Connection to succeed
// The GUI doesn't have to monitor this state, as it is never sent to the GUI
State::Connecting(mut from_pulse) => match from_pulse.recv().await {
Some(Message::Connected) => (Some(Event::Connected), State::Connected(from_pulse)),
Some(Message::Disconnected) => {
(Some(Event::Disconnected), State::Connecting(from_pulse))
}
Some(m) => {
panic!("Unexpected message: {:?}", m);
}
None => {
panic!("Pulse Sender dropped, something has gone wrong!");
}
},
State::Connected(mut from_pulse) => {
// This is where we match messages from the pulse server to pass to the gui
match from_pulse.recv().await {
Some(Message::SetSinks(sinks)) => (
Some(Event::MessageReceived(Message::SetSinks(sinks))),
State::Connected(from_pulse),
),
Some(Message::SetSources(sources)) => (
Some(Event::MessageReceived(Message::SetSources(sources))),
State::Connected(from_pulse),
),
Some(Message::SetDefaultSink(sink)) => (
Some(Event::MessageReceived(Message::SetDefaultSink(sink))),
State::Connected(from_pulse),
),
Some(Message::SetDefaultSource(source)) => (
Some(Event::MessageReceived(Message::SetDefaultSource(source))),
State::Connected(from_pulse),
),
Some(Message::Disconnected) => {
(Some(Event::Disconnected), State::Connecting(from_pulse))
}
None => (Some(Event::Disconnected), State::Connecting(from_pulse)),
_ => (None, State::Connected(from_pulse)),
}
}
}
}
// #[derive(Debug)]
enum State {
Init,