Add ids for subscriptions

This commit is contained in:
Jeremy Soller 2023-11-27 09:02:35 -07:00
parent 78714e81aa
commit 518e791593
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
2 changed files with 84 additions and 72 deletions

34
Cargo.lock generated
View file

@ -956,7 +956,7 @@ dependencies = [
[[package]]
name = "cosmic-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"atomicwrites",
"cosmic-config-derive",
@ -970,7 +970,7 @@ dependencies = [
[[package]]
name = "cosmic-config-derive"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"quote",
"syn 1.0.109",
@ -1043,7 +1043,7 @@ dependencies = [
[[package]]
name = "cosmic-theme"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"almost",
"cosmic-config",
@ -2399,7 +2399,7 @@ dependencies = [
[[package]]
name = "iced"
version = "0.10.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"iced_accessibility",
"iced_core",
@ -2414,7 +2414,7 @@ dependencies = [
[[package]]
name = "iced_accessibility"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"accesskit",
"accesskit_winit",
@ -2423,7 +2423,7 @@ dependencies = [
[[package]]
name = "iced_core"
version = "0.10.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"bitflags 1.3.2",
"instant",
@ -2437,7 +2437,7 @@ dependencies = [
[[package]]
name = "iced_futures"
version = "0.7.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"futures",
"iced_core",
@ -2450,7 +2450,7 @@ dependencies = [
[[package]]
name = "iced_graphics"
version = "0.9.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"bitflags 1.3.2",
"bytemuck",
@ -2468,7 +2468,7 @@ dependencies = [
[[package]]
name = "iced_renderer"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"iced_graphics",
"iced_tiny_skia",
@ -2481,7 +2481,7 @@ dependencies = [
[[package]]
name = "iced_runtime"
version = "0.1.1"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"iced_core",
"iced_futures",
@ -2491,7 +2491,7 @@ dependencies = [
[[package]]
name = "iced_style"
version = "0.9.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"iced_core",
"once_cell",
@ -2501,7 +2501,7 @@ dependencies = [
[[package]]
name = "iced_tiny_skia"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"bytemuck",
"cosmic-text 0.9.0",
@ -2519,7 +2519,7 @@ dependencies = [
[[package]]
name = "iced_wgpu"
version = "0.11.1"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"bitflags 1.3.2",
"bytemuck",
@ -2541,7 +2541,7 @@ dependencies = [
[[package]]
name = "iced_widget"
version = "0.1.3"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"iced_renderer",
"iced_runtime",
@ -2555,7 +2555,7 @@ dependencies = [
[[package]]
name = "iced_winit"
version = "0.10.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"iced_graphics",
"iced_runtime",
@ -2853,7 +2853,7 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "libcosmic"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#001fd744c5f80c9ce058eb0e22ae92f19d12c844"
source = "git+https://github.com/pop-os/libcosmic#d1537b4c39bc48b020c9965c0c862207d0060889"
dependencies = [
"apply",
"ashpd",
@ -5044,7 +5044,7 @@ dependencies = [
[[package]]
name = "taffy"
version = "0.3.11"
source = "git+https://github.com/DioxusLabs/taffy#1876f72bee5e376023eaa518aa7b8a34c769bd1b"
source = "git+https://github.com/DioxusLabs/taffy?rev=7781c70#7781c70241f7f572130c13106f2a869a9cf80885"
dependencies = [
"arrayvec 0.7.4",
"grid",

View file

@ -17,6 +17,7 @@ use cosmic::{
};
use cosmic_text::{Cursor, Edit, Family, FontSystem, SwashCache, SyntaxSystem, ViMode};
use std::{
any::TypeId,
env, fs,
path::{Path, PathBuf},
process,
@ -1180,6 +1181,10 @@ impl Application for App {
}
fn subscription(&self) -> subscription::Subscription<Message> {
struct WatcherSubscription;
struct ConfigSubscription;
struct ThemeSubscription;
subscription::Subscription::batch([
subscription::events_with(|event, _status| match event {
event::Event::Keyboard(keyboard::Event::KeyPressed {
@ -1188,74 +1193,81 @@ impl Application for App {
}) => Some(Message::Key(modifiers, key_code)),
_ => None,
}),
subscription::channel(0, 100, |mut output| async move {
let watcher_res = {
let mut output = output.clone();
notify::recommended_watcher(
move |event_res: Result<notify::Event, notify::Error>| match event_res {
Ok(event) => {
match &event.kind {
notify::EventKind::Access(_)
| notify::EventKind::Modify(
notify::event::ModifyKind::Metadata(_),
) => {
// Data not mutated
return;
subscription::channel(
TypeId::of::<WatcherSubscription>(),
100,
|mut output| async move {
let watcher_res = {
let mut output = output.clone();
notify::recommended_watcher(
move |event_res: Result<notify::Event, notify::Error>| match event_res {
Ok(event) => {
match &event.kind {
notify::EventKind::Access(_)
| notify::EventKind::Modify(
notify::event::ModifyKind::Metadata(_),
) => {
// Data not mutated
return;
}
_ => {}
}
_ => {}
}
match futures::executor::block_on(async {
output.send(Message::NotifyEvent(event)).await
}) {
Ok(()) => {}
Err(err) => {
log::warn!("failed to send notify event: {:?}", err);
match futures::executor::block_on(async {
output.send(Message::NotifyEvent(event)).await
}) {
Ok(()) => {}
Err(err) => {
log::warn!("failed to send notify event: {:?}", err);
}
}
}
}
Err(err) => {
log::warn!("failed to watch files: {:?}", err);
}
},
)
};
Err(err) => {
log::warn!("failed to watch files: {:?}", err);
}
},
)
};
match watcher_res {
Ok(watcher) => {
match output
.send(Message::NotifyWatcher(WatcherWrapper {
watcher_opt: Some(watcher),
}))
.await
{
Ok(()) => {}
Err(err) => {
log::warn!("failed to send notify watcher: {:?}", err);
match watcher_res {
Ok(watcher) => {
match output
.send(Message::NotifyWatcher(WatcherWrapper {
watcher_opt: Some(watcher),
}))
.await
{
Ok(()) => {}
Err(err) => {
log::warn!("failed to send notify watcher: {:?}", err);
}
}
}
Err(err) => {
log::warn!("failed to create file watcher: {:?}", err);
}
}
Err(err) => {
log::warn!("failed to create file watcher: {:?}", err);
}
}
//TODO: how to properly kill this task?
loop {
time::sleep(time::Duration::new(1, 0)).await;
}
}),
cosmic_config::config_subscription(0, Self::APP_ID.into(), CONFIG_VERSION).map(
|(_, res)| match res {
Ok(config) => Message::Config(config),
Err((errs, config)) => {
log::warn!("errors loading config: {:#?}", errs);
Message::Config(config)
//TODO: how to properly kill this task?
loop {
time::sleep(time::Duration::new(1, 0)).await;
}
},
),
cosmic_config::config_subscription(
TypeId::of::<ConfigSubscription>(),
Self::APP_ID.into(),
CONFIG_VERSION,
)
.map(|(_, res)| match res {
Ok(config) => Message::Config(config),
Err((errs, config)) => {
log::warn!("errors loading config: {:#?}", errs);
Message::Config(config)
}
}),
cosmic_config::config_subscription::<_, cosmic_theme::ThemeMode>(
0,
TypeId::of::<ThemeSubscription>(),
cosmic_theme::THEME_MODE_ID.into(),
cosmic_theme::ThemeMode::version(),
)