From d67c4dd94b5f69f419b1d3998bd3acc26d31b1bc Mon Sep 17 00:00:00 2001 From: Karl Date: Tue, 15 Jul 2025 08:02:51 +0100 Subject: [PATCH] share to and pwa --- app.py | 8 +++++--- static/service-worker.js | 16 ++++++++++------ static/site.webmanifest | 11 ++++++++++- templates/add_account.html | 16 ++++++++++++++++ templates/home.html | 9 +++++++-- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index f56114a..df823c6 100644 --- a/app.py +++ b/app.py @@ -156,7 +156,9 @@ def user_accounts(): @app.route("/accounts/add", methods=["GET", "POST"]) def add_account(): - base_url = app.config["BASE_URL"] # Access base_url from the config + base_url = app.config["BASE_URL"] + shared_text = request.args.get('shared_text') + if request.method == "POST": username = request.form["username"] password = request.form["password"] @@ -167,9 +169,9 @@ def add_account(): ): cache.clear() return redirect(url_for("user_accounts")) - return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED")) + return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"), shared_text=shared_text) - return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED")) + return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"), shared_text=shared_text) @app.route("/accounts/delete", methods=["POST"]) diff --git a/static/service-worker.js b/static/service-worker.js index ea6e563..a3cd347 100644 --- a/static/service-worker.js +++ b/static/service-worker.js @@ -6,10 +6,14 @@ self.addEventListener('activate', e => { // console.log('[Service Worker] Activated'); }); -self.addEventListener('fetch', e => { - // e.respondWith( - // caches.match(e.request).then(res => { - // return res || fetch(e.request); - // }) - // ); +self.addEventListener('fetch', (event) => { + if (event.request.method === 'POST' && event.request.url.endsWith('/accounts/add/')) { + event.respondWith( + (async () => { + const formData = await event.request.formData(); + const text = formData.get('text') || ''; + return Response.redirect(`/accounts/add?shared_text=${encodeURIComponent(text)}`, 303); + })() + ); + } }); \ No newline at end of file diff --git a/static/site.webmanifest b/static/site.webmanifest index 4f1e310..6d87d4a 100644 --- a/static/site.webmanifest +++ b/static/site.webmanifest @@ -24,5 +24,14 @@ ], "theme_color": "#ffffff", "background_color": "#ffffff", - "display": "standalone" + "display": "standalone", + "share_target": { + "action": "/accounts/add/", + "method": "GET", + "params": { + "title": "title", + "text": "text", + "url": "url" + } + } } \ No newline at end of file diff --git a/templates/add_account.html b/templates/add_account.html index a197ecc..598c842 100644 --- a/templates/add_account.html +++ b/templates/add_account.html @@ -7,6 +7,7 @@ Add Account - KTVManager +