From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit v3 1/8] state: event: add helper to dispatch custom DOM events
Date: Mon, 30 Nov 2026 13:52:35 +0100 [thread overview]
Message-ID: <20261130125325.2392967-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261130125325.2392967-1-d.csapak@proxmox.com>
Dispatching a custom event is currently open coded for the
`pwt-theme-changed` event. Provide a small wrapper, so that further
users do not have to repeat the window/document lookup and the JS error
conversion, and use it for the theme event too.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/state/event.rs | 21 +++++++++++++++++++++
src/state/mod.rs | 3 +++
src/state/theme.rs | 7 ++-----
3 files changed, 26 insertions(+), 5 deletions(-)
create mode 100644 src/state/event.rs
diff --git a/src/state/event.rs b/src/state/event.rs
new file mode 100644
index 0000000..39f4444
--- /dev/null
+++ b/src/state/event.rs
@@ -0,0 +1,21 @@
+//! Helper to dispatch custom DOM events.
+
+use anyhow::{Error, format_err};
+use web_sys::Event;
+
+/// Dispatch a custom event with the given name on the document.
+///
+/// The event is only delivered to listeners in the current document, so listeners in other
+/// browser tabs or windows are not notified.
+pub fn dispatch_custom_event(name: &str) -> Result<(), Error> {
+ let document = web_sys::window()
+ .and_then(|window| window.document())
+ .ok_or_else(|| format_err!("no document available"))?;
+
+ let event = Event::new(name).map_err(crate::convert_js_error)?;
+
+ document
+ .dispatch_event(&event)
+ .map(|_| ())
+ .map_err(crate::convert_js_error)
+}
diff --git a/src/state/mod.rs b/src/state/mod.rs
index d98d4db..335d7de 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -7,6 +7,9 @@ use serde::{Serialize, de::DeserializeOwned};
mod data_store;
pub use data_store::{DataNode, DataNodeDerefGuard, DataStore};
+mod event;
+pub use event::dispatch_custom_event;
+
mod loader;
pub use loader::{Loader, LoaderState};
diff --git a/src/state/theme.rs b/src/state/theme.rs
index 485c88e..a87679f 100644
--- a/src/state/theme.rs
+++ b/src/state/theme.rs
@@ -155,11 +155,8 @@ impl Default for Theme {
}
fn emit_theme_changed_event() {
- if let Some(window) = web_sys::window() {
- if let Some(document) = window.document() {
- let event = web_sys::Event::new("pwt-theme-changed").unwrap();
- let _ = document.dispatch_event(&event);
- }
+ if let Err(err) = super::dispatch_custom_event("pwt-theme-changed") {
+ log::error!("failed to send theme changed event: {err}");
}
}
--
2.47.3
next prev parent reply other threads:[~2026-11-30 12:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 12:52 [PATCH datacenter-manager/proxmox-yew-comp/yew-widget-toolkit v3 0/8] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
2026-11-30 12:52 ` Dominik Csapak [this message]
2026-11-30 12:52 ` [PATCH yew-widget-toolkit v3 2/8] state: persistent state: allow listening for updates Dominik Csapak
2026-11-30 12:52 ` [PATCH proxmox-yew-comp v3 3/8] xtermjs: allow setting the noVNC scaling mode Dominik Csapak
2026-11-30 12:52 ` [PATCH datacenter-manager v3 4/8] ui: view selector: use a placeholder that can't conflict with a view Dominik Csapak
2026-11-30 12:52 ` [PATCH datacenter-manager v3 5/8] ui: add 'My Settings' dialog with xterm.js and noVNC settings Dominik Csapak
2026-11-30 12:52 ` [PATCH datacenter-manager v3 6/8] ui: views: use the view name as key of the component Dominik Csapak
2026-11-30 12:52 ` [PATCH datacenter-manager v3 7/8] ui: make the default dashboard page configurable Dominik Csapak
2026-11-30 12:52 ` [PATCH datacenter-manager v3 8/8] docs: web ui: describe the 'My Settings' dialog Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130125325.2392967-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.