From 6e4c9d684d5fdf9998551c96cdb84e302845a940 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 26 Aug 2021 18:03:17 +0000 Subject: port latest pwa work from zap --- ServiceWorker.js | 10 ++++ Zotlabs/Module/Manifest.php | 52 ++++++++++++++++++++ Zotlabs/Module/Rpost.php | 67 ++++++++++++++++++++++++++ boot.php | 4 ++ images/app/hz-120.png | Bin 0 -> 5552 bytes images/app/hz-128.png | Bin 0 -> 5885 bytes images/app/hz-144.png | Bin 0 -> 6692 bytes images/app/hz-152.png | Bin 0 -> 7050 bytes images/app/hz-180.png | Bin 0 -> 8522 bytes images/app/hz-192.png | Bin 0 -> 9058 bytes images/app/hz-384.png | Bin 0 -> 19032 bytes images/app/hz-512.png | Bin 0 -> 26021 bytes images/app/hz-72.png | Bin 0 -> 3332 bytes images/app/hz-96.png | Bin 0 -> 4430 bytes images/app/hz.svg | 112 ++++++++++++++++++++++++++++++++++++++++++++ view/js/main.js | 9 ++++ 16 files changed, 254 insertions(+) create mode 100644 ServiceWorker.js create mode 100644 Zotlabs/Module/Manifest.php create mode 100644 images/app/hz-120.png create mode 100644 images/app/hz-128.png create mode 100644 images/app/hz-144.png create mode 100644 images/app/hz-152.png create mode 100644 images/app/hz-180.png create mode 100644 images/app/hz-192.png create mode 100644 images/app/hz-384.png create mode 100644 images/app/hz-512.png create mode 100644 images/app/hz-72.png create mode 100644 images/app/hz-96.png create mode 100644 images/app/hz.svg diff --git a/ServiceWorker.js b/ServiceWorker.js new file mode 100644 index 000000000..1b84fdfb7 --- /dev/null +++ b/ServiceWorker.js @@ -0,0 +1,10 @@ +// This file should be served from the web root to avoid scope and cookie related issues with some browsers +self.addEventListener('install', function(e) { + console.log('install event'); +}); + +self.addEventListener('fetch', function(e) { + // nothing here yet + return; +}); + diff --git a/Zotlabs/Module/Manifest.php b/Zotlabs/Module/Manifest.php new file mode 100644 index 000000000..5297245d3 --- /dev/null +++ b/Zotlabs/Module/Manifest.php @@ -0,0 +1,52 @@ + ucfirst(System::get_platform_name()), + 'short_name' => ucfirst(System::get_platform_name()), + 'icons' => [ + [ 'src' => '/images/app/hz-72.png', 'sizes' => '72x72', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-96.png', 'sizes' => '96x96', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-128.png', 'sizes' => '128x128', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-144.png', 'sizes' => '144x144', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-152.png', 'sizes' => '152x152', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-192.png', 'sizes' => '192x192', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-348.png', 'sizes' => '384x384', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz-512.png', 'sizes' => '512x512', 'type' => 'image/png' ], + [ 'src' => '/images/app/hz.svg', 'sizes' => '64x64', 'type' => 'image/xml+svg' ] + ], + 'scope' => '/', + 'start_url' => z_root(), + 'display' => 'standalone', + 'orientation' => 'any', + 'theme_color' => '#343a40', + 'background_color' => 'white', + 'share_target' => [ + 'action' => '/rpost', + 'method' => 'POST', + 'enctype' => 'multipart/form-data', + 'params' => [ + 'title' => 'title', + 'text' => 'body', + 'url' => 'url', + 'files' => [ + [ 'name' => 'userfile', + 'accept' => [ 'image/*', 'audio/*', 'video/*', 'text/*', 'application/*' ] + ] + ] + ] + ] + ]; + + json_return_and_die($ret,'application/manifest+json'); + } + +} diff --git a/Zotlabs/Module/Rpost.php b/Zotlabs/Module/Rpost.php index 80ad289b2..013817597 100644 --- a/Zotlabs/Module/Rpost.php +++ b/Zotlabs/Module/Rpost.php @@ -66,6 +66,73 @@ class Rpost extends \Zotlabs\Web\Controller { nav_set_selected('Post'); + if (local_channel() && array_key_exists('userfile',$_FILES)) { + + $channel = App::get_channel(); + $observer = App::get_observer(); + + $def_album = get_pconfig($channel['channel_id'],'system','photo_path'); + $def_attach = get_pconfig($channel['channel_id'],'system','attach_path'); + + $r = attach_store($channel, (($observer) ? $observer['xchan_hash'] : ''), '', [ + 'source' => 'editor', + 'visible' => 0, + 'album' => $def_album, + 'directory' => $def_attach, + 'flags' => 1, // indicates temporary permissions are created + 'allow_cid' => '<' . $channel['channel_hash'] . '>' + ]); + + if (! $r['success']) { + notice( $r['message'] . EOL); + } + + $s = EMPTY_STR; + + if (intval($r['data']['is_photo'])) { + $s .= "\n\n" . $r['body'] . "\n\n"; + } + + $url = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path']; + + if (strpos($r['data']['filetype'],'video') === 0) { + $s .= "\n\n" . '[zvideo]' . $url . '[/zvideo]' . "\n\n"; + } + + if (strpos($r['data']['filetype'],'audio') === 0) { + $s .= "\n\n" . '[zaudio]' . $url . '[/zaudio]' . "\n\n"; + } + + if ($r['data']['filetype'] === 'image/svg+xml') { + $x = @file_get_contents('store/' . $channel['channel_address'] . '/' . $r['data']['os_path']); + if ($x) { + $bb = svg2bb($x); + if ($bb) { + $s .= "\n\n" . $bb; + } + else { + logger('empty return from svgbb'); + } + } + else { + logger('unable to read svg data file: ' . 'store/' . $channel['channel_address'] . '/' . $r['data']['os_path']); + } + } + + if ($r['data']['filetype'] === 'text/calendar') { + $content = @file_get_contents('store/' . $channel['channel_address'] . '/' . $r['data']['os_path']); + if ($content) { + $ev = ical_to_ev($content); + if ($ev) { + $s .= "\n\n" . format_event_bbcode($ev[0]) . "\n\n"; + } + } + } + + $s .= "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n"; + $_REQUEST['body'] = ((array_key_exists('body',$_REQUEST)) ? $_REQUEST['body'] . $s : $s); + } + // If we have saved rpost session variables, but nothing in the current $_REQUEST, recover the saved variables if((! array_key_exists('body',$_REQUEST)) && (array_key_exists('rpost',$_SESSION))) { diff --git a/boot.php b/boot.php index ab23365c4..c2d08f87a 100644 --- a/boot.php +++ b/boot.php @@ -1198,6 +1198,10 @@ class App { } } + // webmanifest + head_add_link(['rel' => 'manifest', 'href' => '/manifest.json']); + self::$meta->set('application-name', Zotlabs\Lib\System::get_platform_name()); + self::$meta->set('generator', Zotlabs\Lib\System::get_platform_name()); head_add_link(['rel' => 'shortcut icon', 'href' => head_get_icon()]); diff --git a/images/app/hz-120.png b/images/app/hz-120.png new file mode 100644 index 000000000..a9acf1f17 Binary files /dev/null and b/images/app/hz-120.png differ diff --git a/images/app/hz-128.png b/images/app/hz-128.png new file mode 100644 index 000000000..327d1cc27 Binary files /dev/null and b/images/app/hz-128.png differ diff --git a/images/app/hz-144.png b/images/app/hz-144.png new file mode 100644 index 000000000..58b9b205a Binary files /dev/null and b/images/app/hz-144.png differ diff --git a/images/app/hz-152.png b/images/app/hz-152.png new file mode 100644 index 000000000..bdd9e81c4 Binary files /dev/null and b/images/app/hz-152.png differ diff --git a/images/app/hz-180.png b/images/app/hz-180.png new file mode 100644 index 000000000..f43d39af1 Binary files /dev/null and b/images/app/hz-180.png differ diff --git a/images/app/hz-192.png b/images/app/hz-192.png new file mode 100644 index 000000000..e10aa6502 Binary files /dev/null and b/images/app/hz-192.png differ diff --git a/images/app/hz-384.png b/images/app/hz-384.png new file mode 100644 index 000000000..687500cee Binary files /dev/null and b/images/app/hz-384.png differ diff --git a/images/app/hz-512.png b/images/app/hz-512.png new file mode 100644 index 000000000..86206a0da Binary files /dev/null and b/images/app/hz-512.png differ diff --git a/images/app/hz-72.png b/images/app/hz-72.png new file mode 100644 index 000000000..52e3baf76 Binary files /dev/null and b/images/app/hz-72.png differ diff --git a/images/app/hz-96.png b/images/app/hz-96.png new file mode 100644 index 000000000..f2590eedc Binary files /dev/null and b/images/app/hz-96.png differ diff --git a/images/app/hz.svg b/images/app/hz.svg new file mode 100644 index 000000000..61ca9e1d4 --- /dev/null +++ b/images/app/hz.svg @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/view/js/main.js b/view/js/main.js index 68f3415ee..d121913ea 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -34,6 +34,7 @@ if(localStorage.getItem('uid') !== localUser.toString()) { sessionStorage.clear(); localStorage.setItem('uid', localUser.toString()); } + window.onstorage = function(e) { if(e.key === 'uid' && parseInt(e.newValue) !== localUser) { if(window_needs_alert) { @@ -45,6 +46,14 @@ window.onstorage = function(e) { } } +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/ServiceWorker.js', { scope: '/' }).then(function(registration) { + console.log('Service worker registered. scope is', registration.scope); + }).catch(function(error) { + console.log('Service worker registration failed because ' + error); + }); +} + $.ajaxSetup({cache: false}); $(document).ready(function() { -- cgit v1.2.3