public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Sterz <s.sterz@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v1 2/4] pveproxy/template: add support for switching themes
Date: Wed,  8 Mar 2023 17:40:07 +0100	[thread overview]
Message-ID: <20230308164010.2463409-2-s.sterz@proxmox.com> (raw)
In-Reply-To: <20230308164010.2463409-1-s.sterz@proxmox.com>

load the dark theme only if requested through a cookie, also adds
support for the "auto" theme that uses the dark theme based on a
media query.

this requires a bump of the widget toolkit so the dark-theme css file
is available.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
---
 PVE/Service/pveproxy.pm | 13 +++++++++++++
 www/index.html.tpl      |  8 ++++++++
 2 files changed, 21 insertions(+)

diff --git a/PVE/Service/pveproxy.pm b/PVE/Service/pveproxy.pm
index f73fdd6f..3fd76128 100755
--- a/PVE/Service/pveproxy.pm
+++ b/PVE/Service/pveproxy.pm
@@ -88,6 +88,7 @@ sub init {
     add_dirs($dirs, '/xtermjs/' => "$basedirs->{xtermjs}/");
     add_dirs($dirs, '/pwt/images/' => "$basedirs->{widgettoolkit}/images/");
     add_dirs($dirs, '/pwt/css/' => "$basedirs->{widgettoolkit}/css/");
+    add_dirs($dirs, '/pwt/themes/' => "$basedirs->{widgettoolkit}/themes/");
 
     $self->{server_config} = {
 	title => 'Proxmox VE API',
@@ -191,6 +192,7 @@ sub get_index {
     my $lang;
     my $username;
     my $token = 'null';
+    my $theme = "";
 
     if (my $cookie = $r->header('Cookie')) {
 	if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
@@ -198,6 +200,15 @@ sub get_index {
 		$lang = $newlang;
 	    }
 	}
+
+	if (my $newtheme = ($cookie =~ /(?:^|\s)PVEThemeCookie=([^;]*)/)[0]) {
+	    # theme names need to be kebab case, with each segment a maximum of 10 characters long
+	    # and at most 6 segments
+	    if ($newtheme =~ m/^[a-z]{1,10}(-[a-z]{1,10}){0,5}$/) {
+		$theme = $newtheme;
+	    }
+	}
+
 	my $ticket = PVE::APIServer::Formatter::extract_auth_value($cookie, $server->{cookie_name});
 	if (($username = PVE::AccessControl::verify_ticket($ticket, 1))) {
 	    $token = PVE::AccessControl::assemble_csrf_prevention_token($username);
@@ -252,6 +263,8 @@ sub get_index {
 	debug => $debug,
 	version => "$version",
 	wtversion => $wtversion,
+	theme => $theme,
+	auto => $theme == "auto",
     };
 
     # by default, load the normal index
diff --git a/www/index.html.tpl b/www/index.html.tpl
index 0c819977..be31dd40 100644
--- a/www/index.html.tpl
+++ b/www/index.html.tpl
@@ -12,6 +12,14 @@
     <link rel="stylesheet" type="text/css" href="/pve2/fa/css/font-awesome.css" />
     <link rel="stylesheet" type="text/css" href="/pve2/css/ext6-pve.css?ver=[% version %]" />
     <link rel="stylesheet" type="text/css" href="/pwt/css/ext6-pmx.css?ver=[% wtversion %]" />
+    [%- IF theme %]
+      [%- IF theme == 'auto' %]
+    <link rel="stylesheet" type="text/css" media="(prefers-color-scheme: dark)" href="/pwt/themes/theme-proxmox-dark.css?ver=[% wtversion %]" />
+      [%- ELSE %]
+    <link rel="stylesheet" type="text/css" href="/pwt/themes/theme-[% theme %].css?ver=[% wtversion %]" />
+      [%- END -%]
+    [%- END -%]
+
     [% IF langfile %]
     <script type='text/javascript' src='/pve2/locale/pve-lang-[% lang %].js?ver=[% version %]'></script>
     [%- ELSE %]
-- 
2.30.2





  reply	other threads:[~2023-03-08 16:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 16:18 [pve-devel] [PATCH widget-toolkit v1] Proxmox Dark Theme Stefan Sterz
2023-03-08 16:25 ` Stefan Sterz
2023-03-08 16:33 ` [pve-devel] [PATCH widget-toolkit v1 1/6] dark-theme: add initial version of the proxmox-dark theme Stefan Sterz
2023-03-08 16:36 ` [pve-devel] [PATCH widget-toolkit v1 2/6] subscription/summary/backup: stop setting the background color Stefan Sterz
2023-03-08 16:36   ` [pve-devel] [PATCH widget-toolkit v1 3/6] gauge widget: add support for a dark theme and dynamic theme switching Stefan Sterz
2023-03-08 16:36   ` [pve-devel] [PATCH widget-toolkit v1 4/6] rrd chart: add support for the " Stefan Sterz
2023-03-08 16:37 ` [pve-devel] [PATCH widget-toolkit v1 5/6] util/window/form: add a theme selector Stefan Sterz
2023-03-08 16:37   ` [pve-devel] [PATCH widget-toolkit v1 6/6] dark-theme: add support for the pmg quarantine theme toggle Stefan Sterz
2023-03-08 16:40 ` [pve-devel] [PATCH manager v1 1/4] gui: create user info menu intro for selecting the theme Stefan Sterz
2023-03-08 16:40   ` Stefan Sterz [this message]
2023-03-08 16:40   ` [pve-devel] [PATCH manager v1 3/4] subscription/summary/backup: stop setting the background color Stefan Sterz
2023-03-08 16:40   ` [pve-devel] [PATCH manager v1 4/4] ui: make ceph charts change color more dynamically Stefan Sterz
2023-03-08 16:40   ` [pve-devel] [PATCH docs v1] docs: add dark mode support to the api viewer Stefan Sterz
2023-03-08 17:05   ` [pve-devel] applied-series: [PATCH manager v1 1/4] gui: create user info menu intro for selecting the theme Thomas Lamprecht
2023-03-09  8:07     ` [pve-devel] Shell command and Emacs Lisp code injection in emacsclient-mail.desktop Stefan Sterz
2023-03-09  8:16       ` [pve-devel] applied-series: [PATCH manager v1 1/4] gui: create user info menu intro for selecting the theme Thomas Lamprecht
2023-03-09  8:29         ` Stefan Sterz
2023-03-08 17:04 ` [pve-devel] applied-series: [PATCH widget-toolkit v1] Proxmox Dark Theme Thomas Lamprecht

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=20230308164010.2463409-2-s.sterz@proxmox.com \
    --to=s.sterz@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal