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 093891FF0B4 for ; Fri, 27 Nov 2026 18:09:58 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C5DFD217BA; Fri, 27 Nov 2026 18:09:49 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings Date: Fri, 27 Nov 2026 18:09:24 +0100 Message-ID: <20261127170941.4183880-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261127170941.4183880-1-d.csapak@proxmox.com> References: <20261127170941.4183880-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.247 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: PE7TD42SUOLCTZFUZJGHAQ7BVF3OGR44 X-Message-ID-Hash: PE7TD42SUOLCTZFUZJGHAQ7BVF3OGR44 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', but is not yet used when opening a console. Signed-off-by: Dominik Csapak --- ui/Cargo.toml | 2 +- ui/src/top_nav_bar.rs | 16 +- ui/src/widget/mod.rs | 3 + ui/src/widget/my_settings_dialog.rs | 242 ++++++++++++++++++++++++++++ 4 files changed, 259 insertions(+), 4 deletions(-) create mode 100644 ui/src/widget/my_settings_dialog.rs diff --git a/ui/Cargo.toml b/ui/Cargo.toml index b538333b..5ee9489c 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/top_nav_bar.rs b/ui/src/top_nav_bar.rs index 99b5bbfd..015b6b13 100644 --- a/ui/src/top_nav_bar.rs +++ b/ui/src/top_nav_bar.rs @@ -24,7 +24,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}; #[derive(Deserialize)] pub struct VersionInfo { @@ -58,6 +58,7 @@ impl TopNavBar { #[derive(Clone)] pub enum ViewState { + MySettingsDialog, LanguageDialog, ThemeDialog, OpenTask((String, Option)), @@ -152,8 +153,14 @@ impl Component for PdmTopNavBar { .map(|cb| Callback::from(move |_event: MenuEvent| cb.emit(()))); 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") @@ -231,6 +238,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 07c47e36..888a0e19 100644 --- a/ui/src/widget/mod.rs +++ b/ui/src/widget/mod.rs @@ -1,6 +1,9 @@ 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..0ec84f71 --- /dev/null +++ b/ui/src/widget/my_settings_dialog.rs @@ -0,0 +1,242 @@ +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::props::StorageLocation; +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; + +// 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 { + local_storage()?.get_item(key).ok()??.parse().ok() +} + +fn save_xterm_setting(key: &str, value: Option) { + let Some(store) = local_storage() else { + return; + }; + let result = match value { + Some(value) => store.set_item(key, &value.to_string()), + 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: PersistentState::new(StorageLocation::local("novnc-scaling")), + } + } + + 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(|entered| *entered != 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) + .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