From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 400461FF0B7 for ; Mon, 30 Nov 2026 13:53:41 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 520192175B; Mon, 30 Nov 2026 13:53:31 +0100 (CET) From: Dominik Csapak 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 Message-ID: <20261130125325.2392967-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130125325.2392967-1-d.csapak@proxmox.com> References: <20261130125325.2392967-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.248 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: VWTGY7MDBLJHC2WWRCDV5A7QAOGGQY3J X-Message-ID-Hash: VWTGY7MDBLJHC2WWRCDV5A7QAOGGQY3J X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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> { + 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 = 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(key: &str) -> Option { + let res = local_storage()?.get_item(key).ok()??; + if res.is_empty() { + return None; + } + res.parse().ok() +} + +fn save_xterm_setting(key: &str, value: Option) { + 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, + font_size: Option, + letter_spacing: Option, + line_height: Option, +} + +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>, +} + +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>, +} + +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 { + 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 { + 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, 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) -> 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::::new() + .name("fontSize") + .min(1) + .placeholder(tr!("Default")) + .default(self.xterm_saved.font_size), + ) + .with_field( + tr!("Letter Spacing"), + Number::::new() + .name("letterSpacing") + .placeholder(tr!("Default")) + .default(self.xterm_saved.letter_spacing), + ) + .with_field( + tr!("Line Height"), + Number::::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 for VNode { + fn from(val: MySettingsDialog) -> Self { + let comp = VComp::new::(Rc::new(val), None); + VNode::from(comp) + } +} -- 2.47.3