diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-05-18 08:23:59 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-05-18 08:23:59 +0200 |
commit | fa98aba3d3bab9d08f58f45acfc697cb7992c5cb (patch) | |
tree | 74e28f66adfd4ab16ed519583fad8bbdcbcf9ce0 /lib/Travelynx.pm | |
parent | ccff20876496fdc465cd6c3fa7999329d68b28c5 (diff) |
Pre-select theme css in backend
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-x | lib/Travelynx.pm | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index c4a2b53..2c15154 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -93,6 +93,23 @@ sub startup { $self->defaults( layout => 'default' ); + $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_iris_main => sub { my ($self) = @_; |