share to and pwa
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 4m21s

This commit is contained in:
Karl 2025-07-15 08:02:51 +01:00
parent 629ef4e975
commit d67c4dd94b
5 changed files with 48 additions and 12 deletions

8
app.py
View File

@ -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"])

View File

@ -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);
})()
);
}
});

View File

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

View File

@ -7,6 +7,7 @@
<title>Add Account - KTVManager</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}" />
<link rel="manifest" href="{{ url_for('static', filename='site.webmanifest') }}" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.css" />
<style>
/* Hide the spinner by default */
@ -156,6 +157,21 @@
});
}
});
const sharedTextJson = '{{ shared_text|tojson|safe }}';
const sharedText = JSON.parse(sharedTextJson);
if (sharedText) {
const accountDetailsTextarea = document.getElementById('accountDetails');
if (accountDetailsTextarea) {
accountDetailsTextarea.value = sharedText;
const event = new Event('input', {
bubbles: true,
cancelable: true,
});
accountDetailsTextarea.dispatchEvent(event);
}
}
});
</script>
</body>

View File

@ -6,9 +6,14 @@
<title>KTVManager</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}" />
<link rel="manifest" href="{{ url_for('static', filename='site.webmanifest') }}" />
</head>
<body>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('{{ url_for("static", filename="service-worker.js") }}')
}
</script>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/">KTVManager</a>