From 87b0888d0c25369df3e0a9061e2c37eef2346fcc Mon Sep 17 00:00:00 2001 From: Til Schmitter Date: Thu, 18 Jun 2026 09:51:25 +0200 Subject: [PATCH] pwa support (wip) --- copyparty/__init__.py | 3 ++ copyparty/web/browser.css | 3 +- copyparty/web/browser.html | 1 + copyparty/web/browser.js | 4 ++- copyparty/web/copyparty.png | Bin 0 -> 1585 bytes copyparty/web/idp.html | 1 + copyparty/web/manifest.json | 33 ++++++++++++++++++++++ copyparty/web/md.html | 1 + copyparty/web/mde.html | 1 + copyparty/web/msg.html | 1 + copyparty/web/rups.html | 1 + copyparty/web/shares.html | 1 + copyparty/web/splash.html | 1 + copyparty/web/svcs.html | 1 + copyparty/web/sw.js | 54 ++++++++++++++++++++++++++++++++++++ scripts/sfx.ls | 3 ++ 16 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 copyparty/web/copyparty.png create mode 100644 copyparty/web/manifest.json create mode 100644 copyparty/web/sw.js diff --git a/copyparty/__init__.py b/copyparty/__init__.py index 6430e655..23ec8eae 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -73,6 +73,7 @@ web/browser.js web/browser2.html web/cf.html web/copyparty.gif +web/copyparty.png web/deps/busy.mp3 web/deps/easymde.css web/deps/easymde.js @@ -89,6 +90,7 @@ web/deps/sha512.ac.js web/deps/sha512.hw.js web/idp.html web/iiam.gif +web/manifest.json web/md.css web/md.html web/md.js @@ -110,6 +112,7 @@ web/splash.html web/splash.js web/svcs.html web/svcs.js +web/sw.js web/tl/chi.js web/tl/cze.js web/tl/deu.js diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 045dab03..c19df1a5 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -679,7 +679,8 @@ html .ayjump:focus-visible { #bbox-btns .x, #qs_btns a .x { line-height: .6em; - vertical-align: center; + vertical-align: middle; + vertical-align: center; } #moresearch span { font-size: .6em; diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 6eda8026..c99d7178 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -7,6 +7,7 @@ + {{ html_head }} diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 10b1cb27..a2807f3a 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -15,7 +15,8 @@ function loadScript(name, id) { this.readyState === "loaded" || this.readyState === "complete") ) { done = true; - jsldp(id, name); + if(id) + jsldp(id, name); // Handle memory leak in IE s.onload = s.onreadystatechange = null; @@ -32,6 +33,7 @@ function jsldp(a, b) { } loadScript('baguettebox', "J_BBX"); loadScript('up2k', "J_U2K"); +loadScript('sw'); // disables emojis diff --git a/copyparty/web/copyparty.png b/copyparty/web/copyparty.png new file mode 100644 index 0000000000000000000000000000000000000000..8a17b717093d9f494341e9a34fc33747b7011a19 GIT binary patch literal 1585 zcmbVMc}&xH6o2inw5$bM1Q7}d$Yq8I0)a9NRD?jCvI2rb1!{`SS#_W=L5}`F!f-N+ zh;odhPG*@313VDCembNeibMgK95!;;QBI|REzlM8znNv(%QtzSm+#9b@5uX{U+{@+Q9PW+=(0Ii1*|a_39Y!3s_JzG|0O>g|RDm z{P(rz9+K92GFQCfw^$ev<_JN72lRX`Sh-f8cpjsMP8Hk*3qcjUjo`~dX#K5P`}+_v zdpNMOmQ+hhaA++il&(+bh7DVTq-Jwr$Wwe`rRoTEw{t&~?E+?-Otn7el|prg0+2JM z@cM44%Vv2b?w*Dke6)>=O+5!i4{^OSy@Cj|uBQ!YN2+J#{5zUOaHuYuK!<)OxQUZO z^PUA&B=QvMc7-nS{2x1XoX?0q)!#*)HYOo}O*(mgAxBApk3wBWVYQ{IG;63>Z6->~$Z zOMBx+JPc&HCX(s6V|^KJ>2EGfj(6daF1JR^W6EP)2T7$Dfq+hh9j)n_I=*nsx zw9UPZ%r3{@q!tV?(njcBGaAe_XuG!Kh^t}M6jy|o77j4b(i$^jB#qO2(q)8RkqJKP z{W)4QJ1LV57^Y^#uT^)%2B`K%l>@rNES!!*^6K3t630a*b9pT}mRLLmcBrwHl2L5J z*`~4xvQfAgMiUID%}%WXm?6>Nim7n4WU#;?JEJ=7cdaKBT9;;wiWpNe(K>)YZc1XZ zAH+wQZMJbYkkCD55~b6t@P@PYPJPEk_ym1v;b1XP`8S9;nnIS!7iVjWy(RS6q%Z^F9*WDI0P&Pe)p2kI<8DJLIK#X_ zLebs=2|3F&>04Bgng3Uh4I}e#(WOjngS*rSk;dFayu#@Tw_yLmPh77td!Qg4_Qvwr zA;o*1dw8VS)AdwJgo$vo++t^xvX{WeK4?2d9 zUBZ>a*8ska7QYuL6(MO^}^KwrW=X$)8f@Mslh@K&oBFHYcsC>;=lSfw~@ ze8GbXw;QQ&1}Sf#W|xe|0n7D%eS{wNn(#(9Si_Nm&JW4>1&U|)hPLM7BIi^Oa4sMu`?={}9wfh7MYce}#!qo|tes@3gfAxI>LQpIS4Zl4E?L^Q14GFZf^O4oO(8StGLu|!E&hM> A(*OVf literal 0 HcmV?d00001 diff --git a/copyparty/web/idp.html b/copyparty/web/idp.html index 13360181..2ac37489 100644 --- a/copyparty/web/idp.html +++ b/copyparty/web/idp.html @@ -8,6 +8,7 @@ + {{ html_head }} diff --git a/copyparty/web/manifest.json b/copyparty/web/manifest.json new file mode 100644 index 00000000..b68258ce --- /dev/null +++ b/copyparty/web/manifest.json @@ -0,0 +1,33 @@ +{ + "short_name": "copyparty", + "name": "copyparty", + "description": "the all in one file server", + "icons": [ + { + "src": "/.cpr/copyparty.png", + "sizes": "512x512", + "type": "image/svg+xml" + } + ], + "start_url": "/?utm_medium=PWA&utm_source=launcher", + "display": "minimal-ui", + "orientation": "any", + "theme_color": "#fc5", + "background_color": "#222", + "share_target": { + "action": "/?utm_medium=PWA&utm_source=share-target&share-target", + "method": "POST", + "enctype": "multipart/form-data", + "params": { + "title": "name", + "text": "description", + "url": "link", + "files": [ + { + "name": "files", + "accept": ["*/*"] + } + ] + } + } + } \ No newline at end of file diff --git a/copyparty/web/md.html b/copyparty/web/md.html index e2d1a9e6..fa6e0bc5 100644 --- a/copyparty/web/md.html +++ b/copyparty/web/md.html @@ -7,6 +7,7 @@ + {%- if edit %} diff --git a/copyparty/web/mde.html b/copyparty/web/mde.html index 042d1357..47bba37c 100644 --- a/copyparty/web/mde.html +++ b/copyparty/web/mde.html @@ -7,6 +7,7 @@ + diff --git a/copyparty/web/msg.html b/copyparty/web/msg.html index 30f53d55..891d0a1d 100644 --- a/copyparty/web/msg.html +++ b/copyparty/web/msg.html @@ -7,6 +7,7 @@ + diff --git a/copyparty/web/sw.js b/copyparty/web/sw.js new file mode 100644 index 00000000..7103a254 --- /dev/null +++ b/copyparty/web/sw.js @@ -0,0 +1,54 @@ +// service worker. required for PWAs +// https://www.digitalapplied.com/blog/progressive-web-apps-2026-pwa-performance-guide +// Register service worker on page load +if ('serviceWorker' in navigator) { + self.addEventListener("fetch", (event) => { + // Regular requests not related to Web Share Target. + if (event.request.method !== "POST" || !event.request.enctype.has("share-target")) { + event.respondWith(fetch(event.request)); + return; + } + + // Requests related to Web Share Target. + event.respondWith( + (async () => { + const formData = await event.request.formData(); + const link = formData.get("link") || ""; + // Instead of the original URL `/save-bookmark/`, redirect + // the user to a URL returned by the `saveBookmark()` + // function, for example, `/`. + const responseUrl = await saveBookmark(link); + return Response.redirect(responseUrl, 303); + })(), + ); + }); + window.addEventListener('load', async () => { + try { + const registration = await navigator.serviceWorker.register( + '/service-worker.js', + { scope: '/' } + ); + console.log('SW registered:', registration.scope); + + // Check for waiting update + if (registration.waiting) { + notifyUserOfUpdate(registration); + } + + // Listen for future updates + registration.addEventListener('updatefound', () => { + const newWorker = registration.installing; + newWorker?.addEventListener('statechange', () => { + if ( + newWorker.state === 'installed' && + navigator.serviceWorker.controller + ) { + notifyUserOfUpdate(registration); + } + }); + }); + } catch (error) { + console.error('SW registration failed:', error); + } + }); +} \ No newline at end of file diff --git a/scripts/sfx.ls b/scripts/sfx.ls index 7578b96b..02355b36 100644 --- a/scripts/sfx.ls +++ b/scripts/sfx.ls @@ -75,6 +75,7 @@ copyparty/web/browser.js, copyparty/web/browser2.html, copyparty/web/cf.html, copyparty/web/copyparty.gif, +copyparty/web/copyparty.png, copyparty/web/deps, copyparty/web/deps/__init__.py, copyparty/web/deps/busy.mp3, @@ -93,6 +94,7 @@ copyparty/web/deps/sha512.ac.js, copyparty/web/deps/sha512.hw.js, copyparty/web/idp.html, copyparty/web/iiam.gif, +copyparty/web/manifest.json, copyparty/web/md.css, copyparty/web/md.html, copyparty/web/md.js, @@ -115,6 +117,7 @@ copyparty/web/splash.html, copyparty/web/splash.js, copyparty/web/svcs.html, copyparty/web/svcs.js, +copyparty/web/sw.js, copyparty/web/tl, copyparty/web/tl/chi.js, copyparty/web/tl/cze.js,