Scope mobile share installation to the dashboard route #225

Merged
rockachopa merged 1 commits from timmy/223-mobile-share-subpath into main 2026-08-07 20:27:07 +00:00
5 changed files with 20 additions and 11 deletions

View File

@ -3067,7 +3067,7 @@ textarea { resize: vertical; min-height: 120px; }
if (workSession.active()) workSession.reconcile();
});
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').catch(error =>
navigator.serviceWorker.register('service-worker.js').catch(error =>
console.warn('Stackchain install support unavailable', error)
);
}

View File

@ -2,18 +2,18 @@
"name": "Stackchain Dashboard",
"short_name": "Stackchain",
"description": "Capture, plan, and complete Gitea work from mobile.",
"id": "/",
"start_url": "/",
"scope": "/",
"id": "./",
"start_url": "./",
"scope": "./",
"display": "standalone",
"background_color": "#07111f",
"theme_color": "#0b1220",
"icons": [
{"src": "/static/icons/stackchain-192.png", "sizes": "192x192", "type": "image/png"},
{"src": "/static/icons/stackchain-512.png", "sizes": "512x512", "type": "image/png"}
{"src": "static/icons/stackchain-192.png", "sizes": "192x192", "type": "image/png"},
{"src": "static/icons/stackchain-512.png", "sizes": "512x512", "type": "image/png"}
],
"share_target": {
"action": "/",
"action": "./",
"method": "GET",
"enctype": "application/x-www-form-urlencoded",
"params": {"title": "title", "text": "text", "url": "url"}

View File

@ -1,5 +1,10 @@
const CACHE = 'stackchain-shell-v1';
const SHELL = ['/manifest.webmanifest', '/static/icons/stackchain-192.png', '/static/icons/stackchain-512.png'];
const BASE = new URL('./', self.location.href).pathname;
const SHELL = [
BASE + 'manifest.webmanifest',
BASE + 'static/icons/stackchain-192.png',
BASE + 'static/icons/stackchain-512.png',
];
self.addEventListener('install', event => {
event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(SHELL)).then(() => self.skipWaiting()));

View File

@ -545,7 +545,7 @@ async def test_dashboard_launches_share_capture_with_draft_conflict_choices():
assert 'id="shared-content-conflict"' in html
assert '.shared-content-actions button { min-height:44px;' in html
assert "history.replaceState({}, '', cleanUrl)" in html
assert "navigator.serviceWorker.register('/service-worker.js')" in html
assert "navigator.serviceWorker.register('service-worker.js')" in html
@pytest.mark.anyio

View File

@ -73,12 +73,16 @@ async def test_pwa_assets_expose_root_scoped_share_target_without_caching_api_da
assert manifest.status_code == 200
assert manifest.headers["content-type"].startswith("application/manifest+json")
assert manifest.json()["id"] == "./"
assert manifest.json()["start_url"] == "./"
assert manifest.json()["scope"] == "./"
assert manifest.json()["share_target"] == {
"action": "/", "method": "GET", "enctype": "application/x-www-form-urlencoded",
"action": "./", "method": "GET", "enctype": "application/x-www-form-urlencoded",
"params": {"title": "title", "text": "text", "url": "url"},
}
assert worker.status_code == 200
assert worker.headers["content-type"].startswith("application/javascript")
assert worker.headers["service-worker-allowed"] == "/"
assert "request.url.includes('/api/')" in worker.text
assert "request.method !== 'GET'" in worker.text
assert "request.method !== 'GET'" in worker.text
assert "new URL('./', self.location.href).pathname" in worker.text