refactor: use settings subscriptions and nm secret agent
This commit is contained in:
parent
6534939ba6
commit
10e4f84d3f
14 changed files with 1184 additions and 1742 deletions
18
cosmic-applet-network/src/utils.rs
Normal file
18
cosmic-applet-network/src/utils.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use futures_util::future::select;
|
||||
|
||||
/// Spawn a background tasks and forward its messages
|
||||
pub fn forward_event_loop<M: 'static + Send, T: Future<Output = ()> + Send + 'static>(
|
||||
event_loop: impl FnOnce(async_fn_stream::StreamEmitter<M>) -> T + Send + 'static,
|
||||
) -> (tokio::sync::oneshot::Sender<()>, cosmic::Task<M>) {
|
||||
let (cancel_tx, cancel_rx) = tokio::sync::oneshot::channel::<()>();
|
||||
|
||||
let task = cosmic::Task::stream(async_fn_stream::fn_stream(|emitter| async move {
|
||||
select(
|
||||
std::pin::pin!(cancel_rx),
|
||||
std::pin::pin!(event_loop(emitter)),
|
||||
)
|
||||
.await;
|
||||
}));
|
||||
|
||||
(cancel_tx, task)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue