5d0e23d6a5
ci / web (pull_request) Successful in 48s
ci / docs-site (pull_request) Successful in 53s
apple / swift (pull_request) Successful in 1m16s
apple / screenshots (pull_request) Has been skipped
android / android (pull_request) Has been cancelled
ci / rust (pull_request) Has been cancelled
ci / bench (pull_request) Has been cancelled
windows / build (x86_64-pc-windows-msvc) (pull_request) Has been cancelled
windows / build (aarch64-pc-windows-msvc) (pull_request) Has been cancelled
The NSPasteboard bridge completing Phase 1 (design/clipboard-and-file-transfer.md §5) — with the host backends on this branch, copy/paste now crosses the wire in both directions on macOS. Lazy in both directions: - PunktfunkConnection grows the clipboard plane: its own clipboardLock (close() joins it like the other pullers), hostCaps/hostSupportsClipboard from the Welcome, the typed ClipEvent vocabulary, and the six ABI wrappers (clipControl/clipOffer/clipFetch/clipServe/clipCancel/nextClipboard — borrowed event payloads copied out before the next poll). - ClipboardSync (PunktfunkKit, macOS-only): one drain thread bridging NSPasteboard.general ↔ the QUIC clipboard plane. Local copies announce format lists via a 500 ms changeCount poll (+ immediate on app activation); bytes leave only on a host FetchRequest, answered from the live pasteboard and seq-guarded against staleness. Host copies install one NSPasteboardItem whose data provider fires only when a Mac app actually pastes, then blocks its provider thread (never main) on a 10 s-bounded fetch. Concealed/Transient pasteboards (password managers) are never announced; our own writes are changeCount-suppressed (§3.4). Text/RTF/HTML/PNG; files ride Phase 2. - UI: per-host "Share clipboard with this host" toggle (StoredHost.clipboardSync, optional for saved-JSON forward-compat — wire-format tests extended), a mid-session Share/Stop Sharing Clipboard item in the Stream menu (⌃⌥⇧C, greyed without HOST_CAP_CLIPBOARD), SessionModel owning the lifecycle (start on streaming after the trust gate, drain joined off-main on teardown). swift build + swift test green (macOS). Requires the ABI v8 xcframework (scripts/build-xcframework.sh). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
84 lines
4.0 KiB
Swift
84 lines
4.0 KiB
Swift
// The app's "Stream" menu (macOS menu bar + iPad hardware-keyboard shortcuts). These live at
|
|
// the Scene level so they keep working when the HUD overlay is hidden. The shortcuts are the
|
|
// CROSS-CLIENT set every punktfunk client reserves — Ctrl+Alt+Shift+Q (release the captured
|
|
// mouse) / +D (disconnect) / +S (stats) — and the menu is their discoverable surface on macOS
|
|
// (the Linux client has its GTK Shortcuts window, Windows its start-of-stream banner). While
|
|
// input is CAPTURED these key equivalents never reach the menu (the stream view swallows
|
|
// keys); InputCapture's monitor detects the same combos there and performs the same actions —
|
|
// the menu covers the released state and discoverability. The stats item cycles the shared
|
|
// `statsVerbosity` tier (off → compact → normal → detailed → off); ContentView reads the same
|
|
// @AppStorage and reacts.
|
|
//
|
|
// tvOS has no menu bar / hardware-keyboard command surface (disconnect there is the Siri
|
|
// Remote's Menu button, handled by ContentView's `.onExitCommand`), so this whole file is
|
|
// non-tvOS only.
|
|
|
|
#if !os(tvOS)
|
|
import PunktfunkKit
|
|
import SwiftUI
|
|
|
|
/// The live session's menu-reachable actions, published by ContentView via
|
|
/// `.focusedSceneValue` so the Scene-level commands can drive it.
|
|
struct SessionFocus {
|
|
var isStreaming: Bool
|
|
/// The connected host advertises `HOST_CAP_CLIPBOARD` (gates the Share Clipboard item —
|
|
/// macOS-only UI, but the fact is platform-neutral).
|
|
var clipboardAvailable: Bool
|
|
/// Clipboard sync is live (host-acked) — drives the item's Stop/Share title.
|
|
var clipboardOn: Bool
|
|
var toggleClipboard: () -> Void
|
|
var disconnect: () -> Void
|
|
}
|
|
|
|
private struct SessionFocusKey: FocusedValueKey {
|
|
typealias Value = SessionFocus
|
|
}
|
|
|
|
extension FocusedValues {
|
|
var sessionFocus: SessionFocus? {
|
|
get { self[SessionFocusKey.self] }
|
|
set { self[SessionFocusKey.self] = newValue }
|
|
}
|
|
}
|
|
|
|
struct StreamCommands: Commands {
|
|
@FocusedValue(\.sessionFocus) private var session
|
|
// The raw string so @AppStorage observes the shared key; the absent-key default runs the
|
|
// legacy-hudEnabled migration (same pattern as ContentView/SettingsView).
|
|
@AppStorage(DefaultsKey.statsVerbosity) private var statsVerbosityRaw
|
|
= StatsVerbosity.current.rawValue
|
|
|
|
var body: some Commands {
|
|
CommandMenu("Stream") {
|
|
Button("Cycle Statistics") {
|
|
let current = StatsVerbosity(rawValue: statsVerbosityRaw) ?? .normal
|
|
statsVerbosityRaw = current.next().rawValue
|
|
}
|
|
.keyboardShortcut("s", modifiers: [.control, .option, .shift])
|
|
// Reaches the key window's stream view via NotificationCenter — capture is view
|
|
// state the Scene can't touch directly. (Captured, the combo is handled by
|
|
// InputCapture's monitor before menus see it; this item is the released-state
|
|
// path and the shortcut's menu-bar documentation.)
|
|
Button("Release Mouse") {
|
|
NotificationCenter.default.post(name: .punktfunkReleaseCapture, object: nil)
|
|
}
|
|
.keyboardShortcut("q", modifiers: [.control, .option, .shift])
|
|
.disabled(session?.isStreaming != true)
|
|
#if os(macOS)
|
|
// Mid-session clipboard flip (design/clipboard-and-file-transfer.md §5.3). Greyed
|
|
// when the host doesn't advertise the cap (older host / operator policy off).
|
|
Button(session?.clipboardOn == true ? "Stop Sharing Clipboard" : "Share Clipboard") {
|
|
session?.toggleClipboard()
|
|
}
|
|
.keyboardShortcut("c", modifiers: [.control, .option, .shift])
|
|
.disabled(session?.isStreaming != true || session?.clipboardAvailable != true)
|
|
#endif
|
|
Divider()
|
|
Button("Disconnect") { session?.disconnect() }
|
|
.keyboardShortcut("d", modifiers: [.control, .option, .shift])
|
|
.disabled(session?.isStreaming != true)
|
|
}
|
|
}
|
|
}
|
|
#endif
|