From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager v3 5/8] ui: add 'My Settings' dialog with xterm.js and noVNC settings
Date: Mon, 30 Nov 2026 13:52:39 +0100 [thread overview]
Message-ID: <20261130125325.2392967-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261130125325.2392967-1-d.csapak@proxmox.com>
like in PVE, reachable from the user menu. For now it only contains
the xterm.js settings (font family, font size, letter spacing and line
height) and the noVNC scaling mode.
The xterm.js settings are saved in the 'pve-xterm-*' entries of the
local browser storage, where the xterm.js console reads them from.
The noVNC scaling mode is saved in 'novnc-scaling' and passed to noVNC
as 'resize' parameter when showing or opening the console of a virtual
machine.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
ui/Cargo.toml | 2 +-
ui/src/pve/utils.rs | 13 +-
ui/src/top_nav_bar.rs | 16 +-
ui/src/widget/mod.rs | 3 +
ui/src/widget/my_settings_dialog.rs | 248 ++++++++++++++++++++++++++++
5 files changed, 277 insertions(+), 5 deletions(-)
create mode 100644 ui/src/widget/my_settings_dialog.rs
diff --git a/ui/Cargo.toml b/ui/Cargo.toml
index 32a2020b..03b836b6 100644
--- a/ui/Cargo.toml
+++ b/ui/Cargo.toml
@@ -24,7 +24,7 @@ serde_json = "1.0"
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4"
wasm-logger = "0.2"
-web-sys = { version = "0.3", features = ["Location", "DataTransfer", "Performance"] }
+web-sys = { version = "0.3", features = ["Location", "DataTransfer", "Performance", "Storage"] }
yew = { version = "0.21", features = ["csr"] }
yew-router = { version = "0.18" }
diff --git a/ui/src/pve/utils.rs b/ui/src/pve/utils.rs
index 91cc03b0..b3acb81d 100644
--- a/ui/src/pve/utils.rs
+++ b/ui/src/pve/utils.rs
@@ -325,7 +325,17 @@ pub(crate) fn open_guest_console(remote: &str, node: &str, guest: GuestInfo, nov
false,
),
};
- XTermJs::open_xterm_js_viewer(console_type, node, use_vnc);
+ XTermJs::new()
+ .console_type(console_type)
+ .node_name(node.to_string())
+ .vnc(use_vnc)
+ .resize(novnc_scaling_state().into_inner())
+ .open_viewer();
+}
+
+/// The scaling mode of noVNC that is selected in this browser, `None` for the default of noVNC.
+pub(crate) fn novnc_scaling_state() -> PersistentState<Option<String>> {
+ PersistentState::new("novnc-scaling")
}
/// Returns `console`, or why it cannot be shown if the user lacks `Sys.Console` or `node` runs a
@@ -399,6 +409,7 @@ pub(crate) fn qemu_console(props: &QemuConsoleProps) -> Html {
let mut console = XTermJs::new();
console.set_vnc(novnc);
+ console.set_resize(novnc_scaling_state().into_inner());
console.set_node_name(props.node.clone());
console.set_console_type(ConsoleType::RemotePveKVM(
props.remote.clone(),
diff --git a/ui/src/top_nav_bar.rs b/ui/src/top_nav_bar.rs
index 7ccc388c..09da5a2d 100644
--- a/ui/src/top_nav_bar.rs
+++ b/ui/src/top_nav_bar.rs
@@ -23,7 +23,7 @@ use pbs_api_types::TaskListItem;
use pdm_api_types::RemoteUpid;
use crate::tasks::format_optional_remote_upid;
-use crate::widget::SearchBox;
+use crate::widget::{MySettingsDialog, SearchBox};
mod change_password;
@@ -59,6 +59,7 @@ impl TopNavBar {
#[derive(Clone)]
pub enum ViewState {
+ MySettingsDialog,
LanguageDialog,
ThemeDialog,
ChangePassword,
@@ -168,8 +169,14 @@ impl Component for PdmTopNavBar {
});
let menu = Menu::new()
- // FIXME: implement
- //.with_item(MenuItem::new(tr!("My Settings")).icon_class("fa fa-gear"))
+ .with_item(
+ MenuItem::new(tr!("My Settings"))
+ .icon_class("fa fa-gear")
+ .on_select(
+ ctx.link()
+ .callback(|_| Msg::ChangeView(Some(ViewState::MySettingsDialog))),
+ ),
+ )
.with_item(
MenuItem::new(tr!("Language"))
.icon_class("fa fa-language")
@@ -247,6 +254,9 @@ impl Component for PdmTopNavBar {
}
let dialog: Option<Html> = self.view_state.as_ref().map(|view_state| match view_state {
+ ViewState::MySettingsDialog => MySettingsDialog::new()
+ .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
+ .into(),
ViewState::LanguageDialog => LanguageDialog::new()
.on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
.into(),
diff --git a/ui/src/widget/mod.rs b/ui/src/widget/mod.rs
index 353be148..f719eef2 100644
--- a/ui/src/widget/mod.rs
+++ b/ui/src/widget/mod.rs
@@ -4,6 +4,9 @@ pub use bulk_action_window::{BulkActionWindow, bulk_action_disabled_reason};
mod migrate_window;
pub use migrate_window::MigrateWindow;
+mod my_settings_dialog;
+pub use my_settings_dialog::MySettingsDialog;
+
mod snapshot_window;
pub use snapshot_window::SnapshotWindow;
diff --git a/ui/src/widget/my_settings_dialog.rs b/ui/src/widget/my_settings_dialog.rs
new file mode 100644
index 00000000..c18c5519
--- /dev/null
+++ b/ui/src/widget/my_settings_dialog.rs
@@ -0,0 +1,248 @@
+use std::rc::Rc;
+use std::str::FromStr;
+
+use serde::{Deserialize, Serialize};
+use serde_json::json;
+use yew::html::IntoEventCallback;
+use yew::virtual_dom::{VComp, VNode};
+
+use pwt::css::ColorScheme;
+use pwt::prelude::*;
+use pwt::state::{PersistentState, local_storage};
+use pwt::widget::form::{Combobox, Field, Form, FormContext, Number};
+use pwt::widget::{Button, Container, Dialog, InputPanel, Row};
+
+use pwt_macros::builder;
+
+use crate::pve::utils::novnc_scaling_state;
+
+// The xterm.js console uses the text of its local storage entries as is, so they cannot be saved
+// as (JSON encoded) persistent states.
+fn load_xterm_setting<T: FromStr>(key: &str) -> Option<T> {
+ let res = local_storage()?.get_item(key).ok()??;
+ if res.is_empty() {
+ return None;
+ }
+ res.parse().ok()
+}
+
+fn save_xterm_setting<T: ToString>(key: &str, value: Option<T>) {
+ let Some(store) = local_storage() else {
+ return;
+ };
+ let result = match value.map(|s| s.to_string()) {
+ Some(value) if !value.is_empty() => store.set_item(key, &value),
+ Some(_) | None => store.remove_item(key),
+ };
+ if let Err(err) = result {
+ log::error!("could not save '{key}': {}", pwt::convert_js_error(err));
+ }
+}
+
+/// The xterm.js settings, named like the fields of the form.
+#[derive(Default, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct XtermSettings {
+ font_family: Option<String>,
+ font_size: Option<u64>,
+ letter_spacing: Option<f64>,
+ line_height: Option<f64>,
+}
+
+impl XtermSettings {
+ fn load() -> Self {
+ Self {
+ font_family: load_xterm_setting("pve-xterm-fontFamily"),
+ font_size: load_xterm_setting("pve-xterm-fontSize"),
+ letter_spacing: load_xterm_setting("pve-xterm-letterSpacing"),
+ line_height: load_xterm_setting("pve-xterm-lineHeight"),
+ }
+ }
+
+ fn save(&self) {
+ save_xterm_setting("pve-xterm-fontFamily", self.font_family.as_ref());
+ save_xterm_setting("pve-xterm-fontSize", self.font_size);
+ save_xterm_setting("pve-xterm-letterSpacing", self.letter_spacing);
+ save_xterm_setting("pve-xterm-lineHeight", self.line_height);
+ }
+}
+
+#[derive(Clone, PartialEq, Properties)]
+#[builder]
+pub struct MySettingsDialog {
+ /// Dialog close callback.
+ #[builder_cb(IntoEventCallback, into_event_callback, ())]
+ #[prop_or_default]
+ pub on_close: Option<Callback<()>>,
+}
+
+impl Default for MySettingsDialog {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl MySettingsDialog {
+ pub fn new() -> Self {
+ yew::props!(Self {})
+ }
+}
+
+pub enum Msg {
+ XtermFormChange,
+ XtermSave,
+ XtermReset,
+ NoVncScaling(String),
+}
+
+#[doc(hidden)]
+pub struct PdmMySettingsDialog {
+ xterm_form: FormContext,
+ xterm_saved: XtermSettings,
+ novnc_scaling: PersistentState<Option<String>>,
+}
+
+impl PdmMySettingsDialog {
+ /// Returns the xterm.js settings as entered in the form, or `None` if they are not valid.
+ fn current_valid_xterm_settings(&self) -> Option<XtermSettings> {
+ let form = self.xterm_form.read();
+ if !form.is_valid() {
+ return None;
+ }
+ serde_json::from_value(form.get_submit_data()).ok()
+ }
+}
+
+impl Component for PdmMySettingsDialog {
+ type Message = Msg;
+ type Properties = MySettingsDialog;
+
+ fn create(ctx: &Context<Self>) -> Self {
+ Self {
+ xterm_form: FormContext::new().on_change(ctx.link().callback(|_| Msg::XtermFormChange)),
+ xterm_saved: XtermSettings::load(),
+ novnc_scaling: novnc_scaling_state(),
+ }
+ }
+
+ fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
+ match msg {
+ Msg::XtermFormChange => true,
+ Msg::XtermSave => {
+ if let Some(settings) = self.current_valid_xterm_settings() {
+ settings.save();
+ self.xterm_saved = settings;
+ }
+ true
+ }
+ Msg::XtermReset => {
+ self.xterm_saved = XtermSettings::default();
+ self.xterm_saved.save();
+ self.xterm_form.load_form(json!(self.xterm_saved));
+ true
+ }
+ Msg::NoVncScaling(scaling) => {
+ self.novnc_scaling
+ .update((!scaling.is_empty()).then_some(scaling));
+ false
+ }
+ }
+ }
+
+ fn view(&self, ctx: &Context<Self>) -> Html {
+ let props = ctx.props();
+ let link = ctx.link();
+
+ let current = self.current_valid_xterm_settings();
+ let can_save = current
+ .as_ref()
+ .is_some_and(|current| *current != self.xterm_saved);
+ let can_reset = current != Some(XtermSettings::default());
+
+ let section_title = |title: String| {
+ Container::new()
+ .class("pwt-font-title-medium")
+ .with_child(title)
+ };
+
+ let panel = InputPanel::new()
+ .padding(4)
+ .with_custom_child(section_title(tr!("xterm.js Settings")))
+ .with_field(
+ tr!("Font-Family"),
+ Field::new()
+ .name("fontFamily")
+ .placeholder(tr!("Default"))
+ .default(self.xterm_saved.font_family.clone()),
+ )
+ .with_field(
+ tr!("Font-Size"),
+ Number::<u64>::new()
+ .name("fontSize")
+ .min(1)
+ .placeholder(tr!("Default"))
+ .default(self.xterm_saved.font_size),
+ )
+ .with_field(
+ tr!("Letter Spacing"),
+ Number::<f64>::new()
+ .name("letterSpacing")
+ .placeholder(tr!("Default"))
+ .default(self.xterm_saved.letter_spacing),
+ )
+ .with_field(
+ tr!("Line Height"),
+ Number::<f64>::new()
+ .name("lineHeight")
+ .min(0.1)
+ .step(0.1)
+ .placeholder(tr!("Default"))
+ .default(self.xterm_saved.line_height),
+ )
+ .with_custom_child(
+ Row::new()
+ .gap(2)
+ .with_flex_spacer()
+ .with_child(
+ Button::new(tr!("Reset"))
+ .disabled(!can_reset)
+ .on_activate(link.callback(|_| Msg::XtermReset)),
+ )
+ .with_child(
+ Button::new(tr!("Save"))
+ .class(ColorScheme::Primary)
+ .disabled(!can_save)
+ .on_activate(link.callback(|_| Msg::XtermSave)),
+ ),
+ )
+ .with_custom_child(section_title(tr!("noVNC Settings")).padding_top(2))
+ .with_field(
+ tr!("Scaling mode"),
+ Combobox::from_key_value_pairs([
+ ("scale", tr!("Local Scaling")),
+ ("remote", tr!("Remote Resizing")),
+ ("off", tr!("Off")),
+ ])
+ .placeholder(tr!("Default"))
+ .default(self.novnc_scaling.clone())
+ .on_change(link.callback(Msg::NoVncScaling)),
+ );
+
+ Dialog::new(tr!("My Settings"))
+ .min_width(400)
+ .on_close(props.on_close.clone())
+ .with_child(
+ Form::new()
+ .form_context(self.xterm_form.clone())
+ .with_child(panel),
+ )
+ .into()
+ }
+}
+
+impl From<MySettingsDialog> for VNode {
+ fn from(val: MySettingsDialog) -> Self {
+ let comp = VComp::new::<PdmMySettingsDialog>(Rc::new(val), None);
+ VNode::from(comp)
+ }
+}
--
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 ` [PATCH yew-widget-toolkit v3 1/8] state: event: add helper to dispatch custom DOM events Dominik Csapak
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 ` Dominik Csapak [this message]
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-6-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.