feat: als pwa installierbar
- Manifest 'LAN-Clipboard' / 'Clipboard', standalone, eigene Icons (auch maskable) - iOS: apple-touch-icon, Web-App-Metadaten, Statusleiste black-translucent - Service Worker (vite-plugin-pwa) cacht nur die App-Hülle, nie /api - Hinweis 'Neue Version verfügbar' mit Neu laden - Offline-Seite, wenn beim Start kein Server erreichbar ist - Icons per scripts/render-icons.sh aus SVG gerendert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No files matched your search
@@ -1 +1,2 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
/// <reference types="vite-plugin-pwa/client" />
|
||||||
@@ -5,7 +5,12 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||||
<meta name="color-scheme" content="dark" />
|
<meta name="color-scheme" content="dark" />
|
||||||
<meta name="theme-color" content="#0f1115" />
|
<meta name="theme-color" content="#0f1115" />
|
||||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml" />
|
||||||
|
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
|
||||||
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
|
<meta name="apple-mobile-web-app-title" content="Clipboard" />
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||||
<title>LAN-Clipboard</title>
|
<title>LAN-Clipboard</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
"typescript": "^6.0.3",
|
"typescript": "^6.0.3",
|
||||||
"typescript-eslint": "^8.72.0",
|
"typescript-eslint": "^8.72.0",
|
||||||
"vite": "^8.3.5",
|
"vite": "^8.3.5",
|
||||||
|
"vite-plugin-pwa": "^2.0.0",
|
||||||
"vitest": "^5.0.5",
|
"vitest": "^5.0.5",
|
||||||
"vue-tsc": "^3.3.13"
|
"vue-tsc": "^3.3.13"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect x="6" y="4" width="20" height="25" rx="3" fill="#1b1f27" stroke="#6ea8fe" stroke-width="2"/><rect x="11" y="2" width="10" height="5" rx="1.5" fill="#6ea8fe"/><path d="M11 14h10M11 19h10M11 24h6" stroke="#9aa4b2" stroke-width="2" stroke-linecap="round"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 326 B |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
@@ -0,0 +1,9 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="100%" height="100%">
|
||||||
|
<!-- Full-bleed background; motif stays inside the central safe zone (80 %) -->
|
||||||
|
<rect width="512" height="512" fill="#0f1115"/>
|
||||||
|
<g transform="translate(256 256) scale(0.78) translate(-256 -248)">
|
||||||
|
<rect x="128" y="104" width="256" height="320" rx="36" fill="#1b1f27" stroke="#6ea8fe" stroke-width="20"/>
|
||||||
|
<rect x="196" y="72" width="120" height="64" rx="18" fill="#6ea8fe"/>
|
||||||
|
<path d="M184 216h144M184 280h144M184 344h88" stroke="#9aa4b2" stroke-width="22" stroke-linecap="round"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 601 B |
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="100%" height="100%">
|
||||||
|
<rect width="512" height="512" rx="112" fill="#0f1115"/>
|
||||||
|
<rect x="128" y="104" width="256" height="320" rx="36" fill="#1b1f27" stroke="#6ea8fe" stroke-width="20"/>
|
||||||
|
<rect x="196" y="72" width="120" height="64" rx="18" fill="#6ea8fe"/>
|
||||||
|
<path d="M184 216h144M184 280h144M184 344h88" stroke="#9aa4b2" stroke-width="22" stroke-linecap="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 445 B |
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Renders the PWA icons from the SVG sources with headless Chromium (Playwright image).
|
||||||
|
# Usage (from frontend/): sh scripts/render-icons.sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
IMAGE=mcr.microsoft.com/playwright:v1.63.0-noble
|
||||||
|
CHROME=/ms-playwright/chromium_headless_shell-1243/chrome-headless-shell-linux64/chrome-headless-shell
|
||||||
|
|
||||||
|
render() { # <svg> <size> <png>
|
||||||
|
docker run --rm -v "$PWD/public/icons:/icons" "$IMAGE" "$CHROME" \
|
||||||
|
--no-sandbox --hide-scrollbars --default-background-color=00000000 \
|
||||||
|
--window-size="$2,$2" --screenshot="/icons/$3" "file:///icons/$1" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
render icon.svg 192 icon-192.png
|
||||||
|
render icon.svg 512 icon-512.png
|
||||||
|
render icon-maskable.svg 512 icon-maskable-512.png
|
||||||
|
render icon-maskable.svg 180 apple-touch-icon.png
|
||||||
|
echo "Icons rendered into public/icons/"
|
||||||
@@ -3,6 +3,7 @@ import { watch } from 'vue'
|
|||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
|
|
||||||
import AppHeader from '@/components/AppHeader.vue'
|
import AppHeader from '@/components/AppHeader.vue'
|
||||||
|
import UpdateBanner from '@/components/UpdateBanner.vue'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import { useClipsStore } from '@/stores/clips'
|
import { useClipsStore } from '@/stores/clips'
|
||||||
import { useSyncStore } from '@/stores/sync'
|
import { useSyncStore } from '@/stores/sync'
|
||||||
@@ -28,4 +29,5 @@ watch(
|
|||||||
<template>
|
<template>
|
||||||
<AppHeader v-if="auth.user" />
|
<AppHeader v-if="auth.user" />
|
||||||
<RouterView />
|
<RouterView />
|
||||||
|
<UpdateBanner />
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { applyUpdate, updateAvailable } from '@/pwa'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-if="updateAvailable" class="update-banner" role="status">
|
||||||
|
<span>Neue Version verfügbar</span>
|
||||||
|
<button type="button" class="primary small" @click="applyUpdate">Neu laden</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.update-banner {
|
||||||
|
position: fixed;
|
||||||
|
left: 50%;
|
||||||
|
bottom: calc(1rem + env(safe-area-inset-bottom));
|
||||||
|
z-index: 20;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 0.5rem 0.5rem 0.5rem 1rem;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--accent);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
box-shadow: 0 4px 16px rgb(0 0 0 / 40%);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -6,6 +6,7 @@ import { createApp } from 'vue'
|
|||||||
|
|
||||||
import { setUnauthorizedHandler } from './api/client'
|
import { setUnauthorizedHandler } from './api/client'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
import { initPwa } from './pwa'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import { useAuthStore } from './stores/auth'
|
import { useAuthStore } from './stores/auth'
|
||||||
|
|
||||||
@@ -23,3 +24,4 @@ setUnauthorizedHandler(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
initPwa()
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
import { registerSW } from 'virtual:pwa-register'
|
||||||
|
|
||||||
|
/** True when a new version has been downloaded and waits for the user to reload. */
|
||||||
|
export const updateAvailable = ref(false)
|
||||||
|
|
||||||
|
let updateServiceWorker: ((reload?: boolean) => Promise<void>) | undefined
|
||||||
|
|
||||||
|
export function initPwa(): void {
|
||||||
|
if (!('serviceWorker' in navigator)) return
|
||||||
|
updateServiceWorker = registerSW({
|
||||||
|
onNeedRefresh() {
|
||||||
|
updateAvailable.value = true
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyUpdate(): void {
|
||||||
|
void updateServiceWorker?.(true)
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
|
|
||||||
|
import { ApiError } from '@/api/client'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import HomeView from '@/views/HomeView.vue'
|
import HomeView from '@/views/HomeView.vue'
|
||||||
|
|
||||||
@@ -33,13 +34,24 @@ const router = createRouter({
|
|||||||
component: () => import('@/views/AdminUsersView.vue'),
|
component: () => import('@/views/AdminUsersView.vue'),
|
||||||
meta: { admin: true },
|
meta: { admin: true },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/offline',
|
||||||
|
name: 'offline',
|
||||||
|
component: () => import('@/views/OfflineView.vue'),
|
||||||
|
meta: { public: true },
|
||||||
|
},
|
||||||
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach(async (to) => {
|
router.beforeEach(async (to) => {
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
await auth.ensureLoaded()
|
try {
|
||||||
|
await auth.ensureLoaded()
|
||||||
|
} catch (e) {
|
||||||
|
// Network failure (not an HTTP error): the app shell came from the service worker cache
|
||||||
|
if (!(e instanceof ApiError) && to.name !== 'offline') return { name: 'offline' }
|
||||||
|
}
|
||||||
|
|
||||||
if (to.meta.public) {
|
if (to.meta.public) {
|
||||||
return auth.user && to.name === 'login' ? { name: 'home' } : true
|
return auth.user && to.name === 'login' ? { name: 'home' } : true
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
async function fetchMe(): Promise<void> {
|
async function fetchMe(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
user.value = await api.get<User>('/auth/me')
|
user.value = await api.get<User>('/auth/me')
|
||||||
|
loaded.value = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!(e instanceof ApiError) || e.status !== 401) throw e
|
if (!(e instanceof ApiError) || e.status !== 401) throw e // retry on next navigation
|
||||||
user.value = null
|
user.value = null
|
||||||
} finally {
|
|
||||||
loaded.value = true
|
loaded.value = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
function retry(): void {
|
||||||
|
window.location.assign('/')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<main class="offline">
|
||||||
|
<h1>Keine Verbindung</h1>
|
||||||
|
<p class="muted">
|
||||||
|
Der Server ist gerade nicht erreichbar. Clips werden aus Datenschutzgründen nicht auf dem
|
||||||
|
Gerät gespeichert und sind daher nur online verfügbar.
|
||||||
|
</p>
|
||||||
|
<button type="button" class="primary" @click="retry">Erneut versuchen</button>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.offline {
|
||||||
|
max-width: 28rem;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20vh 1rem 2rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -3,9 +3,47 @@ import { fileURLToPath, URL } from 'node:url'
|
|||||||
|
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [
|
||||||
|
vue(),
|
||||||
|
VitePWA({
|
||||||
|
// Updates are applied after the user confirms (see src/pwa.ts)
|
||||||
|
registerType: 'prompt',
|
||||||
|
injectRegister: false,
|
||||||
|
includeAssets: ['icons/icon.svg', 'icons/apple-touch-icon.png'],
|
||||||
|
manifest: {
|
||||||
|
name: 'LAN-Clipboard',
|
||||||
|
short_name: 'Clipboard',
|
||||||
|
description: 'Texte und Code-Snippets zwischen den eigenen Geräten teilen',
|
||||||
|
lang: 'de',
|
||||||
|
start_url: '/',
|
||||||
|
scope: '/',
|
||||||
|
display: 'standalone',
|
||||||
|
background_color: '#0f1115',
|
||||||
|
theme_color: '#0f1115',
|
||||||
|
icons: [
|
||||||
|
{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
|
||||||
|
{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
|
||||||
|
{
|
||||||
|
src: '/icons/icon-maskable-512.png',
|
||||||
|
sizes: '512x512',
|
||||||
|
type: 'image/png',
|
||||||
|
purpose: 'maskable',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
workbox: {
|
||||||
|
// Only the app shell is cached; clip data from /api is never stored on the device
|
||||||
|
globPatterns: ['**/*.{js,css,html,svg,png}'],
|
||||||
|
navigateFallback: '/index.html',
|
||||||
|
navigateFallbackDenylist: [/^\/api\//],
|
||||||
|
runtimeCaching: [],
|
||||||
|
cleanupOutdatedCaches: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
|
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
|
||||||
},
|
},
|
||||||
|
|||||||