diff --git a/README.en.md b/README.en.md index 3f96d79..c34644b 100644 --- a/README.en.md +++ b/README.en.md @@ -28,7 +28,7 @@ Public instance at [marreta.pcdomanual.com](https://marreta.pcdomanual.com)! - Everything with SSL/TLS - PHP-FPM - OPcache enabled -- PWA (Progressive Web App) support +- PWA (Progressive Web App) support, direct sharing will only work on Android ## 🐳 Docker diff --git a/README.md b/README.md index 520a081..20bd082 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Instancia publica em [marreta.pcdomanual.com](https://marreta.pcdomanual.com)! - Tudo com SSL/TLS - PHP-FPM - OPcache ligado -- Suporte a PWA (Progressive Web App) +- Suporte a PWA (Progressive Web App), o compartilhamento direto irá funcionar somente no Android ## 🐳 Docker diff --git a/app/index.php b/app/index.php index f2dcc55..2cfccfb 100644 --- a/app/index.php +++ b/app/index.php @@ -65,15 +65,12 @@ $cache_folder = $cache->getCacheFileCount(); - - - - - + + - - - + + + diff --git a/app/manifest.php b/app/manifest.php index dfc768d..610477f 100644 --- a/app/manifest.php +++ b/app/manifest.php @@ -3,10 +3,10 @@ * PWA Web Manifest Generator * * This file generates the Web App Manifest (manifest.json) for Progressive Web App (PWA) functionality. - * It defines the application's behavior when installed on a device and its appearance in various contexts. + * It defines the application's behavior when installed on a device and its appearance. * * Este arquivo gera o Manifesto Web (manifest.json) para funcionalidade de Progressive Web App (PWA). - * Ele define o comportamento da aplicação quando instalada em um dispositivo e sua aparência em vários contextos. + * Ele define o comportamento da aplicação quando instalada em um dispositivo e sua aparência. */ require_once 'config.php'; @@ -21,12 +21,11 @@ $manifest = [ 'start_url' => SITE_URL, 'id' => SITE_URL, 'scope' => '/', - 'display' => 'browser', + 'display' => 'standalone', 'display_override' => ['window-controls-overlay', 'minimal-ui'], 'background_color' => '#ffffff', 'theme_color' => '#2563eb', 'orientation' => 'any', - 'categories' => ['utilities', 'productivity'], 'icons' => [ [ 'src' => 'assets/pwa/192x192.png', @@ -39,12 +38,6 @@ $manifest = [ 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'any maskable' - ], - [ - 'src' => 'assets/pwa/apple-touch-icon.png', - 'sizes' => '180x180', - 'type' => 'image/png', - 'purpose' => 'any' ] ], 'share_target' => [ diff --git a/app/pwa.php b/app/pwa.php index e310ece..d9f638c 100644 --- a/app/pwa.php +++ b/app/pwa.php @@ -55,6 +55,13 @@ if (!empty($url) && isValidUrl($url)) { elseif (!empty($text) && isValidUrl($text)) { $redirect_url = $text; } +// If text is not a URL but contains content, try to extract URL from it +// Se o texto não é uma URL mas contém conteúdo, tenta extrair URL dele +elseif (!empty($text)) { + if (preg_match('/https?:\/\/[^\s]+/', $text, $matches)) { + $redirect_url = $matches[0]; + } +} // If we have a valid URL, redirect to it // Se temos uma URL válida, redireciona para ela diff --git a/app/service-worker.js b/app/service-worker.js index f0faad2..621bc4e 100644 --- a/app/service-worker.js +++ b/app/service-worker.js @@ -1,7 +1,23 @@ +/** + * Service Worker for Marreta App + * + * The service worker acts as a network proxy and share target handler, + * enabling the PWA to receive shared URLs from other applications. + * + * O service worker atua como um proxy de rede e manipulador de compartilhamento, + * permitindo que o PWA receba URLs compartilhadas de outros aplicativos. + */ + +// Handles all network requests +// Gerencia todas as requisições de rede self.addEventListener('fetch', (event) => { event.respondWith(fetch(event.request)); }); +/** + * Share target event handler - processes URLs shared from other applications + * Manipulador do evento share_target - processa URLs compartilhadas de outros aplicativos + */ self.addEventListener('share_target', (event) => { event.respondWith((async () => { const formData = await event.request.formData();