otimização do suporte ao pwa

This commit is contained in:
Renan Bernordi 2025-01-10 16:50:25 -03:00
parent 8389a2110b
commit d97178b7ec
6 changed files with 33 additions and 20 deletions

View file

@ -28,7 +28,7 @@ Public instance at [marreta.pcdomanual.com](https://marreta.pcdomanual.com)!
- Everything with SSL/TLS - Everything with SSL/TLS
- PHP-FPM - PHP-FPM
- OPcache enabled - OPcache enabled
- PWA (Progressive Web App) support - PWA (Progressive Web App) support, direct sharing will only work on Android
## 🐳 Docker ## 🐳 Docker

View file

@ -28,7 +28,7 @@ Instancia publica em [marreta.pcdomanual.com](https://marreta.pcdomanual.com)!
- Tudo com SSL/TLS - Tudo com SSL/TLS
- PHP-FPM - PHP-FPM
- OPcache ligado - OPcache ligado
- Suporte a PWA (Progressive Web App) - Suporte a PWA (Progressive Web App), o compartilhamento direto irá funcionar somente no Android
## 🐳 Docker ## 🐳 Docker

View file

@ -65,15 +65,12 @@ $cache_folder = $cache->getCacheFileCount();
<link rel="icon" href="<?php echo SITE_URL; ?>/assets/svg/marreta.svg" type="image/svg+xml"> <link rel="icon" href="<?php echo SITE_URL; ?>/assets/svg/marreta.svg" type="image/svg+xml">
<meta name="theme-color" content="#2563eb"> <meta name="theme-color" content="#2563eb">
<link rel="manifest" href="<?php echo SITE_URL; ?>/manifest.json"> <link rel="manifest" href="<?php echo SITE_URL; ?>/manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <!-- PWA meta tags -->
<meta name="apple-mobile-web-app-title" content="<?php echo SITE_URL; ?>">
<link rel="apple-touch-icon" href="assets/pwa/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="180x180" href="assets/pwa/apple-touch-icon.png">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="application-name" content="<?php echo SITE_URL; ?>"> <meta name="application-name" content="<?php echo SITE_NAME; ?>">
<meta name="msapplication-TileColor" content="#2563eb">
<meta name="msapplication-tap-highlight" content="no"> <!-- Open Graph meta tags -->
<meta property="og:type" content="website" /> <meta property="og:type" content="website" />
<meta property="og:url" content="<?php echo SITE_URL; ?>" /> <meta property="og:url" content="<?php echo SITE_URL; ?>" />
<meta property="og:title" content="<?php echo SITE_NAME; ?>" /> <meta property="og:title" content="<?php echo SITE_NAME; ?>" />

View file

@ -3,10 +3,10 @@
* PWA Web Manifest Generator * PWA Web Manifest Generator
* *
* This file generates the Web App Manifest (manifest.json) for Progressive Web App (PWA) functionality. * 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). * 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'; require_once 'config.php';
@ -21,12 +21,11 @@ $manifest = [
'start_url' => SITE_URL, 'start_url' => SITE_URL,
'id' => SITE_URL, 'id' => SITE_URL,
'scope' => '/', 'scope' => '/',
'display' => 'browser', 'display' => 'standalone',
'display_override' => ['window-controls-overlay', 'minimal-ui'], 'display_override' => ['window-controls-overlay', 'minimal-ui'],
'background_color' => '#ffffff', 'background_color' => '#ffffff',
'theme_color' => '#2563eb', 'theme_color' => '#2563eb',
'orientation' => 'any', 'orientation' => 'any',
'categories' => ['utilities', 'productivity'],
'icons' => [ 'icons' => [
[ [
'src' => 'assets/pwa/192x192.png', 'src' => 'assets/pwa/192x192.png',
@ -39,12 +38,6 @@ $manifest = [
'sizes' => '512x512', 'sizes' => '512x512',
'type' => 'image/png', 'type' => 'image/png',
'purpose' => 'any maskable' 'purpose' => 'any maskable'
],
[
'src' => 'assets/pwa/apple-touch-icon.png',
'sizes' => '180x180',
'type' => 'image/png',
'purpose' => 'any'
] ]
], ],
'share_target' => [ 'share_target' => [

View file

@ -55,6 +55,13 @@ if (!empty($url) && isValidUrl($url)) {
elseif (!empty($text) && isValidUrl($text)) { elseif (!empty($text) && isValidUrl($text)) {
$redirect_url = $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 // If we have a valid URL, redirect to it
// Se temos uma URL válida, redireciona para ela // Se temos uma URL válida, redireciona para ela

View file

@ -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) => { self.addEventListener('fetch', (event) => {
event.respondWith(fetch(event.request)); 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) => { self.addEventListener('share_target', (event) => {
event.respondWith((async () => { event.respondWith((async () => {
const formData = await event.request.formData(); const formData = await event.request.formData();