From eeedb40bdc0510dec0e2ddca149e82bff7495d0a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 20 Apr 2020 20:20:52 +0200 Subject: switch to a proper dark theme using javascript and sass The dark=1 option is still supported, but no longer visible in the UI. --- lib/DBInfoscreen.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/DBInfoscreen.pm') diff --git a/lib/DBInfoscreen.pm b/lib/DBInfoscreen.pm index 6be6e2c..1828737 100644 --- a/lib/DBInfoscreen.pm +++ b/lib/DBInfoscreen.pm @@ -26,6 +26,24 @@ my %default = ( sub startup { my ($self) = @_; + $self->hook( + before_dispatch => sub { + my ($self) = @_; + + # The "theme" cookie is set client-side if the theme we delivered was + # changed by dark mode detection or by using the theme switcher. It's + # not part of Mojolicious' session data (and can't be, due to + # signing and HTTPOnly), so we need to add it here. + + for my $cookie ( @{ $self->req->cookies } ) { + if ( $cookie->name eq 'theme' ) { + $self->session( theme => $cookie->value ); + return; + } + } + } + ); + $self->attr( cache_hafas => sub { my ($self) = @_; -- cgit v1.2.3