aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Offline.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Offline.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Offline.pm63
1 files changed, 61 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Offline.pm b/perllib/FixMyStreet/App/Controller/Offline.pm
index f5d895318..e65642899 100644
--- a/perllib/FixMyStreet/App/Controller/Offline.pm
+++ b/perllib/FixMyStreet/App/Controller/Offline.pm
@@ -1,5 +1,9 @@
package FixMyStreet::App::Controller::Offline;
+
+use Image::Size;
+use JSON::MaybeXS;
use Moose;
+use Path::Tiny;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
@@ -10,19 +14,74 @@ FixMyStreet::App::Controller::Offline - Catalyst Controller
=head1 DESCRIPTION
-Offline pages Catalyst Controller.
+Offline pages Catalyst Controller - service worker and appcache.
=head1 METHODS
=cut
+sub manifest: Path("/.well-known/manifest.webmanifest") {
+ my ($self, $c) = @_;
+ $c->res->content_type('application/manifest+json');
+
+ my $theme = $c->model('DB::ManifestTheme')->find({ cobrand => $c->cobrand->moniker });
+ unless ( $theme ) {
+ $theme = $c->model('DB::ManifestTheme')->new({
+ name => $c->stash->{site_name},
+ short_name => $c->stash->{site_name},
+ background_colour => '#ffffff',
+ theme_colour => '#ffd000',
+ });
+ }
+
+ my @icons;
+ my $uri = '/theme/' . $c->cobrand->moniker;
+ my $theme_path = path(FixMyStreet->path_to('web' . $uri));
+ $theme_path->visit(
+ sub {
+ my ($x, $y, $typ) = Image::Size::imgsize($_->stringify);
+ push @icons, {
+ src => join('/', $uri, $_->basename),
+ sizes => join('x', $x, $y),
+ type => $typ eq 'PNG' ? 'image/png' : $typ eq 'GIF' ? 'image/gif' : $typ eq 'JPG' ? 'image/jpeg' : '',
+ };
+ }
+ );
+
+ unless (@icons) {
+ push @icons,
+ { src => "/cobrands/fixmystreet/images/192.png", sizes => "192x192", type => "image/png" },
+ { src => "/cobrands/fixmystreet/images/512.png", sizes => "512x512", type => "image/png" };
+ }
+
+ my $data = {
+ name => $theme->name,
+ short_name => $theme->short_name,
+ background_color => $theme->background_colour,
+ theme_color => $theme->theme_colour,
+ icons => \@icons,
+ lang => $c->stash->{lang_code},
+ display => "minimal-ui",
+ start_url => "/?pwa",
+ scope => "/",
+ };
+ if ($c->cobrand->can('manifest')) {
+ $data = { %$data, %{$c->cobrand->manifest} };
+ }
+
+ my $json = encode_json($data);
+ $c->res->body($json);
+}
+
+# Old appcache functions below
+
sub have_appcache : Private {
my ($self, $c) = @_;
return $c->user_exists && $c->user->has_body_permission_to('planned_reports')
&& !($c->user->is_superuser && FixMyStreet->staging_flag('enable_appcache', 0));
}
-sub manifest : Path("/offline/appcache.manifest") {
+sub appcache_manifest : Path("/offline/appcache.manifest") {
my ($self, $c) = @_;
unless ($c->forward('have_appcache')) {
$c->response->status(404);