From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-manager v4 2/3] api: provide UI versions via index and /nodes/{node}/version
Date: Fri, 20 Nov 2026 10:46:38 +0100 [thread overview]
Message-ID: <20261120095235.1143525-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261120095235.1143525-1-d.csapak@proxmox.com>
Add a version string from the UI packages, so that the UI can easily
detect when the versions of the backend differ from the ones the page
was loaded with.
Generate the string via a shared `ui_version` helper that takes no
arguments, so that the index and API always produce the same string.
Cache the pwt versions locally for as long as the mtime does not change.
Stat'ing should be cached by the underlying filesystem and be very
cheap. This way we don't hit the file read on every call.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
PVE/API2/Nodes.pm | 14 +++++++++++++-
PVE/API2Tools.pm | 30 +++++++++++++++++++++++++++---
PVE/Service/pveproxy.pm | 3 +++
www/index.html.tpl | 3 ++-
4 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index b34d992c..ddbf7544 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -320,12 +320,24 @@ __PACKAGE__->register_method({
type => 'string',
description => 'The short git commit hash ID from which this version was build',
},
+ 'ui-version' => {
+ type => 'string',
+ optional => 1,
+ description =>
+ 'A string generated from UI package versions, to detect changes.',
+ },
},
},
code => sub {
my ($resp, $param) = @_;
- return PVE::pvecfg::version_info();
+ my $res = PVE::pvecfg::version_info();
+
+ if (my $ui_version = PVE::API2Tools::ui_version()) {
+ $res->{'ui-version'} = $ui_version;
+ }
+
+ return $res;
},
});
diff --git a/PVE/API2Tools.pm b/PVE/API2Tools.pm
index c53ec03f..dcd3dc36 100644
--- a/PVE/API2Tools.pm
+++ b/PVE/API2Tools.pm
@@ -18,6 +18,7 @@ use PVE::RPCEnvironment;
use PVE::SafeSyslog;
use PVE::Storage::Plugin;
use PVE::Tools;
+use PVE::pvecfg;
# each rrd key for a resource will only exist once. The key format might be different though. Therefore return on first hit
sub get_rrd_key {
@@ -280,10 +281,33 @@ sub pwt_base_dir {
return $PWT_BASE_DIR;
}
+my $pwt_version_cache = {};
+
sub read_pwt_version {
- my $wtversionraw = PVE::File::file_read_first_line($PWT_FILE) // '';
- my $wtversion = $wtversionraw =~ m|^// (.*)$| ? $1 : '';
- return $wtversion;
+ my $st = stat($PWT_FILE);
+ my $mtime = $st ? $st->mtime() : 0;
+
+ if (
+ !defined($pwt_version_cache->{version})
+ || $pwt_version_cache->{mtime} != $mtime
+ ) {
+ my $wtversionraw = PVE::File::file_read_first_line($PWT_FILE) // '';
+ my $wtversion = $wtversionraw =~ m|^// (.*)$| ? $1 : '';
+ $pwt_version_cache->{version} = $wtversion;
+ $pwt_version_cache->{mtime} = $mtime;
+ }
+
+ return $pwt_version_cache->{version};
+}
+
+# returns a combined pve-manager and proxmox-widget-toolkit version string
+# or undef if the pwt version was not readable or parseable
+sub ui_version {
+ my $manager_version = PVE::pvecfg::version_text();
+ my $pwt_version = read_pwt_version();
+ return undef if !$pwt_version;
+
+ return "$manager_version-$pwt_version";
}
1;
diff --git a/PVE/Service/pveproxy.pm b/PVE/Service/pveproxy.pm
index dc97f815..40c07ff6 100755
--- a/PVE/Service/pveproxy.pm
+++ b/PVE/Service/pveproxy.pm
@@ -264,6 +264,8 @@ sub get_index {
my $wtversion = PVE::API2Tools::read_pwt_version();
+ my $uiversion = PVE::API2Tools::ui_version();
+
# while we could use the actual pkg version (e.g., shipped as pkg-version file in each
# respective package's /usr/share/<pkg> folder, this way it should also work when using make
# install to directly install to local root filesystem.
@@ -287,6 +289,7 @@ sub get_index {
debug => $debug,
version => "$version",
wtversion => $wtversion,
+ uiversion => $uiversion,
theme => $theme,
consenttext => $consent_text,
i18n_js_mtime => $i18n_js_mtime,
diff --git a/www/index.html.tpl b/www/index.html.tpl
index 125c1046..466418ca 100644
--- a/www/index.html.tpl
+++ b/www/index.html.tpl
@@ -48,7 +48,8 @@
NodeArch: '[% arch %]',
UserName: '[% username %]',
CSRFPreventionToken: '[% token %]',
- ConsentText: '[% consenttext.squote %]'
+ ConsentText: '[% consenttext.squote %]',
+ UIVersion: '[% uiversion %]',
};
</script>
<script type="text/javascript" src="/proxmoxlib.js?ver=[% wtversion %]"></script>
--
2.47.3
next prev parent reply other threads:[~2026-11-20 9:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 9:46 [PATCH pve-manager v4 0/3] ui: prompt users for reload when web ui version changes Dominik Csapak
2026-11-20 9:46 ` [PATCH pve-manager v4 1/3] api: factor out read_pwt_version and pwt_base_dir Dominik Csapak
2026-11-20 9:46 ` Dominik Csapak [this message]
2026-11-20 9:46 ` [PATCH pve-manager v4 3/3] ui: workspace: show reload notice when UI packages were updated 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=20261120095235.1143525-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-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.