From fa98aba3d3bab9d08f58f45acfc697cb7992c5cb Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 18 May 2019 08:23:59 +0200 Subject: Pre-select theme css in backend --- lib/Travelynx.pm | 17 +++++++++++++++++ lib/Travelynx/Controller/Traveling.pm | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') 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) = @_; diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 3d2bb0c..f33a97f 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -10,7 +10,9 @@ sub homepage { if ( $self->is_user_authenticated ) { $self->render( 'landingpage', - version => $self->app->config->{version} // 'UNKNOWN', + + #version => $self->app->config->{version} // 'UNKNOWN', + version => join( '|||', @{ $self->req->cookies } ), with_autocomplete => 1, with_geolocation => 1 ); -- cgit v1.2.3 From 283f5aad0478059414f9fdfbfe2a14f35e07251a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 18 May 2019 08:29:21 +0200 Subject: remove debug output --- lib/Travelynx/Controller/Traveling.pm | 4 +--- templates/layouts/default.html.ep | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index f33a97f..3d2bb0c 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -10,9 +10,7 @@ sub homepage { if ( $self->is_user_authenticated ) { $self->render( 'landingpage', - - #version => $self->app->config->{version} // 'UNKNOWN', - version => join( '|||', @{ $self->req->cookies } ), + version => $self->app->config->{version} // 'UNKNOWN', with_autocomplete => 1, with_geolocation => 1 ); diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 4b11a06..00d446a 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -120,10 +120,7 @@ -- cgit v1.2.3