feat(v0.4): multi-device discovery + share link (frontend)

- tabs.ts: on open, syncLiveSessions() fetches /live-sessions and adds a tab for
  each host session not already open → any device sees & mirrors everything
  running on the host. Empty storage + no live sessions → one fresh tab.
  activeSessionId() + openSession(id) helpers.
- share.ts: 🔗 toolbar button → QR + <origin>/?join=<id> for the active session.
- main.ts: ?join=<id> on load opens/focuses that shared session, then strips the
  param. Mount share button (toolbar: 🔍 ⚙ ▦ 🕘🔗 📱).
- style.css: #sharemodal reuses the QR card/backdrop.

Verified in-browser: fresh device auto-discovered the host session and replayed
its scrollback; two concurrent clients (browser + ws) both received live output
(clientCount=2); share modal shows the join URL/QR.
This commit is contained in:
Yaojia Wang
2026-06-19 10:30:40 +02:00
parent 0718b92267
commit 24b3cbd507
4 changed files with 153 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ import { mountSettings, loadSettings, type Settings } from './settings.js'
import { mountDashboard } from './dashboard.js'
import { mountHistory } from './history.js'
import { mountShortcuts } from './shortcuts.js'
import { mountShareSession } from './share.js'
const paneHost = document.getElementById('term')
const tabs = document.getElementById('tabs')
@@ -29,6 +30,14 @@ if (!toolbar) throw new Error('#toolbar element not found in DOM')
const app = new TabApp(paneHost, tabs)
// v0.4: a share link (?join=<id>) opens/focuses that shared session, then we
// strip the param so a refresh doesn't keep re-opening it.
const joinId = new URLSearchParams(location.search).get('join')
if (joinId) {
app.openSession(joinId)
history.replaceState(null, '', location.pathname)
}
// Apply saved theme/font (M3) to the restored tabs.
let settings: Settings = loadSettings()
app.applySettings(settings)
@@ -57,6 +66,7 @@ mountHistory(toolbar, {
resume: (cwd, id) => app.newTabForResume(cwd, id),
})
mountShortcuts(toolbar)
mountShareSession(toolbar, () => app.activeSessionId())
mountQrConnect(toolbar)
// PWA: register the service worker (installable + offline shell, M4).