chore: update dependencies

This commit is contained in:
Michael Aaron Murphy 2024-08-21 03:07:16 +02:00
parent 6948373a68
commit 3ec53d7f8a
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
10 changed files with 350 additions and 304 deletions

View file

@ -6,7 +6,6 @@ use cosmic_settings_page::Entity;
pub mod desktop;
pub mod display;
pub mod input;
pub mod networking;
pub mod power;
pub mod sound;
pub mod system;

View file

@ -1,7 +1,7 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use std::time::Duration;
use std::{collections::BTreeMap, time::Duration};
use cosmic::{
widget::{self, settings},
@ -71,7 +71,7 @@ pub enum DeviceId {
pub struct Page {
pipewire_thread: Option<(tokio::sync::oneshot::Sender<()>, pipewire::Sender<()>)>,
pulse_thread: Option<tokio::sync::oneshot::Sender<()>>,
devices: IndexMap<DeviceId, Card>,
devices: BTreeMap<DeviceId, Card>,
card_names: IndexMap<DeviceId, String>,
card_profiles: IndexMap<DeviceId, Vec<pulse::CardProfile>>,
active_profiles: IndexMap<DeviceId, Option<String>>,
@ -451,7 +451,7 @@ impl Page {
}
if let Some(card_id) = remove {
_ = self.devices.shift_remove(&card_id);
_ = self.devices.remove(&card_id);
}
if let Some(pos) = self.sink_ids.iter().position(|&id| id == node_id) {

View file

@ -1,3 +1,7 @@
use std::future::Future;
use futures::{future::select, StreamExt};
/// Normalize the labeling of displays across settings pages.
pub fn display_name(name: &str, physical: (u32, u32)) -> String {
let inches = ((physical.0.pow(2) + physical.1.pow(2)) as f32).sqrt() * 0.039_370_1;
@ -15,3 +19,30 @@ pub fn display_name(name: &str, physical: (u32, u32)) -> String {
),
}
}
/// Spawn a background tasks and forward its messages
pub fn forward_event_loop<M: 'static + Send, T: Future<Output = ()> + Send + 'static>(
sender: tokio::sync::mpsc::Sender<crate::pages::Message>,
message_map: fn(M) -> crate::pages::Message,
event_loop: impl FnOnce(futures::channel::mpsc::Sender<M>) -> T + Send + 'static,
) -> tokio::sync::oneshot::Sender<()> {
let (cancel_tx, cancel_rx) = tokio::sync::oneshot::channel::<()>();
tokio::task::spawn(async move {
let (tx, mut rx) = futures::channel::mpsc::channel(1);
let cancel = std::pin::pin!(cancel_rx);
let forwarder = std::pin::pin!(async move {
while let Some(event) = rx.next().await {
if sender.send(message_map(event)).await.is_err() {
break;
}
}
});
select(cancel, select(forwarder, std::pin::pin!(event_loop(tx)))).await;
});
cancel_tx
}