aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Offline.pm63
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm9
-rw-r--r--perllib/FixMyStreet/TestMech.pm2
-rw-r--r--t/app/controller/offline.t36
-rw-r--r--templates/web/base/common_header_tags.html1
-rw-r--r--templates/web/base/offline/appcache_manifest.html (renamed from templates/web/base/offline/manifest.html)0
-rwxr-xr-xweb/cobrands/fixmystreet/images/192.pngbin0 -> 6327 bytes
-rwxr-xr-xweb/cobrands/fixmystreet/images/512.pngbin0 -> 20416 bytes
10 files changed, 111 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 9c6297b3d..974f82187 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,8 @@ FixMyBarangay.po
# Photo upload cache
/web/photo
+# And theme upload
+/web/theme
# Installation
/local
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c4f7bde7a..c710e1e03 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@
- Display map inline with duplicate suggestions on mobile. #2668
- Improved try again process on mobile. #2863
- Improve messaging/display of private reports.
+ - Add a web manifest. #2220
- Admin improvements:
- Add new roles system, to group permissions and apply to users. #2483
- Contact form emails now include user admin links.
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);
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 8339ceede..ba82949c7 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -351,4 +351,13 @@ sub update_email_shortlisted_user {
FixMyStreet::Cobrand::TfL::update_email_shortlisted_user($self, $update);
}
+sub manifest {
+ return {
+ related_applications => [
+ { platform => 'play', url => 'https://play.google.com/store/apps/details?id=org.mysociety.FixMyStreet', id => 'org.mysociety.FixMyStreet' },
+ { platform => 'itunes', url => 'https://apps.apple.com/gb/app/fixmystreet/id297456545', id => 'id297456545' },
+ ],
+ };
+}
+
1;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 5bb975104..1b7fba1bd 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -585,7 +585,7 @@ sub get_ok_json {
# check that the content-type of response is correct
croak "Response was not JSON"
- unless $res->header('Content-Type') =~ m{^application/json\b};
+ unless $res->header('Content-Type') =~ m{^application/(?:[a-z]+\+)?json\b};
return decode_json( $res->content );
}
diff --git a/t/app/controller/offline.t b/t/app/controller/offline.t
new file mode 100644
index 000000000..505e605a0
--- /dev/null
+++ b/t/app/controller/offline.t
@@ -0,0 +1,36 @@
+use FixMyStreet::TestMech;
+use Path::Tiny;
+
+my $mech = FixMyStreet::TestMech->new;
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'test'
+}, sub {
+ my $theme_dir = path(FixMyStreet->path_to('web/theme/test'));
+ $theme_dir->mkpath;
+ my $image_path = path('t/app/controller/sample.jpg');
+ $image_path->copy($theme_dir->child('sample.jpg'));
+ subtest 'manifest' => sub {
+ my $j = $mech->get_ok_json('/.well-known/manifest.webmanifest');
+ is $j->{name}, 'FixMyStreet', 'correct name';
+ is $j->{theme_color}, '#ffd000', 'correct theme colour';
+ is_deeply $j->{icons}[0], {
+ type => 'image/jpeg',
+ src => '/theme/test/sample.jpg',
+ sizes => '133x100'
+ }, 'correct icon';
+ };
+ $theme_dir->remove_tree;
+};
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet'
+}, sub {
+ subtest '.com manifest' => sub {
+ my $j = $mech->get_ok_json('/.well-known/manifest.webmanifest');
+ is $j->{related_applications}[0]{platform}, 'play', 'correct app';
+ is $j->{icons}[0]{sizes}, '192x192', 'correct fallback size';
+ };
+};
+
+done_testing(); \ No newline at end of file
diff --git a/templates/web/base/common_header_tags.html b/templates/web/base/common_header_tags.html
index 728b81363..d54d97297 100644
--- a/templates/web/base/common_header_tags.html
+++ b/templates/web/base/common_header_tags.html
@@ -1,6 +1,7 @@
[% SET start = c.config.ADMIN_BASE_URL IF admin %]
<meta http-equiv="content-type" content="text/html; charset=utf-8">
+<link rel="manifest" href="/.well-known/manifest.webmanifest">
[% IF csrf_token %]
<meta content="[% csrf_token %]" name="csrf-token" />
diff --git a/templates/web/base/offline/manifest.html b/templates/web/base/offline/appcache_manifest.html
index 93d26cb94..93d26cb94 100644
--- a/templates/web/base/offline/manifest.html
+++ b/templates/web/base/offline/appcache_manifest.html
diff --git a/web/cobrands/fixmystreet/images/192.png b/web/cobrands/fixmystreet/images/192.png
new file mode 100755
index 000000000..e43a3bb37
--- /dev/null
+++ b/web/cobrands/fixmystreet/images/192.png
Binary files differ
diff --git a/web/cobrands/fixmystreet/images/512.png b/web/cobrands/fixmystreet/images/512.png
new file mode 100755
index 000000000..13cf165d3
--- /dev/null
+++ b/web/cobrands/fixmystreet/images/512.png
Binary files differ