Maintain application metadata in beacon connection
This commit is contained in:
parent
dc69fdee46
commit
e82b10da77
6 changed files with 88 additions and 21 deletions
|
|
@ -30,6 +30,8 @@ pub enum Message {
|
||||||
at: SystemTime,
|
at: SystemTime,
|
||||||
name: String,
|
name: String,
|
||||||
version: Version,
|
version: Version,
|
||||||
|
theme: Option<theme::Palette>,
|
||||||
|
can_time_travel: bool,
|
||||||
},
|
},
|
||||||
EventLogged {
|
EventLogged {
|
||||||
at: SystemTime,
|
at: SystemTime,
|
||||||
|
|
@ -77,15 +79,22 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct Metadata {
|
||||||
|
pub name: &'static str,
|
||||||
|
pub theme: Option<theme::Palette>,
|
||||||
|
pub can_time_travel: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn connect(name: String) -> Client {
|
pub fn connect(metadata: Metadata) -> Client {
|
||||||
let (sender, receiver) = mpsc::channel(10_000);
|
let (sender, receiver) = mpsc::channel(10_000);
|
||||||
let is_connected = Arc::new(AtomicBool::new(false));
|
let is_connected = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let handle = {
|
let handle = {
|
||||||
let is_connected = is_connected.clone();
|
let is_connected = is_connected.clone();
|
||||||
|
|
||||||
std::thread::spawn(move || run(name, is_connected, receiver))
|
std::thread::spawn(move || run(metadata, is_connected, receiver))
|
||||||
};
|
};
|
||||||
|
|
||||||
Client {
|
Client {
|
||||||
|
|
@ -108,7 +117,7 @@ pub enum Command {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn run(
|
async fn run(
|
||||||
name: String,
|
mut metadata: Metadata,
|
||||||
is_connected: Arc<AtomicBool>,
|
is_connected: Arc<AtomicBool>,
|
||||||
mut receiver: mpsc::Receiver<Action>,
|
mut receiver: mpsc::Receiver<Action>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -133,8 +142,10 @@ async fn run(
|
||||||
&mut writer,
|
&mut writer,
|
||||||
Message::Connected {
|
Message::Connected {
|
||||||
at: SystemTime::now(),
|
at: SystemTime::now(),
|
||||||
name: name.clone(),
|
name: metadata.name.to_owned(),
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
|
can_time_travel: metadata.can_time_travel,
|
||||||
|
theme: metadata.theme,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
@ -148,6 +159,16 @@ async fn run(
|
||||||
loop {
|
loop {
|
||||||
match receive(&mut reader, &mut buffer).await {
|
match receive(&mut reader, &mut buffer).await {
|
||||||
Ok(command) => {
|
Ok(command) => {
|
||||||
|
match command {
|
||||||
|
Command::RewindTo { .. }
|
||||||
|
| Command::GoLive
|
||||||
|
if !metadata.can_time_travel =>
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
let sender = command_sender.lock().await;
|
let sender = command_sender.lock().await;
|
||||||
let _ = sender.send(command).await;
|
let _ = sender.send(command).await;
|
||||||
}
|
}
|
||||||
|
|
@ -161,6 +182,14 @@ async fn run(
|
||||||
while let Some(action) = receiver.recv().await {
|
while let Some(action) = receiver.recv().await {
|
||||||
match action {
|
match action {
|
||||||
Action::Send(message) => {
|
Action::Send(message) => {
|
||||||
|
if let Message::EventLogged {
|
||||||
|
event: Event::ThemeChanged(palette),
|
||||||
|
..
|
||||||
|
} = message
|
||||||
|
{
|
||||||
|
metadata.theme = Some(palette);
|
||||||
|
}
|
||||||
|
|
||||||
match send(&mut writer, message).await {
|
match send(&mut writer, message).await {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ pub enum Event {
|
||||||
at: SystemTime,
|
at: SystemTime,
|
||||||
name: String,
|
name: String,
|
||||||
version: Version,
|
version: Version,
|
||||||
|
theme: Option<theme::Palette>,
|
||||||
|
can_time_travel: bool,
|
||||||
},
|
},
|
||||||
Disconnected {
|
Disconnected {
|
||||||
at: SystemTime,
|
at: SystemTime,
|
||||||
|
|
@ -161,6 +163,8 @@ pub fn run() -> impl Stream<Item = Event> {
|
||||||
at,
|
at,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
|
theme,
|
||||||
|
can_time_travel,
|
||||||
} => {
|
} => {
|
||||||
let _ = output
|
let _ = output
|
||||||
.send(Event::Connected {
|
.send(Event::Connected {
|
||||||
|
|
@ -170,6 +174,8 @@ pub fn run() -> impl Stream<Item = Event> {
|
||||||
at,
|
at,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
|
theme,
|
||||||
|
can_time_travel,
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,13 @@ use crate::futures::Subscription;
|
||||||
|
|
||||||
pub use internal::Span;
|
pub use internal::Span;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct Metadata {
|
||||||
|
pub name: &'static str,
|
||||||
|
pub theme: Option<theme::Palette>,
|
||||||
|
pub can_time_travel: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Primitive {
|
pub enum Primitive {
|
||||||
Quad,
|
Quad,
|
||||||
|
|
@ -30,8 +37,8 @@ pub fn disable() {
|
||||||
internal::disable();
|
internal::disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(name: &str) {
|
pub fn init(metadata: Metadata) {
|
||||||
internal::init(name);
|
internal::init(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn quit() -> bool {
|
pub fn quit() -> bool {
|
||||||
|
|
@ -113,7 +120,7 @@ mod internal {
|
||||||
use crate::core::window;
|
use crate::core::window;
|
||||||
use crate::futures::Subscription;
|
use crate::futures::Subscription;
|
||||||
use crate::futures::futures::Stream;
|
use crate::futures::futures::Stream;
|
||||||
use crate::{Command, Primitive};
|
use crate::{Command, Metadata, Primitive};
|
||||||
|
|
||||||
use iced_beacon as beacon;
|
use iced_beacon as beacon;
|
||||||
|
|
||||||
|
|
@ -123,10 +130,15 @@ mod internal {
|
||||||
use std::sync::atomic::{self, AtomicBool, AtomicUsize};
|
use std::sync::atomic::{self, AtomicBool, AtomicUsize};
|
||||||
use std::sync::{LazyLock, RwLock};
|
use std::sync::{LazyLock, RwLock};
|
||||||
|
|
||||||
pub fn init(name: &str) {
|
pub fn init(metadata: Metadata) {
|
||||||
let name = name.split("::").next().unwrap_or(name);
|
let name = metadata.name.split("::").next().unwrap_or(metadata.name);
|
||||||
|
|
||||||
name.clone_into(&mut NAME.write().expect("Write application name"));
|
*METADATA.write().expect("Write application metadata") =
|
||||||
|
client::Metadata {
|
||||||
|
name,
|
||||||
|
theme: metadata.theme,
|
||||||
|
can_time_travel: metadata.can_time_travel,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn quit() -> bool {
|
pub fn quit() -> bool {
|
||||||
|
|
@ -144,12 +156,12 @@ mod internal {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if LAST_PALETTE.read().expect("Read last palette").as_ref()
|
if METADATA.read().expect("Read last palette").theme.as_ref()
|
||||||
!= Some(&palette)
|
!= Some(&palette)
|
||||||
{
|
{
|
||||||
log(client::Event::ThemeChanged(palette));
|
log(client::Event::ThemeChanged(palette));
|
||||||
|
|
||||||
*LAST_PALETTE.write().expect("Write last palette") = Some(palette);
|
METADATA.write().expect("Write last palette").theme = Some(palette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,12 +304,18 @@ mod internal {
|
||||||
}
|
}
|
||||||
|
|
||||||
static BEACON: LazyLock<Client> = LazyLock::new(|| {
|
static BEACON: LazyLock<Client> = LazyLock::new(|| {
|
||||||
client::connect(NAME.read().expect("Read application name").to_owned())
|
let metadata = METADATA.read().expect("Read application metadata");
|
||||||
|
|
||||||
|
client::connect(metadata.clone())
|
||||||
|
});
|
||||||
|
|
||||||
|
static METADATA: RwLock<client::Metadata> = RwLock::new(client::Metadata {
|
||||||
|
name: "",
|
||||||
|
theme: None,
|
||||||
|
can_time_travel: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
static NAME: RwLock<String> = RwLock::new(String::new());
|
|
||||||
static LAST_UPDATE: AtomicUsize = AtomicUsize::new(0);
|
static LAST_UPDATE: AtomicUsize = AtomicUsize::new(0);
|
||||||
static LAST_PALETTE: RwLock<Option<theme::Palette>> = RwLock::new(None);
|
|
||||||
static ENABLED: AtomicBool = AtomicBool::new(true);
|
static ENABLED: AtomicBool = AtomicBool::new(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,12 +324,12 @@ mod internal {
|
||||||
use crate::core::theme;
|
use crate::core::theme;
|
||||||
use crate::core::window;
|
use crate::core::window;
|
||||||
use crate::futures::Subscription;
|
use crate::futures::Subscription;
|
||||||
use crate::{Command, Primitive};
|
use crate::{Command, Metadata, Primitive};
|
||||||
|
|
||||||
pub fn enable() {}
|
pub fn enable() {}
|
||||||
pub fn disable() {}
|
pub fn disable() {}
|
||||||
|
|
||||||
pub fn init(_name: &str) {}
|
pub fn init(_metadata: Metadata) {}
|
||||||
|
|
||||||
pub fn quit() -> bool {
|
pub fn quit() -> bool {
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,15 @@ impl<P: Program> Application<P> {
|
||||||
Self: 'static,
|
Self: 'static,
|
||||||
{
|
{
|
||||||
#[cfg(all(feature = "debug", not(target_arch = "wasm32")))]
|
#[cfg(all(feature = "debug", not(target_arch = "wasm32")))]
|
||||||
let program = iced_devtools::attach(self.raw);
|
let program = {
|
||||||
|
iced_debug::init(iced_debug::Metadata {
|
||||||
|
name: P::name(),
|
||||||
|
theme: None,
|
||||||
|
can_time_travel: cfg!(feature = "time-travel"),
|
||||||
|
});
|
||||||
|
|
||||||
|
iced_devtools::attach(self.raw)
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(any(not(feature = "debug"), target_arch = "wasm32"))]
|
#[cfg(any(not(feature = "debug"), target_arch = "wasm32"))]
|
||||||
let program = self.raw;
|
let program = self.raw;
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,15 @@ impl<P: Program> Daemon<P> {
|
||||||
Self: 'static,
|
Self: 'static,
|
||||||
{
|
{
|
||||||
#[cfg(all(feature = "debug", not(target_arch = "wasm32")))]
|
#[cfg(all(feature = "debug", not(target_arch = "wasm32")))]
|
||||||
let program = iced_devtools::attach(self.raw);
|
let program = {
|
||||||
|
iced_debug::init(iced_debug::Metadata {
|
||||||
|
name: P::name(),
|
||||||
|
theme: None,
|
||||||
|
can_time_travel: cfg!(feature = "time-travel"),
|
||||||
|
});
|
||||||
|
|
||||||
|
iced_devtools::attach(self.raw)
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(any(not(feature = "debug"), target_arch = "wasm32"))]
|
#[cfg(any(not(feature = "debug"), target_arch = "wasm32"))]
|
||||||
let program = self.raw;
|
let program = self.raw;
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,6 @@ where
|
||||||
{
|
{
|
||||||
use winit::event_loop::EventLoop;
|
use winit::event_loop::EventLoop;
|
||||||
|
|
||||||
debug::init(P::name());
|
|
||||||
|
|
||||||
let boot_span = debug::boot();
|
let boot_span = debug::boot();
|
||||||
|
|
||||||
let graphics_settings = settings.clone().into();
|
let graphics_settings = settings.clone().into();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue