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
- PHP-FPM
- OPcache enabled
- PWA (Progressive Web App) support
- PWA (Progressive Web App) support, direct sharing will only work on Android
## 🐳 Docker

View file

@ -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

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">
<meta name="theme-color" content="#2563eb">
<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">
<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">
<!-- PWA meta tags -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="application-name" content="<?php echo SITE_URL; ?>">
<meta name="msapplication-TileColor" content="#2563eb">
<meta name="msapplication-tap-highlight" content="no">
<meta name="application-name" content="<?php echo SITE_NAME; ?>">
<!-- Open Graph meta tags -->
<meta property="og:type" content="website" />
<meta property="og:url" content="<?php echo SITE_URL; ?>" />
<meta property="og:title" content="<?php echo SITE_NAME; ?>" />

View file

@ -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' => [

View file

@ -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

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) => {
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();