Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Deck: the phone as a macro pad for the PC

Bee061f7e4da8cd
diff --git a/Cargo.lock b/Cargo.lock
index c892b12..b5c692f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2327,6 +2327,7 @@ dependencies = [
"rand",
"rusqlite",
"serde",
+ "serde_json",
"tempfile",
"thiserror 2.0.21",
"tokio",
diff --git a/README.md b/README.md
index ab13dd1..4721aa4 100644
--- a/README.md
+++ b/README.md
@@ -146,6 +146,16 @@ tests; there are no releases yet.
accent-colored dot on the PC screen following the phone's gyroscope or
finger. Off by default on the PC, with a one-time prompt the first time a
phone asks and a per-phone toggle in Settings.
+- **Deck (macro pad)**: turn the phone into a Stream-Deck-style button grid for
+ the PC, with multiple swipable pages, full-screen portrait and landscape
+ layouts, haptic feedback, and live tiles that show whether PC media is playing,
+ the speaker volume level, and whether the microphone is muted. Tiles are
+ configured on the PC (in Nectarlink's **Deck** page, with drag-and-drop
+ reordering, icons and colors): media controls, speaker volume and mute,
+ microphone mute, Lock PC, Show desktop, Switch window, Screenshot, custom
+ keyboard shortcuts, web links, text snippets, launching `.exe`/`.lnk` apps, and
+ PC shell commands (gated behind a separate per-phone **Run Deck commands**
+ permission that is off by default).
- **Voice recorder**: record with the phone's microphone (with a live level
meter, pause and resume, timestamped markers, and recording that keeps going
when the screen turns off) and send it straight to the PC. On the PC it lands
@@ -171,7 +181,7 @@ tests; there are no releases yet.
- **Capability matrix**: both apps compute which features work for a pair of
devices and what would enable the rest, so the interface never offers
something that can't work.
-- **Windows app**: home, messages, calls, photos and settings, two themes in light and dark (Bloom,
+- **Windows app**: home, messages, calls, photos, deck and settings, two themes in light and dark (Bloom,
which takes its colors from the desktop wallpaper, and Graphite), Mica, a
custom title bar with Snap Layouts, and a tray icon. In the background it
uses about 10 MB of memory (as shown in Task Manager).
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt b/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
index bb229cc..33a6600 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
@@ -790,6 +790,30 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
}
}
+ // ---- Deck (phone -> PC) ----
+
+ enum class DeckPressResult { Ok, Denied, Offline, NotFound, Failed }
+
+ /** Presses a Deck tile on a paired PC (`deck.press`). */
+ suspend fun deckPress(id: String, tile: String): DeckPressResult {
+ startJob?.join()
+ val node = node ?: return DeckPressResult.Offline
+ return try {
+ node.deckPress(id, tile)
+ DeckPressResult.Ok
+ } catch (e: NectarlinkException) {
+ when (e) {
+ is NectarlinkException.Denied -> DeckPressResult.Denied
+ is NectarlinkException.Offline -> DeckPressResult.Offline
+ is NectarlinkException.NotFound -> DeckPressResult.NotFound
+ else -> {
+ _messages.tryEmit(describe(e))
+ DeckPressResult.Failed
+ }
+ }
+ }
+ }
+
/** Reconnects to PCs that aren't connected and syncs connected ones. */
fun refresh() {
refreshNotificationAccess()
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/core/CoreState.kt b/android/app/src/main/kotlin/app/nectarlink/android/core/CoreState.kt
index 2717fb7..b420ef8 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/core/CoreState.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/core/CoreState.kt
@@ -54,6 +54,8 @@ data class Device(
val battery: app.nectarlink.core.Battery? = null,
val power: PowerLevel = PowerLevel.NOT_APPLICABLE,
val features: List<Feature> = emptyList(),
+ val deckLayout: app.nectarlink.core.DeckLayout? = null,
+ val deckState: app.nectarlink.core.DeckState? = null,
) {
val online: Boolean get() = link is Link.Online
@@ -103,8 +105,18 @@ data class CoreState(
fun nameOf(id: String): String? =
device(id)?.name ?: discovered.firstOrNull { it.id == id }?.name
- fun withDevices(paired: List<PairedDevice>): CoreState =
- copy(devices = paired.map { it.toDevice() }.sortedBy { it.pairedAt })
+ fun withDevices(paired: List<PairedDevice>): CoreState {
+ val prevById = devices.associateBy { it.id }
+ return copy(
+ devices = paired.map { p ->
+ val prev = prevById[p.id]
+ p.toDevice().copy(
+ deckLayout = prev?.deckLayout,
+ deckState = prev?.deckState,
+ )
+ }.sortedBy { it.pairedAt },
+ )
+ }
fun withWakeState(id: String, state: WakeState): CoreState =
update(id) { it.copy(wakeState = state) }
@@ -137,6 +149,8 @@ data class CoreState(
}
is Event.Battery -> update(event.id) { it.copy(battery = event.battery) }
is Event.Capabilities -> update(event.id) { it.copy(features = event.features) }
+ is Event.DeckLayout -> update(event.id) { it.copy(deckLayout = event.layout) }
+ is Event.DeckState -> update(event.id) { it.copy(deckState = event.state) }
is Event.Ring -> copy(ringingFrom = if (event.on) nameOf(event.id) ?: "" else null)
is Event.Discovered -> copy(discovered = discovered.filterNot { it.id == event.device.id } + event.device)
is Event.DiscoveryExpired -> copy(discovered = discovered.filterNot { it.id == event.id })
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/MainActivity.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/MainActivity.kt
index 95355b3..4d66e56 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/MainActivity.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/MainActivity.kt
@@ -49,6 +49,7 @@ import app.nectarlink.android.ui.home.HomeScreen
import app.nectarlink.android.ui.pairing.PairingActions
import android.view.KeyEvent
import app.nectarlink.android.core.LocalNetwork
+import app.nectarlink.android.ui.deck.DeckScreen
import app.nectarlink.android.ui.pairing.PairingScreen
import app.nectarlink.android.ui.recorder.RecorderScreen
import app.nectarlink.android.ui.remote.RemoteMode
@@ -61,6 +62,7 @@ class MainActivity : ComponentActivity() {
private var activeRemotePcId: String? = null
private var requestedRemotePc by mutableStateOf<String?>(null)
private var requestedRemoteMode by mutableStateOf(RemoteMode.Touchpad)
+ private var requestedDeckPc by mutableStateOf<String?>(null)
private var requestedRecordPc by mutableStateOf<String?>(null)
private val permissions =
@@ -85,6 +87,7 @@ class MainActivity : ComponentActivity() {
if (savedInstanceState == null) {
handlePairingLink(intent)
handleRemoteIntent(intent)
+ handleDeckIntent(intent)
handleRecordIntent(intent)
}
@@ -110,6 +113,8 @@ class MainActivity : ComponentActivity() {
requestedRemotePc = requestedRemotePc,
requestedRemoteMode = requestedRemoteMode,
onRemoteConsumed = { requestedRemotePc = null },
+ requestedDeckPc = requestedDeckPc,
+ onDeckConsumed = { requestedDeckPc = null },
requestedRecordPc = requestedRecordPc,
onRecordConsumed = { requestedRecordPc = null },
onActiveRemoteChanged = { activeRemotePcId = it },
@@ -131,6 +136,7 @@ class MainActivity : ComponentActivity() {
super.onNewIntent(intent)
handlePairingLink(intent)
handleRemoteIntent(intent)
+ handleDeckIntent(intent)
handleRecordIntent(intent)
}
@@ -177,6 +183,11 @@ class MainActivity : ComponentActivity() {
requestedRemotePc = pc
}
+ private fun handleDeckIntent(intent: Intent?) {
+ val pc = intent?.getStringExtra("deck_pc") ?: return
+ requestedDeckPc = pc
+ }
+
private fun handleRecordIntent(intent: Intent?) {
val pc = intent?.getStringExtra("record_pc") ?: return
requestedRecordPc = pc
@@ -207,6 +218,8 @@ private fun App(
requestedRemotePc: String?,
requestedRemoteMode: RemoteMode,
onRemoteConsumed: () -> Unit,
+ requestedDeckPc: String?,
+ onDeckConsumed: () -> Unit,
requestedRecordPc: String?,
onRecordConsumed: () -> Unit,
onActiveRemoteChanged: (String?) -> Unit,
@@ -215,6 +228,7 @@ private fun App(
var pairing by rememberSaveable { mutableStateOf(false) }
var remotePcId by rememberSaveable { mutableStateOf<String?>(null) }
var remoteInitialMode by rememberSaveable { mutableStateOf(RemoteMode.Touchpad) }
+ var deckPcId by rememberSaveable { mutableStateOf<String?>(null) }
var recordPcId by rememberSaveable { mutableStateOf<String?>(null) }
val snackbar = remember { SnackbarHostState() }
LaunchedEffect(Unit) { core.messages.collect { snackbar.showSnackbar(it) } }
@@ -224,23 +238,37 @@ private fun App(
val target = if (req == "first") state.devices.firstOrNull()?.id else state.device(req)?.id
if (target != null) {
recordPcId = null
+ deckPcId = null
remoteInitialMode = requestedRemoteMode
remotePcId = target
onRemoteConsumed()
}
}
+ LaunchedEffect(requestedDeckPc, state.devices) {
+ val req = requestedDeckPc ?: return@LaunchedEffect
+ val target = if (req == "first") state.devices.firstOrNull()?.id else state.device(req)?.id
+ if (target != null) {
+ remotePcId = null
+ recordPcId = null
+ deckPcId = target
+ onDeckConsumed()
+ }
+ }
+
LaunchedEffect(requestedRecordPc, state.devices) {
val req = requestedRecordPc ?: return@LaunchedEffect
val target = if (req == "first") state.devices.firstOrNull()?.id else state.device(req)?.id
if (target != null) {
remotePcId = null
+ deckPcId = null
recordPcId = target
onRecordConsumed()
}
}
val remoteDevice = remotePcId?.let { state.device(it) }
+ val deckDevice = deckPcId?.let { state.device(it) }
val recordDevice = recordPcId?.let { state.device(it) }
LaunchedEffect(remoteDevice?.id) {
onActiveRemoteChanged(remoteDevice?.id)
@@ -281,6 +309,19 @@ private fun App(
)
}
}
+ deckDevice != null -> {
+ BackHandler { deckPcId = null }
+ Scaffold(
+ snackbarHost = { SnackbarHost(snackbar) },
+ ) { padding ->
+ DeckScreen(
+ device = deckDevice,
+ core = core,
+ onBack = { deckPcId = null },
+ modifier = Modifier.fillMaxSize().padding(padding),
+ )
+ }
+ }
remoteDevice != null -> {
BackHandler { remotePcId = null }
val sensitivity by preferences.touchpadSensitivity.collectAsStateWithLifecycle()
@@ -330,6 +371,9 @@ private fun App(
remoteInitialMode = RemoteMode.Touchpad
remotePcId = id
},
+ onDeck = { id ->
+ deckPcId = id
+ },
onRecord = { id ->
recordPcId = id
},
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/deck/DeckScreen.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/deck/DeckScreen.kt
new file mode 100644
index 0000000..47c6983
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/deck/DeckScreen.kt
@@ -0,0 +1,911 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.ui.deck
+
+import android.app.Activity
+import android.content.res.Configuration
+import android.view.HapticFeedbackConstants
+import android.view.WindowManager
+import androidx.compose.animation.core.Spring
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.animation.core.spring
+import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.Canvas
+import androidx.compose.foundation.gestures.detectTapGestures
+import androidx.compose.foundation.horizontalScroll
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.lazy.grid.GridCells
+import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
+import androidx.compose.foundation.lazy.grid.items
+import androidx.compose.foundation.pager.HorizontalPager
+import androidx.compose.foundation.pager.rememberPagerState
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.material3.FilterChip
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedButton
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.saveable.rememberSaveable
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.CornerRadius
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.Path
+import androidx.compose.ui.graphics.StrokeCap
+import androidx.compose.ui.graphics.StrokeJoin
+import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.Stroke
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.graphics.luminance
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.platform.LocalConfiguration
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalView
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.role
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import androidx.core.view.WindowCompat
+import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.WindowInsetsControllerCompat
+import app.nectarlink.android.R
+import app.nectarlink.android.core.Core
+import app.nectarlink.android.core.Device
+import app.nectarlink.core.DeckLayout
+import app.nectarlink.core.DeckPage
+import app.nectarlink.core.DeckState
+import app.nectarlink.core.DeckTile
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
+
+@Composable
+fun DeckScreen(
+ device: Device,
+ core: Core,
+ onBack: () -> Unit,
+ modifier: Modifier = Modifier,
+) {
+ val view = LocalView.current
+ val context = LocalContext.current
+ val configuration = LocalConfiguration.current
+ val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
+ val isDark = MaterialTheme.colorScheme.background.luminance() < 0.5f
+ val scope = rememberCoroutineScope()
+
+ var fullScreen by rememberSaveable { mutableStateOf(false) }
+ var access by remember(device.id) { mutableStateOf(Core.RemoteAccess.Allowed) }
+ var commandsDenied by remember(device.id) { mutableStateOf(false) }
+
+ // Keep the phone's screen on while Deck is open, and restore system bars on exit.
+ DisposableEffect(view, device.id) {
+ val window = (context as? Activity)?.window
+ val prevKeepOn = view.keepScreenOn
+ view.keepScreenOn = true
+ window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ onDispose {
+ view.keepScreenOn = prevKeepOn
+ window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ if (window != null) {
+ WindowCompat.getInsetsController(window, view)
+ .show(WindowInsetsCompat.Type.systemBars())
+ }
+ }
+ }
+
+ LaunchedEffect(fullScreen, view) {
+ val window = (context as? Activity)?.window ?: return@LaunchedEffect
+ val controller = WindowCompat.getInsetsController(window, view)
+ if (fullScreen) {
+ controller.systemBarsBehavior =
+ WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
+ controller.hide(WindowInsetsCompat.Type.systemBars())
+ } else {
+ controller.show(WindowInsetsCompat.Type.systemBars())
+ }
+ }
+
+ // Check remote_input access on entry and poll while denied so the banner clears
+ // as soon as the user clicks Allow on the PC.
+ LaunchedEffect(device.id, device.online) {
+ if (!device.online) {
+ access = Core.RemoteAccess.Offline
+ return@LaunchedEffect
+ }
+ access = core.remoteCheck(device.id)
+ while (access == Core.RemoteAccess.Denied && device.online) {
+ delay(1_500)
+ access = core.remoteCheck(device.id)
+ }
+ }
+
+ val layout = device.deckLayout ?: remember { fallbackDefaultLayout() }
+ val liveState = device.deckState ?: DeckState(
+ playing = false,
+ volume = 50u,
+ muted = false,
+ micMuted = false,
+ )
+ val pages = layout.pages.ifEmpty { fallbackDefaultLayout().pages }
+ val pagerState = rememberPagerState(pageCount = { pages.size })
+
+ Column(
+ modifier = modifier
+ .fillMaxSize()
+ .padding(
+ horizontal = if (isLandscape) 16.dp else 16.dp,
+ vertical = if (fullScreen || isLandscape) 8.dp else 12.dp,
+ ),
+ verticalArrangement = Arrangement.spacedBy(if (isLandscape) 8.dp else 12.dp),
+ ) {
+ // Header row: Back, PC name + status dot, Full-screen toggle
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ TextButton(
+ onClick = onBack,
+ contentPadding = PaddingValues(horizontal = 12.dp, vertical = 6.dp),
+ ) {
+ Text("← " + stringResource(R.string.action_back), style = MaterialTheme.typography.labelLarge)
+ }
+ Spacer(Modifier.width(4.dp))
+ Column(modifier = Modifier.weight(1f)) {
+ Row(verticalAlignment = Alignment.CenterVertically) {
+ Text(
+ device.name,
+ style = if (isLandscape) MaterialTheme.typography.titleMedium else MaterialTheme.typography.titleLarge,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ Spacer(Modifier.width(8.dp))
+ Surface(
+ shape = CircleShape,
+ color = if (device.online) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline,
+ modifier = Modifier.size(8.dp),
+ ) {}
+ }
+ if (!fullScreen && !isLandscape) {
+ Text(
+ stringResource(R.string.deck_hint, device.name),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+ }
+ OutlinedButton(
+ onClick = { fullScreen = !fullScreen },
+ contentPadding = PaddingValues(horizontal = 12.dp, vertical = 6.dp),
+ ) {
+ Text(
+ stringResource(if (fullScreen) R.string.deck_exit_fullscreen else R.string.deck_fullscreen),
+ style = MaterialTheme.typography.labelMedium,
+ )
+ }
+ }
+
+ // Status / permission banners
+ if (!device.online) {
+ DeckBanner(
+ title = stringResource(R.string.remote_offline_text, device.name),
+ text = null,
+ )
+ } else if (access == Core.RemoteAccess.Denied) {
+ DeckBanner(
+ title = stringResource(R.string.remote_denied_title, device.name),
+ text = stringResource(R.string.remote_denied_text, device.name),
+ )
+ } else if (commandsDenied) {
+ DeckBanner(
+ title = stringResource(R.string.deck_commands_denied_title, device.name),
+ text = stringResource(R.string.deck_commands_denied_text, device.name),
+ onDismiss = { commandsDenied = false },
+ )
+ }
+
+ // Page tabs when multiple pages exist
+ if (pages.size > 1) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .horizontalScroll(rememberScrollState()),
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ pages.forEachIndexed { index, page ->
+ FilterChip(
+ selected = pagerState.currentPage == index,
+ onClick = {
+ scope.launch { pagerState.animateScrollToPage(index) }
+ },
+ label = {
+ Text(
+ page.name,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ },
+ )
+ }
+ }
+ }
+
+ // Swipable pages of tactile Deck tiles
+ HorizontalPager(
+ state = pagerState,
+ modifier = Modifier
+ .fillMaxWidth()
+ .weight(1f),
+ ) { pageIndex ->
+ val page = pages.getOrNull(pageIndex) ?: pages.first()
+ if (page.tiles.isEmpty()) {
+ Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+ Text(
+ stringResource(R.string.deck_empty_page, device.name),
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.padding(24.dp),
+ )
+ }
+ } else {
+ val columns = if (isLandscape) 4 else 3
+ LazyVerticalGrid(
+ columns = GridCells.Fixed(columns),
+ modifier = Modifier.fillMaxSize(),
+ contentPadding = PaddingValues(vertical = 4.dp),
+ horizontalArrangement = Arrangement.spacedBy(10.dp),
+ verticalArrangement = Arrangement.spacedBy(10.dp),
+ ) {
+ items(page.tiles, key = { it.id }) { tile ->
+ DeckTileButton(
+ tile = tile,
+ liveState = liveState,
+ isDark = isDark,
+ compact = isLandscape,
+ enabled = device.online,
+ onPress = {
+ view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
+ scope.launch {
+ when (core.deckPress(device.id, tile.id)) {
+ Core.DeckPressResult.Ok -> {
+ access = Core.RemoteAccess.Allowed
+ if (tile.kind == "run_command") commandsDenied = false
+ }
+ Core.DeckPressResult.Denied -> {
+ val chk = core.remoteCheck(device.id)
+ access = chk
+ if (chk == Core.RemoteAccess.Allowed && tile.kind == "run_command") {
+ commandsDenied = true
+ }
+ }
+ Core.DeckPressResult.Offline -> {
+ access = Core.RemoteAccess.Offline
+ }
+ else -> {}
+ }
+ }
+ },
+ )
+ }
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun DeckBanner(
+ title: String,
+ text: String?,
+ onDismiss: (() -> Unit)? = null,
+) {
+ Surface(
+ shape = MaterialTheme.shapes.large,
+ color = MaterialTheme.colorScheme.secondaryContainer,
+ contentColor = MaterialTheme.colorScheme.onSecondaryContainer,
+ ) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 16.dp, vertical = 12.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Column(modifier = Modifier.weight(1f)) {
+ Text(title, style = MaterialTheme.typography.titleSmall)
+ if (text != null) {
+ Spacer(Modifier.height(2.dp))
+ Text(text, style = MaterialTheme.typography.bodySmall)
+ }
+ }
+ if (onDismiss != null) {
+ TextButton(onClick = onDismiss) {
+ Text("×", style = MaterialTheme.typography.titleMedium)
+ }
+ }
+ }
+ }
+}
+
+private data class TilePalette(
+ val bg: Color,
+ val border: Color,
+ val accent: Color,
+ val fg: Color,
+)
+
+private fun tilePalette(colorName: String, isDark: Boolean): TilePalette = when (colorName) {
+ "amber" -> if (isDark) {
+ TilePalette(Color(0xFF33240C), Color(0xFF6B4C1B), Color(0xFFF59E0B), Color(0xFFFDE68A))
+ } else {
+ TilePalette(Color(0xFFFEF3C7), Color(0xFFF59E0B), Color(0xFFD97706), Color(0xFF78350F))
+ }
+ "coral" -> if (isDark) {
+ TilePalette(Color(0xFF361B12), Color(0xFF7A3720), Color(0xFFF97316), Color(0xFFFED7AA))
+ } else {
+ TilePalette(Color(0xFFFFEDD5), Color(0xFFF97316), Color(0xFFEA580C), Color(0xFF7C2D12))
+ }
+ "red", "rose" -> if (isDark) {
+ TilePalette(Color(0xFF371520), Color(0xFF7F2642), Color(0xFFF43F5E), Color(0xFFFECDD3))
+ } else {
+ TilePalette(Color(0xFFFFE4E6), Color(0xFFF43F5E), Color(0xFFE11D48), Color(0xFF881337))
+ }
+ "violet" -> if (isDark) {
+ TilePalette(Color(0xFF25173D), Color(0xFF56348E), Color(0xFF8B5CF6), Color(0xFFDDD6FE))
+ } else {
+ TilePalette(Color(0xFFEDE9FE), Color(0xFF8B5CF6), Color(0xFF7C3AED), Color(0xFF4C1D95))
+ }
+ "blue", "indigo" -> if (isDark) {
+ TilePalette(Color(0xFF14263D), Color(0xFF285185), Color(0xFF3B82F6), Color(0xFFBFDBFE))
+ } else {
+ TilePalette(Color(0xFFDBEAFE), Color(0xFF3B82F6), Color(0xFF2563EB), Color(0xFF1E3A8A))
+ }
+ "teal" -> if (isDark) {
+ TilePalette(Color(0xFF102E2C), Color(0xFF21645F), Color(0xFF14B8A6), Color(0xFF99F6E4))
+ } else {
+ TilePalette(Color(0xFFCCFBF1), Color(0xFF14B8A6), Color(0xFF0D9488), Color(0xFF134E4A))
+ }
+ "green", "emerald" -> if (isDark) {
+ TilePalette(Color(0xFF112E20), Color(0xFF226444), Color(0xFF10B981), Color(0xFFA7F3D0))
+ } else {
+ TilePalette(Color(0xFFD1FAE5), Color(0xFF10B981), Color(0xFF059669), Color(0xFF064E3B))
+ }
+ else -> if (isDark) {
+ TilePalette(Color(0xFF1E2530), Color(0xFF3D4B5F), Color(0xFF94A3B8), Color(0xFFE2E8F0))
+ } else {
+ TilePalette(Color(0xFFF1F5F9), Color(0xFF94A3B8), Color(0xFF475569), Color(0xFF1E293B))
+ }
+}
+
+@Composable
+private fun liveBadgeText(kind: String, state: DeckState): String? = when (kind) {
+ "media_play_pause" -> stringResource(if (state.playing) R.string.deck_playing else R.string.deck_paused)
+ "volume_up", "volume_down", "volume_mute" ->
+ if (state.muted) stringResource(R.string.deck_muted)
+ else stringResource(R.string.deck_volume_percent, state.volume.toInt())
+ "mic_mute" -> when (state.micMuted) {
+ true -> stringResource(R.string.deck_muted)
+ false -> stringResource(R.string.deck_live)
+ null -> null
+ }
+ else -> null
+}
+
+private fun isLiveHighlighted(kind: String, state: DeckState): Boolean = when (kind) {
+ "media_play_pause" -> state.playing
+ "volume_mute" -> state.muted
+ "mic_mute" -> state.micMuted == true
+ else -> false
+}
+
+private fun effectiveIcon(tile: DeckTile, state: DeckState): String = when {
+ tile.kind == "media_play_pause" && state.playing -> "pause"
+ tile.kind == "mic_mute" && state.micMuted == true -> "mic_off"
+ tile.kind == "volume_mute" && state.muted -> "volume_off"
+ else -> tile.icon
+}
+
+@Composable
+private fun DeckTileButton(
+ tile: DeckTile,
+ liveState: DeckState,
+ isDark: Boolean,
+ compact: Boolean,
+ enabled: Boolean,
+ onPress: () -> Unit,
+) {
+ val palette = tilePalette(tile.color, isDark)
+ val badge = liveBadgeText(tile.kind, liveState)
+ val highlighted = isLiveHighlighted(tile.kind, liveState)
+ val iconName = effectiveIcon(tile, liveState)
+
+ var pressed by remember { mutableStateOf(false) }
+ val scale by animateFloatAsState(
+ targetValue = if (pressed) 0.94f else 1f,
+ animationSpec = spring(stiffness = Spring.StiffnessHigh),
+ label = "tileScale",
+ )
+
+ val a11yDescription = if (badge != null) "${tile.label}, $badge" else tile.label
+
+ Surface(
+ shape = MaterialTheme.shapes.large,
+ color = palette.bg.copy(alpha = if (enabled) 1f else 0.55f),
+ contentColor = palette.fg,
+ border = BorderStroke(
+ width = if (highlighted) 2.dp else 1.dp,
+ color = if (highlighted) palette.accent else palette.border.copy(alpha = 0.65f),
+ ),
+ modifier = Modifier
+ .fillMaxWidth()
+ .height(if (compact) 98.dp else 118.dp)
+ .graphicsLayer {
+ scaleX = scale
+ scaleY = scale
+ }
+ .semantics {
+ role = Role.Button
+ contentDescription = a11yDescription
+ }
+ .pointerInput(enabled, tile.id) {
+ if (!enabled) return@pointerInput
+ detectTapGestures(
+ onPress = {
+ pressed = true
+ try {
+ if (tryAwaitRelease()) {
+ onPress()
+ }
+ } finally {
+ pressed = false
+ }
+ },
+ )
+ },
+ ) {
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(horizontal = 11.dp, vertical = 10.dp),
+ verticalArrangement = Arrangement.SpaceBetween,
+ ) {
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.Top,
+ ) {
+ Surface(
+ shape = MaterialTheme.shapes.medium,
+ color = palette.accent.copy(alpha = if (isDark) 0.24f else 0.16f),
+ modifier = Modifier.size(if (compact) 34.dp else 36.dp),
+ ) {
+ Box(contentAlignment = Alignment.Center) {
+ DeckIcon(
+ name = iconName,
+ tint = palette.fg,
+ modifier = Modifier.size(if (compact) 18.dp else 20.dp),
+ )
+ }
+ }
+
+ if (badge != null) {
+ Surface(
+ shape = CircleShape,
+ color = if (highlighted) palette.accent else palette.accent.copy(alpha = if (isDark) 0.24f else 0.16f),
+ contentColor = if (highlighted) Color.White else palette.fg,
+ ) {
+ Text(
+ text = badge,
+ style = MaterialTheme.typography.labelSmall,
+ fontWeight = FontWeight.SemiBold,
+ maxLines = 1,
+ softWrap = false,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp),
+ )
+ }
+ }
+ }
+
+ Text(
+ text = tile.label,
+ style = if (compact) MaterialTheme.typography.labelLarge else MaterialTheme.typography.titleSmall,
+ fontWeight = FontWeight.SemiBold,
+ color = palette.fg,
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ )
+ }
+ }
+}
+
+@Composable
+private fun DeckIcon(
+ name: String,
+ tint: Color,
+ modifier: Modifier = Modifier,
+) {
+ Canvas(modifier = modifier) {
+ drawDeckIcon(name, tint)
+ }
+}
+
+private fun DrawScope.drawDeckIcon(name: String, color: Color) {
+ val w = size.width
+ val h = size.height
+ val stroke = Stroke(
+ width = w * 0.095f,
+ cap = StrokeCap.Round,
+ join = StrokeJoin.Round,
+ )
+ fun sx(x: Float) = x / 24f * w
+ fun sy(y: Float) = y / 24f * h
+ fun pt(x: Float, y: Float) = Offset(sx(x), sy(y))
+
+ when (name) {
+ "play", "play_pause" -> {
+ val play = Path().apply {
+ moveTo(sx(6f), sy(4.5f))
+ lineTo(sx(19f), sy(12f))
+ lineTo(sx(6f), sy(19.5f))
+ close()
+ }
+ drawPath(play, color = color, style = stroke)
+ }
+ "pause" -> {
+ drawLine(color, pt(8f, 5f), pt(8f, 19f), strokeWidth = stroke.width * 1.15f, cap = StrokeCap.Round)
+ drawLine(color, pt(16f, 5f), pt(16f, 19f), strokeWidth = stroke.width * 1.15f, cap = StrokeCap.Round)
+ }
+ "skip_next" -> {
+ val tri = Path().apply {
+ moveTo(sx(5f), sy(5f))
+ lineTo(sx(15f), sy(12f))
+ lineTo(sx(5f), sy(19f))
+ close()
+ }
+ drawPath(tri, color = color, style = stroke)
+ drawLine(color, pt(19f, 5f), pt(19f, 19f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "skip_previous" -> {
+ val tri = Path().apply {
+ moveTo(sx(19f), sy(5f))
+ lineTo(sx(9f), sy(12f))
+ lineTo(sx(19f), sy(19f))
+ close()
+ }
+ drawPath(tri, color = color, style = stroke)
+ drawLine(color, pt(5f, 5f), pt(5f, 19f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "volume_up" -> {
+ drawSpeakerCone(color, stroke, ::sx, ::sy)
+ drawArc(
+ color = color,
+ startAngle = -45f,
+ sweepAngle = 90f,
+ useCenter = false,
+ topLeft = pt(12f, 8f),
+ size = Size(sx(5f), sy(8f)),
+ style = stroke,
+ )
+ drawArc(
+ color = color,
+ startAngle = -45f,
+ sweepAngle = 90f,
+ useCenter = false,
+ topLeft = pt(14f, 5f),
+ size = Size(sx(7f), sy(14f)),
+ style = stroke,
+ )
+ }
+ "volume_down" -> {
+ drawSpeakerCone(color, stroke, ::sx, ::sy)
+ drawArc(
+ color = color,
+ startAngle = -45f,
+ sweepAngle = 90f,
+ useCenter = false,
+ topLeft = pt(12.5f, 8f),
+ size = Size(sx(5f), sy(8f)),
+ style = stroke,
+ )
+ }
+ "volume_off" -> {
+ drawSpeakerCone(color, stroke, ::sx, ::sy)
+ drawLine(color, pt(16f, 9f), pt(21f, 15f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawLine(color, pt(21f, 9f), pt(16f, 15f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "mic", "mic_off" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(9f, 3f),
+ size = Size(sx(6f), sy(10f)),
+ cornerRadius = CornerRadius(sx(3f), sy(3f)),
+ style = stroke,
+ )
+ drawArc(
+ color = color,
+ startAngle = 0f,
+ sweepAngle = 180f,
+ useCenter = false,
+ topLeft = pt(5f, 6f),
+ size = Size(sx(14f), sy(11f)),
+ style = stroke,
+ )
+ drawLine(color, pt(12f, 17f), pt(12f, 21f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawLine(color, pt(8f, 21f), pt(16f, 21f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ if (name == "mic_off") {
+ drawLine(color, pt(4f, 4f), pt(20f, 20f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ }
+ "lock" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(5f, 11f),
+ size = Size(sx(14f), sy(10f)),
+ cornerRadius = CornerRadius(sx(2f), sy(2f)),
+ style = stroke,
+ )
+ drawArc(
+ color = color,
+ startAngle = 180f,
+ sweepAngle = 180f,
+ useCenter = false,
+ topLeft = pt(8f, 4f),
+ size = Size(sx(8f), sy(8f)),
+ style = stroke,
+ )
+ drawLine(color, pt(8f, 8f), pt(8f, 11f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawLine(color, pt(16f, 8f), pt(16f, 11f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "desktop" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(3f, 4f),
+ size = Size(sx(18f), sy(12f)),
+ cornerRadius = CornerRadius(sx(2f), sy(2f)),
+ style = stroke,
+ )
+ drawLine(color, pt(8f, 20f), pt(16f, 20f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawLine(color, pt(12f, 16f), pt(12f, 20f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "switch_window", "windows" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(3f, 7f),
+ size = Size(sx(13f), sy(12f)),
+ cornerRadius = CornerRadius(sx(2f), sy(2f)),
+ style = stroke,
+ )
+ val back = Path().apply {
+ moveTo(sx(8f), sy(7f))
+ lineTo(sx(8f), sy(5f))
+ lineTo(sx(21f), sy(5f))
+ lineTo(sx(21f), sy(15f))
+ lineTo(sx(16f), sy(15f))
+ }
+ drawPath(back, color = color, style = stroke)
+ }
+ "screenshot", "camera" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(3f, 7f),
+ size = Size(sx(18f), sy(12f)),
+ cornerRadius = CornerRadius(sx(2f), sy(2f)),
+ style = stroke,
+ )
+ drawCircle(color = color, radius = sx(3.2f), center = pt(12f, 13f), style = stroke)
+ drawLine(color, pt(9f, 4.5f), pt(15f, 4.5f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "keyboard" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(2f, 5f),
+ size = Size(sx(20f), sy(14f)),
+ cornerRadius = CornerRadius(sx(2f), sy(2f)),
+ style = stroke,
+ )
+ drawLine(color, pt(8f, 15f), pt(16f, 15f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ for (x in listOf(6f, 10f, 14f, 18f)) {
+ drawCircle(color = color, radius = sx(1f), center = pt(x, 10f))
+ }
+ }
+ "globe" -> {
+ drawCircle(color = color, radius = sx(9f), center = pt(12f, 12f), style = stroke)
+ drawLine(color, pt(3f, 12f), pt(21f, 12f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawOval(
+ color = color,
+ topLeft = pt(8f, 3f),
+ size = Size(sx(8f), sy(18f)),
+ style = stroke,
+ )
+ }
+ "text" -> {
+ drawLine(color, pt(4f, 6f), pt(20f, 6f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawLine(color, pt(12f, 6f), pt(12f, 19f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawLine(color, pt(9f, 19f), pt(15f, 19f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "app", "rocket" -> {
+ for (gx in listOf(4f, 13f)) {
+ for (gy in listOf(4f, 13f)) {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(gx, gy),
+ size = Size(sx(7f), sy(7f)),
+ cornerRadius = CornerRadius(sx(1.5f), sy(1.5f)),
+ style = stroke,
+ )
+ }
+ }
+ }
+ "terminal" -> {
+ val chevron = Path().apply {
+ moveTo(sx(4f), sy(7f))
+ lineTo(sx(10f), sy(12f))
+ lineTo(sx(4f), sy(17f))
+ }
+ drawPath(chevron, color = color, style = stroke)
+ drawLine(color, pt(12f, 17f), pt(20f, 17f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ "spark", "bolt" -> {
+ val bolt = Path().apply {
+ moveTo(sx(13f), sy(2f))
+ lineTo(sx(4f), sy(14f))
+ lineTo(sx(11f), sy(14f))
+ lineTo(sx(10f), sy(22f))
+ lineTo(sx(20f), sy(10f))
+ lineTo(sx(13f), sy(10f))
+ close()
+ }
+ drawPath(bolt, color = color, style = stroke)
+ }
+ "music" -> {
+ val note = Path().apply {
+ moveTo(sx(9f), sy(18f))
+ lineTo(sx(9f), sy(6f))
+ lineTo(sx(19f), sy(4f))
+ lineTo(sx(19f), sy(16f))
+ }
+ drawPath(note, color = color, style = stroke)
+ drawCircle(color = color, radius = sx(2.5f), center = pt(6.5f, 18f), style = stroke)
+ drawCircle(color = color, radius = sx(2.5f), center = pt(16.5f, 16f), style = stroke)
+ }
+ "video" -> {
+ drawRoundRect(
+ color = color,
+ topLeft = pt(3f, 6f),
+ size = Size(sx(12f), sy(12f)),
+ cornerRadius = CornerRadius(sx(2f), sy(2f)),
+ style = stroke,
+ )
+ val lens = Path().apply {
+ moveTo(sx(15f), sy(10f))
+ lineTo(sx(21f), sy(7f))
+ lineTo(sx(21f), sy(17f))
+ lineTo(sx(15f), sy(14f))
+ close()
+ }
+ drawPath(lens, color = color, style = stroke)
+ }
+ "folder" -> {
+ val folder = Path().apply {
+ moveTo(sx(3f), sy(6f))
+ lineTo(sx(9f), sy(6f))
+ lineTo(sx(11f), sy(8f))
+ lineTo(sx(21f), sy(8f))
+ lineTo(sx(21f), sy(19f))
+ lineTo(sx(3f), sy(19f))
+ close()
+ }
+ drawPath(folder, color = color, style = stroke)
+ }
+ "star" -> {
+ val star = Path().apply {
+ moveTo(sx(12f), sy(3f))
+ lineTo(sx(14.8f), sy(8.8f))
+ lineTo(sx(21f), sy(9.7f))
+ lineTo(sx(16.5f), sy(14.1f))
+ lineTo(sx(17.6f), sy(20.3f))
+ lineTo(sx(12f), sy(17.4f))
+ lineTo(sx(6.4f), sy(20.3f))
+ lineTo(sx(7.5f), sy(14.1f))
+ lineTo(sx(3f), sy(9.7f))
+ lineTo(sx(9.2f), sy(8.8f))
+ close()
+ }
+ drawPath(star, color = color, style = stroke)
+ }
+ "bell" -> {
+ val bell = Path().apply {
+ moveTo(sx(6f), sy(16f))
+ lineTo(sx(6f), sy(10f))
+ cubicTo(sx(6f), sy(6.5f), sx(18f), sy(6.5f), sx(18f), sy(10f))
+ lineTo(sx(18f), sy(16f))
+ lineTo(sx(4f), sy(16f))
+ lineTo(sx(20f), sy(16f))
+ }
+ drawPath(bell, color = color, style = stroke)
+ drawLine(color, pt(10f, 19.5f), pt(14f, 19.5f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ }
+ else -> {
+ // "power" or fallback
+ drawLine(color, pt(12f, 3f), pt(12f, 11f), strokeWidth = stroke.width, cap = StrokeCap.Round)
+ drawArc(
+ color = color,
+ startAngle = -55f,
+ sweepAngle = 290f,
+ useCenter = false,
+ topLeft = pt(5f, 5f),
+ size = Size(sx(14f), sy(14f)),
+ style = stroke,
+ )
+ }
+ }
+}
+
+private fun DrawScope.drawSpeakerCone(
+ color: Color,
+ stroke: Stroke,
+ sx: (Float) -> Float,
+ sy: (Float) -> Float,
+) {
+ val cone = Path().apply {
+ moveTo(sx(11f), sy(5f))
+ lineTo(sx(6f), sy(9f))
+ lineTo(sx(3f), sy(9f))
+ lineTo(sx(3f), sy(15f))
+ lineTo(sx(6f), sy(15f))
+ lineTo(sx(11f), sy(19f))
+ close()
+ }
+ drawPath(cone, color = color, style = stroke)
+}
+
+private fun fallbackDefaultLayout(): DeckLayout = DeckLayout(
+ pages = listOf(
+ DeckPage(
+ id = "main",
+ name = "Main",
+ tiles = listOf(
+ DeckTile("play_pause", "Play / Pause", "play", "amber", "media_play_pause"),
+ DeckTile("prev_track", "Previous", "skip_previous", "slate", "media_previous"),
+ DeckTile("next_track", "Next", "skip_next", "slate", "media_next"),
+ DeckTile("vol_down", "Volume Down", "volume_down", "teal", "volume_down"),
+ DeckTile("vol_up", "Volume Up", "volume_up", "teal", "volume_up"),
+ DeckTile("vol_mute", "Mute Audio", "volume_off", "teal", "volume_mute"),
+ DeckTile("mic_mute", "Mic Mute", "mic", "coral", "mic_mute"),
+ DeckTile("show_desktop", "Show Desktop", "desktop", "blue", "show_desktop"),
+ DeckTile("switch_window", "Switch Window", "switch_window", "blue", "switch_window"),
+ DeckTile("screenshot", "Screenshot", "screenshot", "violet", "screenshot"),
+ DeckTile("lock_pc", "Lock PC", "lock", "red", "lock_pc"),
+ ),
+ ),
+ ),
+)
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt
index 528e082..63405bb 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/home/HomeScreen.kt
@@ -84,6 +84,7 @@ fun HomeScreen(
onPower: (pcId: String, sleep: Boolean) -> Unit,
onWake: (pcId: String) -> Unit,
onRemote: (pcId: String) -> Unit,
+ onDeck: (pcId: String) -> Unit,
onRecord: (pcId: String) -> Unit,
updater: AppUpdater,
onSendFiles: (pcId: String, uris: List<Uri>) -> Unit,
@@ -201,7 +202,7 @@ fun HomeScreen(
}
}
items(state.devices, key = { it.id }) { device ->
- PcCard(device, onRing, onSendFiles, onSendFolder, onPower, onWake, onRemote, onRecord)
+ PcCard(device, onRing, onSendFiles, onSendFolder, onPower, onWake, onRemote, onDeck, onRecord)
}
if (state.transfers.isNotEmpty()) {
item { TransfersCard(state, onCancelTransfer) }
@@ -247,6 +248,7 @@ private fun PcCard(
onPower: (String, Boolean) -> Unit,
onWake: (String) -> Unit,
onRemote: (String) -> Unit,
+ onDeck: (String) -> Unit,
onRecord: (String) -> Unit,
) {
val pickFiles = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris ->
@@ -340,6 +342,12 @@ private fun PcCard(
) {
Text(stringResource(R.string.action_remote_pc))
}
+ FilledTonalButton(
+ colors = tonal,
+ onClick = { onDeck(device.id) },
+ ) {
+ Text(stringResource(R.string.action_deck_pc))
+ }
FilledTonalButton(
colors = tonal,
onClick = { onRecord(device.id) },
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index a9b5c64..a663927 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -299,4 +299,20 @@
<item quantity="one">%1$d marker</item>
<item quantity="other">%1$d markers</item>
</plurals>
+
+ <!-- Deck (macro pad -> PC) -->
+ <string name="action_deck_pc">Deck</string>
+ <string name="deck_title">Deck</string>
+ <string name="deck_fullscreen">Full screen</string>
+ <string name="deck_exit_fullscreen">Exit full screen</string>
+ <string name="deck_playing">Playing</string>
+ <string name="deck_paused">Paused</string>
+ <string name="deck_muted">Muted</string>
+ <string name="deck_live">Live</string>
+ <string name="deck_volume_percent">%1$d%%</string>
+ <string name="deck_waiting">Loading %1$s\'s Deck…</string>
+ <string name="deck_empty_page">No tiles on this page yet. Add tiles in Nectarlink on %1$s.</string>
+ <string name="deck_commands_denied_title">Allow commands on %1$s</string>
+ <string name="deck_commands_denied_text">To run shell commands from this phone, turn on “Run Deck commands” for this phone in Nectarlink › Settings › Devices on %1$s.</string>
+ <string name="deck_hint">Configure pages and tiles in Nectarlink › Deck on %1$s.</string>
</resources>
diff --git a/core/nectarlink-cli/src/main.rs b/core/nectarlink-cli/src/main.rs
index 5621664..dac12c3 100644
--- a/core/nectarlink-cli/src/main.rs
+++ b/core/nectarlink-cli/src/main.rs
@@ -242,6 +242,13 @@ enum Command {
#[command(subcommand)]
action: RemoteArg,
},
+ /// Show a paired PC's deck pages and tiles (with live states), or press a
+ /// tile with `deck <device> press <tile>`.
+ Deck {
+ device: String,
+ #[command(subcommand)]
+ action: Option<DeckArg>,
+ },
/// Act as a phone sharing its screen (use with --as-phone): when a PC
/// asks, streams an H.264 file (Annex B, with access unit delimiters) in
/// a loop at `fps`. Stays online.
@@ -578,6 +585,12 @@ enum TogglesArg {
Set { id: String, value: String },
}
+#[derive(Debug, Subcommand)]
+enum DeckArg {
+ /// Press a tile on the PC's deck by its ID.
+ Press { tile: String },
+}
+
/// Where `mirror` saves the video, and what arrived.
static RECORDING: std::sync::OnceLock<std::sync::Arc<Recording>> = std::sync::OnceLock::new();
@@ -1730,6 +1743,10 @@ impl Platform for TerminalPlatform {
}
Ok(())
}
+ fn deck_press(&self, _peer: &DeviceId, tile: &str) -> Result<(), String> {
+ println!("A paired device pressed deck tile {tile}");
+ Ok(())
+ }
}
fn main() -> Result<()> {
@@ -1781,6 +1798,7 @@ async fn start_node(cli: &Cli) -> Result<Node> {
config.capabilities.push(nectarlink_core::RECORDER.into());
config.capabilities.push(nectarlink_core::TOGGLES_SHOW.into());
config.capabilities.push(nectarlink_core::PC_WAKE.into());
+ config.capabilities.push(nectarlink_core::DECK_ACTIONS.into());
}
let extra_caps = config.capabilities.clone();
let node = Node::start(config, Arc::new(TerminalPlatform)).await.context("failed to start")?;
@@ -2190,6 +2208,56 @@ async fn run(cli: &Cli, node: &Node) -> Result<()> {
}
println!("Sent.");
}
+ Command::Deck { device, action: None } => {
+ let mut events = node.events();
+ let id = resolve(node, device)?;
+ wait_until_online(node, id).await?;
+ let layout = match node.deck_layout(id) {
+ Some(l) => l,
+ None => {
+ let wait = async {
+ loop {
+ if let Ok(NodeEvent::DeckLayout { device: d, layout }) = events.recv().await
+ && d == id
+ {
+ return layout;
+ }
+ }
+ };
+ tokio::time::timeout(Duration::from_secs(5), wait)
+ .await
+ .context("the PC didn't report its deck layout")?
+ }
+ };
+ let state = match node.deck_state(id) {
+ Some(s) => s,
+ None => {
+ let wait = async {
+ loop {
+ if let Ok(NodeEvent::DeckState { device: d, state }) = events.recv().await
+ && d == id
+ {
+ return state;
+ }
+ }
+ };
+ tokio::time::timeout(Duration::from_millis(500), wait)
+ .await
+ .ok()
+ .or_else(|| node.deck_state(id))
+ .unwrap_or_default()
+ }
+ };
+ print_deck(&layout, &state);
+ }
+ Command::Deck { device, action: Some(DeckArg::Press { tile }) } => {
+ let id = resolve(node, device)?;
+ wait_until_online(node, id).await?;
+ node.deck_press(id, tile.clone())
+ .await
+ .with_context(|| format!("the PC refused deck tile {tile:?}"))?;
+ println!("Pressed {tile}.");
+ }
Command::Apps { device, at } => {
let id = resolve(node, device)?;
if !at.is_empty() {
@@ -3381,6 +3449,13 @@ fn print_event(node: &Node, event: &NodeEvent) {
NodeEvent::PhoneToggles { device, toggles } => {
println!("{}: toggles {}", name(device), summarize_toggles(toggles));
}
+ NodeEvent::DeckLayout { device, layout } => {
+ let tiles: usize = layout.pages.iter().map(|p| p.tiles.len()).sum();
+ println!("{}: deck layout ({} page(s), {tiles} tile(s))", name(device), layout.pages.len());
+ }
+ NodeEvent::DeckState { device, state } => {
+ println!("{}: deck state {}", name(device), summarize_deck_state(state));
+ }
NodeEvent::WakeInfoChanged { device, can_wake } => {
let detail = node
.wake_info(*device)
@@ -3504,6 +3579,34 @@ fn summarize_toggles(t: &nectarlink_core::PhoneToggles) -> String {
)
}
+fn summarize_deck_state(state: &nectarlink_core::DeckState) -> String {
+ let vol = if state.muted { "muted".to_owned() } else { format!("{}%", state.volume) };
+ let mic = match state.mic_muted {
+ Some(true) => "muted",
+ Some(false) => "live",
+ None => "—",
+ };
+ let media = if state.playing { "playing" } else { "paused" };
+ format!("vol={vol} mic={mic} media={media}")
+}
+
+fn print_deck(layout: &nectarlink_core::DeckLayout, state: &nectarlink_core::DeckState) {
+ println!("State: {}", summarize_deck_state(state));
+ for (idx, page) in layout.pages.iter().enumerate() {
+ if idx > 0 {
+ println!();
+ }
+ println!("Page {}: {} [{}]", idx + 1, page.name, page.id);
+ for tile in &page.tiles {
+ let status = state.tile_status(&tile.kind).map(|s| format!(" ({s})")).unwrap_or_default();
+ println!(
+ " {:<18} {:<22} [{}, {}, {}]{status}",
+ tile.id, tile.label, tile.kind, tile.icon, tile.color
+ );
+ }
+ }
+}
+
fn parse_phone_toggle_value(id: &str, raw: &str) -> Result<nectarlink_core::PhoneToggleValue> {
use nectarlink_core::PhoneToggleValue as V;
let s = raw.trim().to_ascii_lowercase();
diff --git a/core/nectarlink-core/Cargo.toml b/core/nectarlink-core/Cargo.toml
index 225ce95..f7f58bc 100644
--- a/core/nectarlink-core/Cargo.toml
+++ b/core/nectarlink-core/Cargo.toml
@@ -16,6 +16,7 @@ n0-future.workspace = true
rand.workspace = true
rusqlite.workspace = true
serde.workspace = true
+serde_json.workspace = true
thiserror.workspace = true
bytes.workspace = true
tokio.workspace = true
diff --git a/core/nectarlink-core/src/config.rs b/core/nectarlink-core/src/config.rs
index ec6da1e..f8c379c 100644
--- a/core/nectarlink-core/src/config.rs
+++ b/core/nectarlink-core/src/config.rs
@@ -285,6 +285,14 @@ pub trait Platform: Send + Sync + 'static {
fn set_phone_toggle(&self, _id: &str, _value: &crate::PhoneToggleValue) -> Result<(), String> {
Err("this device has no phone toggles".into())
}
+
+ /// Run a Deck tile's action on this PC (`deck.press`, `docs/protocol/deck.md`).
+ /// `tile` has been validated against the current Deck layout and the
+ /// required per-device toggles (`remote_input`, plus `commands` for
+ /// `run_command` tiles). `Err` holds a reason for logs.
+ fn deck_press(&self, _from: &nectarlink_protocol::DeviceId, _tile: &str) -> Result<(), String> {
+ Err("this device has no deck actions".into())
+ }
}
/// A platform that does nothing; useful for tests and headless tools.
diff --git a/core/nectarlink-core/src/deck.rs b/core/nectarlink-core/src/deck.rs
new file mode 100644
index 0000000..e471e14
--- /dev/null
+++ b/core/nectarlink-core/src/deck.rs
@@ -0,0 +1,755 @@
+// SPDX-License-Identifier: MPL-2.0
+//! Phone as a macro pad for a PC (`docs/protocol/deck.md`).
+//!
+//! A PC that offers `deck.actions` shares its Deck layout (`deck.layout`) and
+//! live tile state (`deck.state`) when a session starts and after every edit
+//! or state change. A phone sends `deck.press { tile }` by tile ID only; the
+//! PC checks the `remote_input` toggle (and the `commands` toggle for
+//! `run_command` tiles) before running the tile's action.
+
+use std::{
+ collections::{BTreeSet, HashMap},
+ path::Path,
+ sync::{Arc, Mutex},
+};
+
+pub use nectarlink_protocol::messages::{
+ DeckLayout, DeckPage, DeckPress, DeckState, DeckTile, KeyMod,
+ deck::{
+ ACTIONS as DECK_ACTIONS, MAX_ID_BYTES as MAX_DECK_ID_BYTES, MAX_LABEL_BYTES as MAX_DECK_LABEL_BYTES,
+ MAX_PAGES as MAX_DECK_PAGES, MAX_TILES_PER_PAGE as MAX_DECK_TILES_PER_PAGE,
+ },
+ deck_colors, deck_icons, deck_kinds, is_valid_deck_id, remote_keys,
+};
+use nectarlink_protocol::{
+ DeviceId, Envelope, ErrorCode,
+ messages::{remote, types},
+};
+use serde::{Deserialize, Serialize};
+
+use crate::{
+ Error, Result,
+ events::NodeEvent,
+ node::Shared,
+ session::{REQUEST_TIMEOUT, Session},
+};
+
+/// Per-device toggle required for all `deck.press` actions (off by default).
+pub const INPUT_TOGGLE: &str = "remote_input";
+
+/// Additional per-device toggle required for `run_command` tiles (off by default).
+pub const COMMANDS_TOGGLE: &str = "commands";
+
+const MAX_URL_BYTES: usize = 2048;
+const MAX_PATH_BYTES: usize = 1024;
+const MAX_COMMAND_BYTES: usize = 1024;
+
+/// A PC-owned action bound to a Deck tile. Parameters stay on the PC and are
+/// never sent over the wire.
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(tag = "kind", rename_all = "snake_case")]
+pub enum DeckAction {
+ MediaPlayPause,
+ MediaNext,
+ MediaPrevious,
+ VolumeUp,
+ VolumeDown,
+ VolumeMute,
+ MicMute,
+ LockPc,
+ ShowDesktop,
+ SwitchWindow,
+ Screenshot,
+ Shortcut {
+ key: String,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ mods: Vec<KeyMod>,
+ },
+ OpenUrl {
+ url: String,
+ },
+ TypeText {
+ text: String,
+ },
+ LaunchApp {
+ path: String,
+ },
+ RunCommand {
+ command: String,
+ },
+}
+
+/// Never prints paths, URLs, text snippets, or commands (protocol v0 §11).
+impl std::fmt::Debug for DeckAction {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckAction").field("kind", &self.kind()).finish_non_exhaustive()
+ }
+}
+
+impl DeckAction {
+ /// The wire action kind (`docs/protocol/deck.md` §2.4).
+ pub fn kind(&self) -> &'static str {
+ match self {
+ Self::MediaPlayPause => deck_kinds::MEDIA_PLAY_PAUSE,
+ Self::MediaNext => deck_kinds::MEDIA_NEXT,
+ Self::MediaPrevious => deck_kinds::MEDIA_PREVIOUS,
+ Self::VolumeUp => deck_kinds::VOLUME_UP,
+ Self::VolumeDown => deck_kinds::VOLUME_DOWN,
+ Self::VolumeMute => deck_kinds::VOLUME_MUTE,
+ Self::MicMute => deck_kinds::MIC_MUTE,
+ Self::LockPc => deck_kinds::LOCK_PC,
+ Self::ShowDesktop => deck_kinds::SHOW_DESKTOP,
+ Self::SwitchWindow => deck_kinds::SWITCH_WINDOW,
+ Self::Screenshot => deck_kinds::SCREENSHOT,
+ Self::Shortcut { .. } => deck_kinds::SHORTCUT,
+ Self::OpenUrl { .. } => deck_kinds::OPEN_URL,
+ Self::TypeText { .. } => deck_kinds::TYPE_TEXT,
+ Self::LaunchApp { .. } => deck_kinds::LAUNCH_APP,
+ Self::RunCommand { .. } => deck_kinds::RUN_COMMAND,
+ }
+ }
+
+ /// Whether this action requires the per-device `commands` toggle.
+ pub fn requires_commands_toggle(&self) -> bool {
+ matches!(self, Self::RunCommand { .. })
+ }
+
+ /// Validates action parameters.
+ pub fn is_valid(&self) -> bool {
+ match self {
+ Self::MediaPlayPause
+ | Self::MediaNext
+ | Self::MediaPrevious
+ | Self::VolumeUp
+ | Self::VolumeDown
+ | Self::VolumeMute
+ | Self::MicMute
+ | Self::LockPc
+ | Self::ShowDesktop
+ | Self::SwitchWindow
+ | Self::Screenshot => true,
+ Self::Shortcut { key, mods } => is_valid_shortcut(key, mods),
+ Self::OpenUrl { url } => is_valid_http_url(url),
+ Self::TypeText { text } => is_valid_snippet(text),
+ Self::LaunchApp { path } => is_valid_app_path(path),
+ Self::RunCommand { command } => is_valid_command(command),
+ }
+ }
+
+ /// Short human-readable summary for the PC's Deck editor.
+ pub fn summary(&self) -> String {
+ match self {
+ Self::MediaPlayPause => "Play or pause media".into(),
+ Self::MediaNext => "Next track".into(),
+ Self::MediaPrevious => "Previous track".into(),
+ Self::VolumeUp => "Volume up".into(),
+ Self::VolumeDown => "Volume down".into(),
+ Self::VolumeMute => "Mute or unmute speakers".into(),
+ Self::MicMute => "Mute or unmute microphone".into(),
+ Self::LockPc => "Lock this PC".into(),
+ Self::ShowDesktop => "Show desktop (Win+D)".into(),
+ Self::SwitchWindow => "Switch window (Alt+Tab)".into(),
+ Self::Screenshot => "Take screenshot (Win+Shift+S)".into(),
+ Self::Shortcut { key, mods } => format_shortcut(key, mods),
+ Self::OpenUrl { url } => url.clone(),
+ Self::TypeText { text } => {
+ let single: String =
+ text.chars().map(|c| if c == '\n' || c == '\t' { ' ' } else { c }).collect();
+ let mut chars = single.chars();
+ let head: String = chars.by_ref().take(32).collect();
+ if chars.next().is_some() { format!("{head}…") } else { head }
+ }
+ Self::LaunchApp { path } => Path::new(path)
+ .file_name()
+ .map(|n| n.to_string_lossy().into_owned())
+ .filter(|s| !s.is_empty())
+ .unwrap_or_else(|| path.clone()),
+ Self::RunCommand { command } => {
+ let mut chars = command.trim().chars();
+ let head: String = chars.by_ref().take(32).collect();
+ if chars.next().is_some() { format!("{head}…") } else { head }
+ }
+ }
+ }
+}
+
+/// Validates a shortcut key and modifier list.
+pub fn is_valid_shortcut(key: &str, mods: &[KeyMod]) -> bool {
+ if mods.len() > 4 {
+ return false;
+ }
+ for (i, m) in mods.iter().enumerate() {
+ if mods[..i].contains(m) {
+ return false;
+ }
+ }
+ if remote_keys::SHORTCUTS.contains(&key) {
+ return mods.is_empty();
+ }
+ if remote_keys::NAMED.contains(&key) {
+ return true;
+ }
+ key.len() == 1 && key.as_bytes()[0].is_ascii_lowercase()
+ || (key.len() == 1 && key.as_bytes()[0].is_ascii_digit())
+}
+
+/// Formats a shortcut for display (e.g. `"Ctrl + Shift + M"`).
+pub fn format_shortcut(key: &str, mods: &[KeyMod]) -> String {
+ let mut parts: Vec<String> = mods
+ .iter()
+ .map(|m| {
+ match m {
+ KeyMod::Ctrl => "Ctrl",
+ KeyMod::Alt => "Alt",
+ KeyMod::Shift => "Shift",
+ KeyMod::Win => "Win",
+ }
+ .into()
+ })
+ .collect();
+ let key_label = if key.len() == 1 { key.to_ascii_uppercase() } else { key.replace('_', " ") };
+ parts.push(key_label);
+ parts.join(" + ")
+}
+
+/// Validates that `url` is a well-formed `http` or `https` URL.
+pub fn is_valid_http_url(url: &str) -> bool {
+ let trimmed = url.trim();
+ trimmed.len() <= MAX_URL_BYTES && crate::actions::valid_link(trimmed)
+}
+
+/// Validates a text snippet for `TypeText`.
+pub fn is_valid_snippet(text: &str) -> bool {
+ !text.is_empty()
+ && text.len() <= remote::MAX_TEXT_BYTES
+ && !text.chars().any(|c| c.is_control() && c != '\n' && c != '\t')
+}
+
+/// Validates that `path` is a non-empty `.exe` or `.lnk` file path on the PC.
+pub fn is_valid_app_path(path: &str) -> bool {
+ let trimmed = path.trim();
+ if trimmed.is_empty() || trimmed.len() > MAX_PATH_BYTES || trimmed.chars().any(char::is_control) {
+ return false;
+ }
+ let lower = trimmed.to_ascii_lowercase();
+ (lower.ends_with(".exe") || lower.ends_with(".lnk")) && trimmed.len() > 4
+}
+
+/// Validates a command string for `RunCommand`.
+pub fn is_valid_command(command: &str) -> bool {
+ let trimmed = command.trim();
+ !trimmed.is_empty() && trimmed.len() <= MAX_COMMAND_BYTES && !trimmed.chars().any(char::is_control)
+}
+
+/// One tile in the PC's stored [`DeckConfig`].
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckTileConfig {
+ pub id: String,
+ pub label: String,
+ pub icon: String,
+ pub color: String,
+ pub action: DeckAction,
+}
+
+impl std::fmt::Debug for DeckTileConfig {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckTileConfig")
+ .field("id", &self.id)
+ .field("icon", &self.icon)
+ .field("color", &self.color)
+ .field("action", &self.action)
+ .finish_non_exhaustive()
+ }
+}
+
+impl DeckTileConfig {
+ pub fn is_valid(&self) -> bool {
+ self.action.is_valid() && self.to_wire().is_valid()
+ }
+
+ pub fn sanitized(self) -> Option<Self> {
+ if !self.action.is_valid() {
+ return None;
+ }
+ let wire = self.to_wire().sanitized()?;
+ Some(DeckTileConfig {
+ id: wire.id,
+ label: wire.label,
+ icon: wire.icon,
+ color: wire.color,
+ action: self.action,
+ })
+ }
+
+ /// Converts to the wire [`DeckTile`], stripping any local path, URL,
+ /// snippet, or command.
+ pub fn to_wire(&self) -> DeckTile {
+ DeckTile {
+ id: self.id.clone(),
+ label: self.label.clone(),
+ icon: self.icon.clone(),
+ color: self.color.clone(),
+ kind: self.action.kind().into(),
+ }
+ }
+}
+
+/// One page of tiles in the PC's stored [`DeckConfig`].
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckPageConfig {
+ pub id: String,
+ pub name: String,
+ #[serde(default)]
+ pub tiles: Vec<DeckTileConfig>,
+}
+
+impl std::fmt::Debug for DeckPageConfig {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckPageConfig")
+ .field("id", &self.id)
+ .field("tiles", &self.tiles.len())
+ .finish_non_exhaustive()
+ }
+}
+
+impl DeckPageConfig {
+ pub fn to_wire(&self) -> DeckPage {
+ DeckPage {
+ id: self.id.clone(),
+ name: self.name.clone(),
+ tiles: self.tiles.iter().map(DeckTileConfig::to_wire).collect(),
+ }
+ }
+}
+
+/// The PC-owned Deck configuration (saved as `deck.json` in the PC's data directory).
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckConfig {
+ pub pages: Vec<DeckPageConfig>,
+}
+
+impl DeckConfig {
+ pub fn is_valid(&self) -> bool {
+ self.pages.iter().flat_map(|p| p.tiles.iter()).all(DeckTileConfig::is_valid)
+ && self.to_wire_layout().is_valid()
+ }
+
+ pub fn sanitized(self) -> Option<Self> {
+ let mut page_ids = BTreeSet::new();
+ let mut tile_ids = BTreeSet::new();
+ let mut pages = Vec::new();
+ for page in self.pages {
+ if pages.len() >= MAX_DECK_PAGES {
+ break;
+ }
+ if !is_valid_deck_id(&page.id) || !page_ids.insert(page.id.clone()) {
+ continue;
+ }
+ let name: String = page.name.chars().filter(|c| !c.is_control()).collect();
+ let name = name.trim();
+ if name.is_empty() {
+ continue;
+ }
+ let mut end = name.len().min(MAX_DECK_LABEL_BYTES);
+ while end > 0 && !name.is_char_boundary(end) {
+ end -= 1;
+ }
+ let name = name[..end].trim().to_owned();
+ if name.is_empty() {
+ continue;
+ }
+ let mut tiles = Vec::new();
+ for tile in page.tiles {
+ if tiles.len() >= MAX_DECK_TILES_PER_PAGE {
+ break;
+ }
+ if let Some(clean) = tile.sanitized()
+ && tile_ids.insert(clean.id.clone())
+ {
+ tiles.push(clean);
+ }
+ }
+ pages.push(DeckPageConfig { id: page.id, name, tiles });
+ }
+ (!pages.is_empty()).then_some(DeckConfig { pages })
+ }
+
+ /// Converts to the wire [`DeckLayout`] sent to paired phones.
+ pub fn to_wire_layout(&self) -> DeckLayout {
+ DeckLayout { pages: self.pages.iter().map(DeckPageConfig::to_wire).collect() }
+ }
+
+ /// Finds a tile by ID across all pages.
+ pub fn tile(&self, id: &str) -> Option<&DeckTileConfig> {
+ self.pages.iter().flat_map(|p| p.tiles.iter()).find(|t| t.id == id)
+ }
+
+ /// The default single-page Deck on first use (`docs/protocol/deck.md`).
+ pub fn default_deck() -> Self {
+ let tile = |id: &str, action: DeckAction| {
+ let kind = action.kind();
+ DeckTileConfig {
+ id: id.into(),
+ label: deck_kinds::default_label(kind).into(),
+ icon: deck_kinds::default_icon(kind).into(),
+ color: deck_kinds::default_color(kind).into(),
+ action,
+ }
+ };
+ DeckConfig {
+ pages: vec![DeckPageConfig {
+ id: "main".into(),
+ name: "Main".into(),
+ tiles: vec![
+ tile("play_pause", DeckAction::MediaPlayPause),
+ tile("prev_track", DeckAction::MediaPrevious),
+ tile("next_track", DeckAction::MediaNext),
+ tile("vol_down", DeckAction::VolumeDown),
+ tile("vol_up", DeckAction::VolumeUp),
+ tile("vol_mute", DeckAction::VolumeMute),
+ tile("mic_mute", DeckAction::MicMute),
+ tile("show_desktop", DeckAction::ShowDesktop),
+ tile("switch_window", DeckAction::SwitchWindow),
+ tile("screenshot", DeckAction::Screenshot),
+ tile("lock_pc", DeckAction::LockPc),
+ ],
+ }],
+ }
+ }
+
+ /// Loads `DeckConfig` from `path`, falling back to [`Self::default_deck`]
+ /// when the file does not exist or cannot be parsed/sanitized.
+ pub fn load(path: &Path) -> Self {
+ std::fs::read_to_string(path)
+ .ok()
+ .and_then(|s| serde_json::from_str::<DeckConfig>(&s).ok())
+ .and_then(DeckConfig::sanitized)
+ .unwrap_or_else(Self::default_deck)
+ }
+
+ /// Writes `self` as pretty-printed JSON to `path`.
+ pub fn save(&self, path: &Path) -> std::io::Result<()> {
+ if let Some(parent) = path.parent() {
+ std::fs::create_dir_all(parent)?;
+ }
+ let json = serde_json::to_string_pretty(self).map_err(std::io::Error::other)?;
+ std::fs::write(path, json)
+ }
+}
+
+impl Default for DeckConfig {
+ fn default() -> Self {
+ Self::default_deck()
+ }
+}
+
+/// This PC's Deck layout and live state (sent to newly connected phones) and
+/// the latest layout and state received from each connected PC.
+pub(crate) struct Current {
+ local_layout: Mutex<DeckLayout>,
+ local_state: Mutex<DeckState>,
+ peer_layouts: Mutex<HashMap<DeviceId, DeckLayout>>,
+ peer_states: Mutex<HashMap<DeviceId, DeckState>>,
+}
+
+impl Default for Current {
+ fn default() -> Self {
+ Self {
+ local_layout: Mutex::new(DeckLayout::default_layout()),
+ local_state: Mutex::new(DeckState::default()),
+ peer_layouts: Mutex::new(HashMap::new()),
+ peer_states: Mutex::new(HashMap::new()),
+ }
+ }
+}
+
+impl Current {
+ pub fn local_layout(&self) -> DeckLayout {
+ self.local_layout.lock().unwrap_or_else(|e| e.into_inner()).clone()
+ }
+
+ pub fn set_local_layout(&self, layout: DeckLayout) -> bool {
+ let mut guard = self.local_layout.lock().unwrap_or_else(|e| e.into_inner());
+ if *guard == layout {
+ false
+ } else {
+ *guard = layout;
+ true
+ }
+ }
+
+ pub fn local_state(&self) -> DeckState {
+ self.local_state.lock().unwrap_or_else(|e| e.into_inner()).clone()
+ }
+
+ pub fn set_local_state(&self, state: DeckState) -> bool {
+ let mut guard = self.local_state.lock().unwrap_or_else(|e| e.into_inner());
+ if *guard == state {
+ false
+ } else {
+ *guard = state;
+ true
+ }
+ }
+
+ pub fn peer_layout(&self, peer: &DeviceId) -> Option<DeckLayout> {
+ self.peer_layouts.lock().unwrap_or_else(|e| e.into_inner()).get(peer).cloned()
+ }
+
+ pub fn set_peer_layout(&self, peer: DeviceId, layout: DeckLayout) {
+ self.peer_layouts.lock().unwrap_or_else(|e| e.into_inner()).insert(peer, layout);
+ }
+
+ pub fn peer_state(&self, peer: &DeviceId) -> Option<DeckState> {
+ self.peer_states.lock().unwrap_or_else(|e| e.into_inner()).get(peer).cloned()
+ }
+
+ pub fn set_peer_state(&self, peer: DeviceId, state: DeckState) {
+ self.peer_states.lock().unwrap_or_else(|e| e.into_inner()).insert(peer, state);
+ }
+
+ pub fn remove_peer(&self, peer: &DeviceId) {
+ self.peer_layouts.lock().unwrap_or_else(|e| e.into_inner()).remove(peer);
+ self.peer_states.lock().unwrap_or_else(|e| e.into_inner()).remove(peer);
+ }
+}
+
+impl Shared {
+ fn offers_deck(&self) -> bool {
+ self.local_capabilities().iter().any(|c| c == DECK_ACTIONS)
+ }
+
+ /// Sends this PC's Deck layout and live state to `session` if this device
+ /// offers `deck.actions`.
+ pub(crate) async fn send_deck(&self, session: &Arc<Session>) {
+ if !self.offers_deck() {
+ return;
+ }
+ let layout = self.deck.local_layout();
+ if let Ok(env) = Envelope::new(types::DECK_LAYOUT, &layout) {
+ let _ = session.send(env).await;
+ }
+ let state = self.deck.local_state();
+ if let Ok(env) = Envelope::new(types::DECK_STATE, &state) {
+ let _ = session.send(env).await;
+ }
+ }
+
+ /// Updates this PC's Deck layout and sends it to connected peers.
+ pub(crate) async fn set_deck_layout(&self, layout: DeckLayout) -> Result<()> {
+ let clean = layout.sanitized().ok_or_else(|| Error::Protocol("invalid deck layout".into()))?;
+ self.deck.set_local_layout(clean.clone());
+ if self.offers_deck()
+ && let Ok(env) = Envelope::new(types::DECK_LAYOUT, &clean)
+ {
+ for session in self.live_sessions() {
+ let _ = session.send(env.clone()).await;
+ }
+ }
+ Ok(())
+ }
+
+ /// Updates this PC's live Deck state and sends it to connected peers when
+ /// it changed.
+ pub(crate) async fn set_deck_state(&self, state: DeckState) -> Result<()> {
+ let clean = state.sanitized().ok_or_else(|| Error::Protocol("invalid deck state".into()))?;
+ let changed = self.deck.set_local_state(clean.clone());
+ if changed
+ && self.offers_deck()
+ && let Ok(env) = Envelope::new(types::DECK_STATE, &clean)
+ {
+ for session in self.live_sessions() {
+ let _ = session.send(env.clone()).await;
+ }
+ }
+ Ok(())
+ }
+}
+
+/// Asks a paired PC to run the action bound to `tile` (`deck.press`).
+pub(crate) async fn press(shared: &Arc<Shared>, session: &Arc<Session>, tile: String) -> Result<()> {
+ let req = DeckPress { tile };
+ if !req.is_valid() {
+ return Err(Error::Protocol("invalid deck tile ID".into()));
+ }
+ let peer_caps = shared.store.get_peer(&session.peer)?.map(|p| p.caps).unwrap_or_default();
+ if !peer_caps.contains(DECK_ACTIONS) {
+ return Err(Error::Unsupported);
+ }
+ let env = Envelope::new(types::DECK_PRESS, &req)?;
+ session.request(env, REQUEST_TIMEOUT).await?.expect(types::OK)?;
+ Ok(())
+}
+
+/// Handles `deck.layout`, `deck.state`, and `deck.press`.
+pub(crate) async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: &Envelope) -> Result<bool> {
+ let peer = session.peer;
+ match env.t.as_str() {
+ types::DECK_LAYOUT => {
+ let layout: DeckLayout = env.body()?;
+ if let Some(clean) = layout.sanitized() {
+ shared.deck.set_peer_layout(peer, clean.clone());
+ shared.emit(NodeEvent::DeckLayout { device: peer, layout: clean });
+ }
+ }
+ types::DECK_STATE => {
+ let state: DeckState = env.body()?;
+ if let Some(clean) = state.sanitized() {
+ shared.deck.set_peer_state(peer, clean.clone());
+ shared.emit(NodeEvent::DeckState { device: peer, state: clean });
+ }
+ }
+ types::DECK_PRESS => {
+ let req: DeckPress = env.body()?;
+ let reply = run_press(shared, &peer, req).await;
+ session.send(reply.reply_to(env.id)).await?;
+ }
+ _ => return Ok(false),
+ }
+ Ok(true)
+}
+
+async fn run_press(shared: &Arc<Shared>, peer: &DeviceId, req: DeckPress) -> Envelope {
+ if !req.is_valid() {
+ return Envelope::error(ErrorCode::BadMessage, "invalid tile ID");
+ }
+ if !shared.offers_deck() {
+ return Envelope::error(ErrorCode::Unsupported, "deck actions are not supported here");
+ }
+ if !shared.toggle_on(peer, INPUT_TOGGLE) {
+ let first_time = shared.remote.lock().unwrap_or_else(|e| e.into_inner()).mark_prompted(*peer);
+ if first_time {
+ shared.emit(NodeEvent::RemoteInputRequested { device: *peer });
+ }
+ return Envelope::error(ErrorCode::Denied, "remote input is turned off for this device");
+ }
+ let layout = shared.deck.local_layout();
+ let Some(tile) = layout.tile(&req.tile).cloned() else {
+ return Envelope::error(ErrorCode::NotFound, "unknown tile");
+ };
+ if tile.kind == deck_kinds::RUN_COMMAND && !shared.toggle_on(peer, COMMANDS_TOGGLE) {
+ return Envelope::error(ErrorCode::Denied, "commands are turned off for this device");
+ }
+ let platform = shared.platform.clone();
+ let from = *peer;
+ let id = tile.id;
+ let ran = tokio::task::spawn_blocking(move || platform.deck_press(&from, &id))
+ .await
+ .unwrap_or_else(|e| Err(e.to_string()));
+ match ran {
+ Ok(()) => Envelope::empty(types::OK),
+ Err(reason) => {
+ tracing::warn!(reason, "deck action failed");
+ Envelope::error(ErrorCode::Internal, "failed")
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn default_deck_matches_wire_layout_and_is_valid() {
+ let cfg = DeckConfig::default_deck();
+ assert!(cfg.is_valid());
+ let wire = cfg.to_wire_layout();
+ assert_eq!(wire, DeckLayout::default_layout());
+ assert!(wire.is_valid());
+ }
+
+ #[test]
+ fn action_validation_enforces_http_exe_lnk_and_shortcuts() {
+ assert!(DeckAction::OpenUrl { url: "https://example.com/path?q=1".into() }.is_valid());
+ assert!(DeckAction::OpenUrl { url: "http://localhost:8080".into() }.is_valid());
+ assert!(!DeckAction::OpenUrl { url: "javascript:alert(1)".into() }.is_valid());
+ assert!(!DeckAction::OpenUrl { url: "file:///C:/Windows/System32/cmd.exe".into() }.is_valid());
+ assert!(!DeckAction::OpenUrl { url: "ftp://example.com".into() }.is_valid());
+
+ assert!(DeckAction::LaunchApp { path: r"C:\Windows\System32\calc.exe".into() }.is_valid());
+ assert!(DeckAction::LaunchApp { path: r"C:\Users\me\Desktop\OBS Studio.LNK".into() }.is_valid());
+ assert!(!DeckAction::LaunchApp { path: r"C:\scripts\evil.bat".into() }.is_valid());
+ assert!(!DeckAction::LaunchApp { path: r"C:\scripts\evil.ps1".into() }.is_valid());
+ assert!(!DeckAction::LaunchApp { path: ".exe".into() }.is_valid());
+
+ assert!(DeckAction::Shortcut { key: "m".into(), mods: vec![KeyMod::Ctrl, KeyMod::Shift] }.is_valid());
+ assert!(DeckAction::Shortcut { key: remote_keys::F5.into(), mods: vec![] }.is_valid());
+ assert!(!DeckAction::Shortcut { key: "m".into(), mods: vec![KeyMod::Ctrl, KeyMod::Ctrl] }.is_valid());
+ assert!(!DeckAction::Shortcut { key: "unknown".into(), mods: vec![] }.is_valid());
+
+ assert!(DeckAction::TypeText { text: "Hello\nworld".into() }.is_valid());
+ assert!(!DeckAction::TypeText { text: String::new() }.is_valid());
+ assert!(!DeckAction::TypeText { text: "bad\u{0}char".into() }.is_valid());
+
+ assert!(DeckAction::RunCommand { command: "cargo test --workspace".into() }.is_valid());
+ assert!(!DeckAction::RunCommand { command: " ".into() }.is_valid());
+ assert!(!DeckAction::RunCommand { command: "line1\nline2".into() }.is_valid());
+ }
+
+ #[test]
+ fn wire_layout_and_debug_never_expose_paths_urls_or_commands() {
+ let mut cfg = DeckConfig::default_deck();
+ cfg.pages[0].tiles.push(DeckTileConfig {
+ id: "secret_cmd".into(),
+ label: "Deploy".into(),
+ icon: deck_icons::TERMINAL.into(),
+ color: deck_colors::CORAL.into(),
+ action: DeckAction::RunCommand { command: "echo super-secret-token".into() },
+ });
+ cfg.pages[0].tiles.push(DeckTileConfig {
+ id: "secret_app".into(),
+ label: "Calculator".into(),
+ icon: deck_icons::APP.into(),
+ color: deck_colors::TEAL.into(),
+ action: DeckAction::LaunchApp { path: r"C:\Private\secret_app.exe".into() },
+ });
+ cfg.pages[0].tiles.push(DeckTileConfig {
+ id: "secret_url".into(),
+ label: "Dashboard".into(),
+ icon: deck_icons::GLOBE.into(),
+ color: deck_colors::BLUE.into(),
+ action: DeckAction::OpenUrl { url: "https://internal.example.com/secret".into() },
+ });
+
+ let dbg = format!("{cfg:?}");
+ assert!(!dbg.contains("super-secret-token") && !dbg.contains("secret_app.exe"), "{dbg}");
+
+ let wire = cfg.to_wire_layout();
+ let cbor = Envelope::new(types::DECK_LAYOUT, &wire).unwrap().to_cbor();
+ let cbor_text = String::from_utf8_lossy(&cbor);
+ assert!(!cbor_text.contains("super-secret-token"));
+ assert!(!cbor_text.contains("secret_app.exe"));
+ assert!(!cbor_text.contains("internal.example.com"));
+ assert_eq!(wire.tile("secret_cmd").unwrap().kind, deck_kinds::RUN_COMMAND);
+ assert_eq!(wire.tile("secret_app").unwrap().kind, deck_kinds::LAUNCH_APP);
+ assert_eq!(wire.tile("secret_url").unwrap().kind, deck_kinds::OPEN_URL);
+ }
+
+ #[test]
+ fn deck_config_persists_to_disk_and_falls_back_on_corrupt_file() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("deck.json");
+
+ // Missing file returns the default deck.
+ assert_eq!(DeckConfig::load(&path), DeckConfig::default_deck());
+
+ let mut custom = DeckConfig::default_deck();
+ custom.pages.push(DeckPageConfig {
+ id: "custom".into(),
+ name: "Work".into(),
+ tiles: vec![DeckTileConfig {
+ id: "site".into(),
+ label: "Docs".into(),
+ icon: deck_icons::GLOBE.into(),
+ color: deck_colors::BLUE.into(),
+ action: DeckAction::OpenUrl { url: "https://example.com".into() },
+ }],
+ });
+ custom.save(&path).unwrap();
+ assert_eq!(DeckConfig::load(&path), custom);
+
+ // Corrupt JSON falls back to default_deck().
+ std::fs::write(&path, b"{not valid json").unwrap();
+ assert_eq!(DeckConfig::load(&path), DeckConfig::default_deck());
+ }
+}
diff --git a/core/nectarlink-core/src/events.rs b/core/nectarlink-core/src/events.rs
index 5398416..015d195 100644
--- a/core/nectarlink-core/src/events.rs
+++ b/core/nectarlink-core/src/events.rs
@@ -182,4 +182,14 @@ pub enum NodeEvent {
device: DeviceId,
can_wake: bool,
},
+ /// A paired PC's Deck layout arrived or changed (`docs/protocol/deck.md`).
+ DeckLayout {
+ device: DeviceId,
+ layout: crate::DeckLayout,
+ },
+ /// A paired PC's live Deck state arrived or changed (`docs/protocol/deck.md`).
+ DeckState {
+ device: DeviceId,
+ state: crate::DeckState,
+ },
}
diff --git a/core/nectarlink-core/src/features.rs b/core/nectarlink-core/src/features.rs
index d91c2bf..322bb32 100644
--- a/core/nectarlink-core/src/features.rs
+++ b/core/nectarlink-core/src/features.rs
@@ -343,6 +343,8 @@ pub const DEVICE_TOGGLES: &[(&str, bool)] = &[
("mirroring", true),
// Controlling this PC's mouse and keyboard is opt-in.
("remote_input", false),
+ // Running custom Deck commands on this PC is opt-in.
+ ("commands", false),
// Browsing the PC's files from anywhere is opt-in.
("remote_files", false),
];
diff --git a/core/nectarlink-core/src/lib.rs b/core/nectarlink-core/src/lib.rs
index 8754fc0..30e4599 100644
--- a/core/nectarlink-core/src/lib.rs
+++ b/core/nectarlink-core/src/lib.rs
@@ -11,6 +11,7 @@ mod calls;
mod clipboard;
mod config;
mod contacts;
+pub mod deck;
mod error;
mod events;
pub mod features;
@@ -31,6 +32,13 @@ mod transfer;
pub use actions::{PC_WAKE, PowerAction};
pub use calls::CallCommand;
pub use config::{NodeConfig, NoopPlatform, Platform};
+pub use deck::{
+ COMMANDS_TOGGLE as DECK_COMMANDS_TOGGLE, DECK_ACTIONS, DeckAction, DeckConfig, DeckLayout, DeckPage,
+ DeckPageConfig, DeckPress, DeckState, DeckTile, DeckTileConfig, INPUT_TOGGLE as DECK_INPUT_TOGGLE,
+ MAX_DECK_ID_BYTES, MAX_DECK_LABEL_BYTES, MAX_DECK_PAGES, MAX_DECK_TILES_PER_PAGE, deck_colors,
+ deck_icons, deck_kinds, format_shortcut, is_valid_app_path, is_valid_command, is_valid_deck_id,
+ is_valid_http_url, is_valid_shortcut, is_valid_snippet,
+};
pub use error::{Error, Result, Side};
pub use events::{
ConnectionPath, DiscoveredDevice, LinkState, NodeEvent, PairedDevice, PairingEvent, PairingFailure,
diff --git a/core/nectarlink-core/src/node.rs b/core/nectarlink-core/src/node.rs
index edbcc53..e2602e3 100644
--- a/core/nectarlink-core/src/node.rs
+++ b/core/nectarlink-core/src/node.rs
@@ -124,6 +124,8 @@ pub(crate) struct Shared {
pub(crate) toggles: crate::toggles::Current,
/// This PC's Wake-on-LAN adapter addresses (docs/protocol/actions.md).
pub(crate) wake_info: crate::actions::CurrentWakeInfo,
+ /// This PC's Deck layout and live state, and connected PCs' Decks (docs/protocol/deck.md).
+ pub(crate) deck: crate::deck::Current,
/// Stop signals for phone screens shown here, by phone.
pub(crate) mirror_stops: Mutex<HashMap<MirrorStop, Arc<tokio::sync::Notify>>>,
/// Per-peer rate limiters and prompt state for remote input.
@@ -314,6 +316,7 @@ impl Shared {
lock(&self.matrices).remove(peer);
lock(&self.remote).remove_peer(peer);
self.toggles.remove_peer(peer);
+ self.deck.remove_peer(peer);
if existed {
self.emit(NodeEvent::DeviceRemoved(*peer));
}
@@ -384,6 +387,7 @@ impl Shared {
shared.send_call_state(&s).await;
shared.send_toggles_state(&s).await;
crate::actions::send_wake_info(&shared, &s).await;
+ shared.send_deck(&s).await;
});
Some(session)
}
@@ -395,6 +399,7 @@ impl Shared {
if current {
sessions.remove(&ended.peer);
self.toggles.remove_peer(&ended.peer);
+ self.deck.remove_peer(&ended.peer);
if paired {
tracing::info!(peer = %ended.peer.short(), "disconnected");
// Still under the lock: a new session for the peer can't
@@ -643,6 +648,7 @@ impl Node {
calls: Default::default(),
toggles: Default::default(),
wake_info: Default::default(),
+ deck: Default::default(),
mirror_stops: Mutex::new(HashMap::new()),
remote: Mutex::new(Default::default()),
data_dir: config.data_dir.clone(),
@@ -765,6 +771,7 @@ impl Node {
self.shared.send_media_state(&session).await;
self.shared.send_toggles_state(&session).await;
crate::actions::send_wake_info(&self.shared, &session).await;
+ self.shared.send_deck(&session).await;
}
}
@@ -1365,6 +1372,36 @@ impl Node {
crate::toggles::set(&self.shared, &session, id, value).await
}
+ // ---- Deck (docs/protocol/deck.md) ----
+
+ /// The latest Deck layout reported by a connected PC, if any.
+ pub fn deck_layout(&self, peer: DeviceId) -> Option<crate::DeckLayout> {
+ self.shared.deck.peer_layout(&peer)
+ }
+
+ /// The latest live Deck state reported by a connected PC, if any.
+ pub fn deck_state(&self, peer: DeviceId) -> Option<crate::DeckState> {
+ self.shared.deck.peer_state(&peer)
+ }
+
+ /// Updates this PC's Deck layout and sends it to every connected phone
+ /// when this device offers `deck.actions`.
+ pub async fn set_deck_layout(&self, layout: crate::DeckLayout) -> Result<()> {
+ self.shared.set_deck_layout(layout).await
+ }
+
+ /// Updates this PC's live Deck state and sends it to every connected phone
+ /// when it changed and this device offers `deck.actions`.
+ pub async fn set_deck_state(&self, state: crate::DeckState) -> Result<()> {
+ self.shared.set_deck_state(state).await
+ }
+
+ /// Asks a paired PC to run the action bound to `tile` (`deck.press`).
+ pub async fn deck_press(&self, peer: DeviceId, tile: String) -> Result<()> {
+ let session = self.connected(&peer)?;
+ crate::deck::press(&self.shared, &session, tile).await
+ }
+
// ---- Local state reported by the app ----
/// Reports this device's battery; forwarded to connected devices.
@@ -1399,6 +1436,9 @@ impl Node {
self.shared.broadcast(env).await;
}
self.shared.refresh_all_capabilities();
+ for session in self.shared.live_sessions() {
+ self.shared.send_deck(&session).await;
+ }
}
}
diff --git a/core/nectarlink-core/src/remote.rs b/core/nectarlink-core/src/remote.rs
index 85430cf..f583e73 100644
--- a/core/nectarlink-core/src/remote.rs
+++ b/core/nectarlink-core/src/remote.rs
@@ -117,8 +117,14 @@ fn we_offer(shared: &Shared, cap: &str) -> bool {
shared.local_capabilities().iter().any(|c| c == cap)
}
-fn check_allowed(shared: &Shared, peer: &DeviceId) -> std::result::Result<(), (ErrorCode, &'static str)> {
- if !we_offer(shared, INPUT_INJECT) {
+fn check_allowed_with(
+ shared: &Shared,
+ peer: &DeviceId,
+ allow_deck: bool,
+) -> std::result::Result<(), (ErrorCode, &'static str)> {
+ let supported =
+ we_offer(shared, INPUT_INJECT) || (allow_deck && we_offer(shared, crate::deck::DECK_ACTIONS));
+ if !supported {
return Err((ErrorCode::Unsupported, "remote input is not supported here"));
}
if !shared.toggle_on(peer, TOGGLE) {
@@ -131,9 +137,15 @@ fn check_allowed(shared: &Shared, peer: &DeviceId) -> std::result::Result<(), (E
Ok(())
}
+fn check_allowed(shared: &Shared, peer: &DeviceId) -> std::result::Result<(), (ErrorCode, &'static str)> {
+ check_allowed_with(shared, peer, false)
+}
+
/// Checks whether `peer` (a PC) currently accepts remote input from this phone.
pub(crate) async fn check(shared: &Arc<Shared>, session: &Arc<Session>) -> Result<()> {
- if !peer_offers(shared, &session.peer, INPUT_INJECT)? {
+ if !peer_offers(shared, &session.peer, INPUT_INJECT)?
+ && !peer_offers(shared, &session.peer, crate::deck::DECK_ACTIONS)?
+ {
return Err(Error::Unsupported);
}
session.request(Envelope::empty(types::REMOTE_CHECK), TIMEOUT).await?.expect(types::OK)?;
@@ -237,7 +249,7 @@ async fn send_datagram(shared: &Arc<Shared>, session: &Arc<Session>, event: &Rem
/// Handles incoming `remote.*` requests on the control stream.
pub(crate) async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: &Envelope) -> Result<bool> {
let reply = match env.t.as_str() {
- types::REMOTE_CHECK => match check_allowed(shared, &session.peer) {
+ types::REMOTE_CHECK => match check_allowed_with(shared, &session.peer, true) {
Ok(()) => Envelope::empty(types::OK),
Err((code, msg)) => Envelope::error(code, msg),
},
diff --git a/core/nectarlink-core/src/session.rs b/core/nectarlink-core/src/session.rs
index 8c5f730..3954526 100644
--- a/core/nectarlink-core/src/session.rs
+++ b/core/nectarlink-core/src/session.rs
@@ -406,6 +406,7 @@ async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: Envelope) ->
t if t.starts_with("mirror.") && crate::mirror::handle(shared, session, &env).await? => {}
t if t.starts_with("remote.") && crate::remote::handle(shared, session, &env).await? => {}
t if t.starts_with("phone.toggle") && crate::toggles::handle(shared, session, &env).await? => {}
+ t if t.starts_with("deck.") && crate::deck::handle(shared, session, &env).await? => {}
other => {
if env.id.is_some() {
let reply = Envelope::error(ErrorCode::Unsupported, format!("unknown message type {other}"));
diff --git a/core/nectarlink-core/tests/two_devices.rs b/core/nectarlink-core/tests/two_devices.rs
index 928aa76..4e32b18 100644
--- a/core/nectarlink-core/tests/two_devices.rs
+++ b/core/nectarlink-core/tests/two_devices.rs
@@ -42,6 +42,7 @@ struct RecordingPlatform {
photo_barrier: Mutex<Option<Arc<std::sync::Barrier>>>,
remote_inputs: Mutex<Vec<nectarlink_core::RemoteInput>>,
phone_toggles: Mutex<Vec<(String, nectarlink_core::PhoneToggleValue)>>,
+ deck_presses: Mutex<Vec<String>>,
}
impl Platform for RecordingPlatform {
@@ -395,6 +396,10 @@ impl Platform for RecordingPlatform {
self.phone_toggles.lock().unwrap().push((id.to_owned(), value.clone()));
Ok(())
}
+ fn deck_press(&self, _from: &nectarlink_core::DeviceId, tile: &str) -> Result<(), String> {
+ self.deck_presses.lock().unwrap().push(tile.to_owned());
+ Ok(())
+ }
}
#[derive(Debug, Default)]
@@ -2547,3 +2552,102 @@ async fn wake_info_syncs_persists_respects_toggle_and_sends_magic_packet() {
assert_eq!(&buf[..102], &magic_packet(&[0x38, 0xA7, 0x46, 0x37, 0x2E, 0x64])[..]);
phone.node.shutdown().await;
}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn deck_layout_and_state_arrive_press_runs_action_and_respects_toggles_and_unknown_tile() {
+ use nectarlink_core::{
+ DECK_ACTIONS, DeckAction, DeckConfig, DeckLayout, DeckState, DeckTileConfig, deck_colors, deck_icons,
+ };
+
+ let mut pc = device_with("Desktop", DeviceKind::Desktop, &[DECK_ACTIONS]).await;
+ let mut phone = device("Pixel", DeviceKind::Phone).await;
+
+ let mut cfg = DeckConfig::default_deck();
+ cfg.pages[0].tiles.push(DeckTileConfig {
+ id: "run_build".into(),
+ label: "Build".into(),
+ icon: deck_icons::TERMINAL.into(),
+ color: deck_colors::CORAL.into(),
+ action: DeckAction::RunCommand { command: "cargo check".into() },
+ });
+ let expected_layout = cfg.to_wire_layout();
+ pc.node.set_deck_layout(expected_layout.clone()).await.unwrap();
+ let initial_state = DeckState { playing: true, volume: 60, muted: false, mic_muted: Some(false) };
+ pc.node.set_deck_state(initial_state.clone()).await.unwrap();
+
+ pair_qr(&mut pc, &mut phone).await;
+ let (pc_id, phone_id) = (pc.node.device_id(), phone.node.device_id());
+
+ // Initial layout and live state arrive on connect.
+ let got_layout = wait_for(&mut phone, "initial deck layout", |e| match e {
+ NodeEvent::DeckLayout { device, layout } if *device == pc_id => Some(layout.clone()),
+ _ => None,
+ })
+ .await;
+ assert_eq!(got_layout, expected_layout);
+ assert_eq!(phone.node.deck_layout(pc_id), Some(expected_layout));
+
+ let got_state = wait_for(&mut phone, "initial deck state", |e| match e {
+ NodeEvent::DeckState { device, state } if *device == pc_id && *state == initial_state => {
+ Some(state.clone())
+ }
+ _ => None,
+ })
+ .await;
+ assert_eq!(got_state, initial_state);
+ assert_eq!(phone.node.deck_state(pc_id), Some(initial_state));
+
+ // Both `remote_input` and `commands` are off by default on the PC.
+ let toggles = pc.node.device_toggles(phone_id).unwrap();
+ assert!(toggles.contains(&("remote_input", false)));
+ assert!(toggles.contains(&("commands", false)));
+
+ // Pressing any tile while `remote_input` is off is denied and emits the one-time prompt.
+ assert!(matches!(phone.node.deck_press(pc_id, "play_pause".into()).await, Err(Error::Denied)));
+ wait_for(&mut pc, "remote input prompt from deck", |e| match e {
+ NodeEvent::RemoteInputRequested { device } if *device == phone_id => Some(()),
+ _ => None,
+ })
+ .await;
+ assert!(pc.platform.deck_presses.lock().unwrap().is_empty());
+
+ // Enable `remote_input`: built-in tiles work, unknown tiles return NotFound,
+ // and `run_command` tiles are still denied while `commands` is off.
+ pc.node.set_device_toggle(phone_id, "remote_input", true).unwrap();
+ with_timeout("press play_pause", phone.node.deck_press(pc_id, "play_pause".into())).await.unwrap();
+ with_timeout("press mic_mute", phone.node.deck_press(pc_id, "mic_mute".into())).await.unwrap();
+ assert!(matches!(phone.node.deck_press(pc_id, "no_such_tile".into()).await, Err(Error::NotFound)));
+ assert!(matches!(phone.node.deck_press(pc_id, "bad tile!".into()).await, Err(Error::Protocol(_))));
+ assert!(matches!(phone.node.deck_press(pc_id, "run_build".into()).await, Err(Error::Denied)));
+
+ // Enable `commands`: the `run_command` tile now runs.
+ pc.node.set_device_toggle(phone_id, "commands", true).unwrap();
+ with_timeout("press run_build", phone.node.deck_press(pc_id, "run_build".into())).await.unwrap();
+
+ assert_eq!(
+ *pc.platform.deck_presses.lock().unwrap(),
+ vec!["play_pause".to_owned(), "mic_mute".to_owned(), "run_build".to_owned()]
+ );
+
+ // Live state updates push to the phone.
+ let updated_state = DeckState { playing: false, volume: 45, muted: true, mic_muted: Some(true) };
+ pc.node.set_deck_state(updated_state.clone()).await.unwrap();
+ let got_updated = wait_for(&mut phone, "updated deck state", |e| match e {
+ NodeEvent::DeckState { device, state } if *device == pc_id && *state == updated_state => {
+ Some(state.clone())
+ }
+ _ => None,
+ })
+ .await;
+ assert_eq!(got_updated, updated_state);
+
+ // Layout edits push to the phone; removed tiles can no longer be pressed.
+ let default_only = DeckLayout::default_layout();
+ pc.node.set_deck_layout(default_only.clone()).await.unwrap();
+ wait_for(&mut phone, "updated deck layout", |e| match e {
+ NodeEvent::DeckLayout { device, layout } if *device == pc_id && *layout == default_only => Some(()),
+ _ => None,
+ })
+ .await;
+ assert!(matches!(phone.node.deck_press(pc_id, "run_build".into()).await, Err(Error::NotFound)));
+}
diff --git a/core/nectarlink-ffi/src/lib.rs b/core/nectarlink-ffi/src/lib.rs
index 1d183b6..76d91b7 100644
--- a/core/nectarlink-ffi/src/lib.rs
+++ b/core/nectarlink-ffi/src/lib.rs
@@ -486,6 +486,93 @@ pub enum Event {
id: String,
can_wake: bool,
},
+ /// A paired PC's Deck layout arrived or changed (phones only).
+ DeckLayout {
+ id: String,
+ layout: DeckLayout,
+ },
+ /// A paired PC's live Deck state arrived or changed (phones only).
+ DeckState {
+ id: String,
+ state: DeckState,
+ },
+}
+
+/// One tile on a PC's Deck (`docs/protocol/deck.md`).
+#[derive(Clone, PartialEq, Eq, uniffi::Record)]
+pub struct DeckTile {
+ pub id: String,
+ pub label: String,
+ pub icon: String,
+ pub color: String,
+ pub kind: String,
+}
+
+impl std::fmt::Debug for DeckTile {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckTile")
+ .field("id", &self.id)
+ .field("icon", &self.icon)
+ .field("color", &self.color)
+ .field("kind", &self.kind)
+ .finish_non_exhaustive()
+ }
+}
+
+impl From<core::DeckTile> for DeckTile {
+ fn from(t: core::DeckTile) -> Self {
+ DeckTile { id: t.id, label: t.label, icon: t.icon, color: t.color, kind: t.kind }
+ }
+}
+
+/// One page of tiles on a PC's Deck (`docs/protocol/deck.md`).
+#[derive(Clone, PartialEq, Eq, uniffi::Record)]
+pub struct DeckPage {
+ pub id: String,
+ pub name: String,
+ pub tiles: Vec<DeckTile>,
+}
+
+impl std::fmt::Debug for DeckPage {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckPage")
+ .field("id", &self.id)
+ .field("tiles", &self.tiles.len())
+ .finish_non_exhaustive()
+ }
+}
+
+impl From<core::DeckPage> for DeckPage {
+ fn from(p: core::DeckPage) -> Self {
+ DeckPage { id: p.id, name: p.name, tiles: p.tiles.into_iter().map(Into::into).collect() }
+ }
+}
+
+/// A PC's Deck layout (`docs/protocol/deck.md`).
+#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
+pub struct DeckLayout {
+ pub pages: Vec<DeckPage>,
+}
+
+impl From<core::DeckLayout> for DeckLayout {
+ fn from(l: core::DeckLayout) -> Self {
+ DeckLayout { pages: l.pages.into_iter().map(Into::into).collect() }
+ }
+}
+
+/// Live PC state reflected on Deck tiles (`docs/protocol/deck.md`).
+#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
+pub struct DeckState {
+ pub playing: bool,
+ pub volume: u8,
+ pub muted: bool,
+ pub mic_muted: Option<bool>,
+}
+
+impl From<core::DeckState> for DeckState {
+ fn from(s: core::DeckState) -> Self {
+ DeckState { playing: s.playing, volume: s.volume, muted: s.muted, mic_muted: s.mic_muted }
+ }
}
/// This phone's quick settings state (docs/protocol/toggles.md).
@@ -1324,6 +1411,12 @@ impl From<NodeEvent> for Event {
NodeEvent::WakeInfoChanged { device, can_wake } => {
Event::WakeInfoChanged { id: device.to_string(), can_wake }
}
+ NodeEvent::DeckLayout { device, layout } => {
+ Event::DeckLayout { id: device.to_string(), layout: layout.into() }
+ }
+ NodeEvent::DeckState { device, state } => {
+ Event::DeckState { id: device.to_string(), state: state.into() }
+ }
}
}
}
@@ -2169,6 +2262,27 @@ impl NectarlinkNode {
self.run(async move { Ok(node.remote_laser(id, on, x, y).await?) }).await
}
+ // ---- Deck (macro pad) ----
+
+ /// The latest Deck layout reported by a connected PC, if any.
+ pub fn deck_layout(&self, id: String) -> Result<Option<DeckLayout>> {
+ let id = parse_id(&id)?;
+ Ok(self.node.deck_layout(id).map(Into::into))
+ }
+
+ /// The latest live Deck state reported by a connected PC, if any.
+ pub fn deck_state(&self, id: String) -> Result<Option<DeckState>> {
+ let id = parse_id(&id)?;
+ Ok(self.node.deck_state(id).map(Into::into))
+ }
+
+ /// Asks a paired PC to run the action bound to `tile` (`deck.press`).
+ pub async fn deck_press(&self, id: String, tile: String) -> Result<()> {
+ let id = parse_id(&id)?;
+ let node = self.node.clone();
+ self.run(async move { Ok(node.deck_press(id, tile).await?) }).await
+ }
+
/// Opens this phone's screen stream to a PC that asked (after the user
/// agreed).
pub async fn mirror_open(&self, pc_id: String) -> Result<Arc<MirrorStream>> {
diff --git a/core/nectarlink-protocol/src/messages.rs b/core/nectarlink-protocol/src/messages.rs
index a15663c..570aa0a 100644
--- a/core/nectarlink-protocol/src/messages.rs
+++ b/core/nectarlink-protocol/src/messages.rs
@@ -73,6 +73,9 @@ pub mod types {
pub const REMOTE_INPUT: &str = "remote.input";
pub const PHONE_TOGGLES: &str = "phone.toggles";
pub const PHONE_TOGGLE_SET: &str = "phone.toggle.set";
+ pub const DECK_LAYOUT: &str = "deck.layout";
+ pub const DECK_STATE: &str = "deck.state";
+ pub const DECK_PRESS: &str = "deck.press";
}
/// What kind of device this is.
@@ -2211,6 +2214,443 @@ impl PhoneToggleSet {
}
}
+// ---- Deck (docs/protocol/deck.md) ----
+
+pub mod deck {
+ /// Offered by PCs that share their Deck layout and live state and run Deck actions.
+ pub const ACTIONS: &str = "deck.actions";
+ /// Maximum pages in a `DeckLayout`.
+ pub const MAX_PAGES: usize = 8;
+ /// Maximum tiles on a single `DeckPage`.
+ pub const MAX_TILES_PER_PAGE: usize = 24;
+ /// Maximum bytes in a page or tile ID.
+ pub const MAX_ID_BYTES: usize = 64;
+ /// Maximum UTF-8 bytes in a page name or tile label.
+ pub const MAX_LABEL_BYTES: usize = 64;
+}
+
+/// Action kinds for [`DeckTile::kind`] (`docs/protocol/deck.md` §2.4).
+pub mod deck_kinds {
+ pub const MEDIA_PLAY_PAUSE: &str = "media_play_pause";
+ pub const MEDIA_NEXT: &str = "media_next";
+ pub const MEDIA_PREVIOUS: &str = "media_previous";
+ pub const VOLUME_UP: &str = "volume_up";
+ pub const VOLUME_DOWN: &str = "volume_down";
+ pub const VOLUME_MUTE: &str = "volume_mute";
+ pub const MIC_MUTE: &str = "mic_mute";
+ pub const LOCK_PC: &str = "lock_pc";
+ pub const SHOW_DESKTOP: &str = "show_desktop";
+ pub const SWITCH_WINDOW: &str = "switch_window";
+ pub const SCREENSHOT: &str = "screenshot";
+ pub const SHORTCUT: &str = "shortcut";
+ pub const OPEN_URL: &str = "open_url";
+ pub const TYPE_TEXT: &str = "type_text";
+ pub const LAUNCH_APP: &str = "launch_app";
+ pub const RUN_COMMAND: &str = "run_command";
+
+ pub const ALL: &[&str] = &[
+ MEDIA_PLAY_PAUSE,
+ MEDIA_NEXT,
+ MEDIA_PREVIOUS,
+ VOLUME_UP,
+ VOLUME_DOWN,
+ VOLUME_MUTE,
+ MIC_MUTE,
+ LOCK_PC,
+ SHOW_DESKTOP,
+ SWITCH_WINDOW,
+ SCREENSHOT,
+ SHORTCUT,
+ OPEN_URL,
+ TYPE_TEXT,
+ LAUNCH_APP,
+ RUN_COMMAND,
+ ];
+
+ /// Default icon for an action kind.
+ pub fn default_icon(kind: &str) -> &'static str {
+ use super::deck_icons::*;
+ match kind {
+ MEDIA_PLAY_PAUSE => PLAY,
+ MEDIA_NEXT => SKIP_NEXT,
+ MEDIA_PREVIOUS => SKIP_PREVIOUS,
+ VOLUME_UP => VOLUME_UP,
+ VOLUME_DOWN => VOLUME_DOWN,
+ VOLUME_MUTE => VOLUME_OFF,
+ MIC_MUTE => MIC,
+ LOCK_PC => LOCK,
+ SHOW_DESKTOP => DESKTOP,
+ SWITCH_WINDOW => SWITCH_WINDOW,
+ SCREENSHOT => SCREENSHOT,
+ SHORTCUT => SHORTCUT,
+ OPEN_URL => GLOBE,
+ TYPE_TEXT => TEXT,
+ LAUNCH_APP => APP,
+ RUN_COMMAND => TERMINAL,
+ _ => SPARKLE,
+ }
+ }
+
+ /// Default color for an action kind.
+ pub fn default_color(kind: &str) -> &'static str {
+ use super::deck_colors::*;
+ match kind {
+ MEDIA_PLAY_PAUSE => AMBER,
+ MEDIA_NEXT | MEDIA_PREVIOUS => SLATE,
+ VOLUME_UP | VOLUME_DOWN | VOLUME_MUTE => TEAL,
+ MIC_MUTE => CORAL,
+ LOCK_PC => RED,
+ SHOW_DESKTOP | SWITCH_WINDOW => BLUE,
+ SCREENSHOT => VIOLET,
+ SHORTCUT => AMBER,
+ OPEN_URL => BLUE,
+ TYPE_TEXT => GREEN,
+ LAUNCH_APP => TEAL,
+ RUN_COMMAND => CORAL,
+ _ => AMBER,
+ }
+ }
+
+ /// Default label for an action kind.
+ pub fn default_label(kind: &str) -> &'static str {
+ match kind {
+ MEDIA_PLAY_PAUSE => "Play / Pause",
+ MEDIA_NEXT => "Next",
+ MEDIA_PREVIOUS => "Previous",
+ VOLUME_UP => "Volume Up",
+ VOLUME_DOWN => "Volume Down",
+ VOLUME_MUTE => "Mute Audio",
+ MIC_MUTE => "Mic Mute",
+ LOCK_PC => "Lock PC",
+ SHOW_DESKTOP => "Show Desktop",
+ SWITCH_WINDOW => "Switch Window",
+ SCREENSHOT => "Screenshot",
+ SHORTCUT => "Shortcut",
+ OPEN_URL => "Open Website",
+ TYPE_TEXT => "Type Text",
+ LAUNCH_APP => "Launch App",
+ RUN_COMMAND => "Run Command",
+ _ => "Action",
+ }
+ }
+}
+
+/// Fixed icon identifiers for [`DeckTile::icon`] (`docs/protocol/deck.md` §2.4).
+pub mod deck_icons {
+ pub const PLAY: &str = "play";
+ pub const PAUSE: &str = "pause";
+ pub const SKIP_NEXT: &str = "skip_next";
+ pub const SKIP_PREVIOUS: &str = "skip_previous";
+ pub const VOLUME_UP: &str = "volume_up";
+ pub const VOLUME_DOWN: &str = "volume_down";
+ pub const VOLUME_OFF: &str = "volume_off";
+ pub const MIC: &str = "mic";
+ pub const MIC_OFF: &str = "mic_off";
+ pub const LOCK: &str = "lock";
+ pub const DESKTOP: &str = "desktop";
+ pub const SWITCH_WINDOW: &str = "switch_window";
+ pub const SCREENSHOT: &str = "screenshot";
+ pub const SHORTCUT: &str = "shortcut";
+ pub const GLOBE: &str = "globe";
+ pub const TEXT: &str = "text";
+ pub const APP: &str = "app";
+ pub const TERMINAL: &str = "terminal";
+ pub const SPARKLE: &str = "sparkle";
+ pub const STAR: &str = "star";
+
+ pub const ALL: &[&str] = &[
+ PLAY,
+ PAUSE,
+ SKIP_NEXT,
+ SKIP_PREVIOUS,
+ VOLUME_UP,
+ VOLUME_DOWN,
+ VOLUME_OFF,
+ MIC,
+ MIC_OFF,
+ LOCK,
+ DESKTOP,
+ SWITCH_WINDOW,
+ SCREENSHOT,
+ SHORTCUT,
+ GLOBE,
+ TEXT,
+ APP,
+ TERMINAL,
+ SPARKLE,
+ STAR,
+ ];
+}
+
+/// Fixed color identifiers for [`DeckTile::color`] (`docs/protocol/deck.md` §2.4).
+pub mod deck_colors {
+ pub const AMBER: &str = "amber";
+ pub const CORAL: &str = "coral";
+ pub const RED: &str = "red";
+ pub const TEAL: &str = "teal";
+ pub const GREEN: &str = "green";
+ pub const BLUE: &str = "blue";
+ pub const VIOLET: &str = "violet";
+ pub const SLATE: &str = "slate";
+
+ pub const ALL: &[&str] = &[AMBER, CORAL, RED, TEAL, GREEN, BLUE, VIOLET, SLATE];
+}
+
+/// Whether a Deck page or tile ID is 1..=64 ASCII alphanumeric, `_`, `-`, or `.` characters.
+pub fn is_valid_deck_id(id: &str) -> bool {
+ (1..=deck::MAX_ID_BYTES).contains(&id.len())
+ && id.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'_' | b'-' | b'.'))
+}
+
+fn is_valid_deck_label(s: &str) -> bool {
+ let trimmed = s.trim();
+ !trimmed.is_empty() && s.len() <= deck::MAX_LABEL_BYTES && !s.chars().any(char::is_control)
+}
+
+fn sanitize_deck_label(s: &str) -> Option<String> {
+ let filtered: String = s.chars().filter(|c| !c.is_control()).collect();
+ let trimmed = filtered.trim();
+ if trimmed.is_empty() {
+ return None;
+ }
+ let mut end = trimmed.len().min(deck::MAX_LABEL_BYTES);
+ while end > 0 && !trimmed.is_char_boundary(end) {
+ end -= 1;
+ }
+ let out = trimmed[..end].trim().to_owned();
+ (!out.is_empty()).then_some(out)
+}
+
+/// One tile in a [`DeckPage`] (`docs/protocol/deck.md` §2.1).
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckTile {
+ pub id: String,
+ pub label: String,
+ pub icon: String,
+ pub color: String,
+ pub kind: String,
+}
+
+/// Never prints the user label (protocol v0 §11).
+impl std::fmt::Debug for DeckTile {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckTile")
+ .field("id", &self.id)
+ .field("icon", &self.icon)
+ .field("color", &self.color)
+ .field("kind", &self.kind)
+ .finish_non_exhaustive()
+ }
+}
+
+impl DeckTile {
+ pub fn is_valid(&self) -> bool {
+ is_valid_deck_id(&self.id)
+ && is_valid_deck_label(&self.label)
+ && deck_icons::ALL.contains(&self.icon.as_str())
+ && deck_colors::ALL.contains(&self.color.as_str())
+ && deck_kinds::ALL.contains(&self.kind.as_str())
+ }
+
+ pub fn sanitized(self) -> Option<Self> {
+ if !is_valid_deck_id(&self.id) || !deck_kinds::ALL.contains(&self.kind.as_str()) {
+ return None;
+ }
+ let label = sanitize_deck_label(&self.label)?;
+ let icon = if deck_icons::ALL.contains(&self.icon.as_str()) {
+ self.icon
+ } else {
+ deck_kinds::default_icon(&self.kind).into()
+ };
+ let color = if deck_colors::ALL.contains(&self.color.as_str()) {
+ self.color
+ } else {
+ deck_kinds::default_color(&self.kind).into()
+ };
+ Some(DeckTile { id: self.id, label, icon, color, kind: self.kind })
+ }
+}
+
+/// One page of tiles in [`DeckLayout`] (`docs/protocol/deck.md` §2.1).
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckPage {
+ pub id: String,
+ pub name: String,
+ #[serde(default)]
+ pub tiles: Vec<DeckTile>,
+}
+
+/// Never prints the page name (protocol v0 §11).
+impl std::fmt::Debug for DeckPage {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DeckPage")
+ .field("id", &self.id)
+ .field("tiles", &self.tiles.len())
+ .finish_non_exhaustive()
+ }
+}
+
+/// Body of `deck.layout`: pages and tiles configured on the PC (`docs/protocol/deck.md` §2.1).
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckLayout {
+ pub pages: Vec<DeckPage>,
+}
+
+impl DeckLayout {
+ pub fn is_valid(&self) -> bool {
+ if !(1..=deck::MAX_PAGES).contains(&self.pages.len()) {
+ return false;
+ }
+ let mut page_ids = std::collections::BTreeSet::new();
+ let mut tile_ids = std::collections::BTreeSet::new();
+ for page in &self.pages {
+ if !is_valid_deck_id(&page.id)
+ || !is_valid_deck_label(&page.name)
+ || page.tiles.len() > deck::MAX_TILES_PER_PAGE
+ || !page_ids.insert(page.id.as_str())
+ {
+ return false;
+ }
+ for tile in &page.tiles {
+ if !tile.is_valid() || !tile_ids.insert(tile.id.as_str()) {
+ return false;
+ }
+ }
+ }
+ true
+ }
+
+ pub fn sanitized(self) -> Option<Self> {
+ let mut page_ids = std::collections::BTreeSet::new();
+ let mut tile_ids = std::collections::BTreeSet::new();
+ let mut pages = Vec::new();
+ for page in self.pages {
+ if pages.len() >= deck::MAX_PAGES {
+ break;
+ }
+ if !is_valid_deck_id(&page.id) || !page_ids.insert(page.id.clone()) {
+ continue;
+ }
+ let Some(name) = sanitize_deck_label(&page.name) else {
+ continue;
+ };
+ let mut tiles = Vec::new();
+ for tile in page.tiles {
+ if tiles.len() >= deck::MAX_TILES_PER_PAGE {
+ break;
+ }
+ if let Some(clean) = tile.sanitized()
+ && tile_ids.insert(clean.id.clone())
+ {
+ tiles.push(clean);
+ }
+ }
+ pages.push(DeckPage { id: page.id, name, tiles });
+ }
+ (!pages.is_empty()).then_some(DeckLayout { pages })
+ }
+
+ /// Finds a tile by ID across all pages.
+ pub fn tile(&self, id: &str) -> Option<&DeckTile> {
+ self.pages.iter().flat_map(|p| p.tiles.iter()).find(|t| t.id == id)
+ }
+
+ /// The default single-page Deck layout (`docs/protocol/deck.md`).
+ pub fn default_layout() -> Self {
+ let tile = |id: &str, kind: &str| DeckTile {
+ id: id.into(),
+ label: deck_kinds::default_label(kind).into(),
+ icon: deck_kinds::default_icon(kind).into(),
+ color: deck_kinds::default_color(kind).into(),
+ kind: kind.into(),
+ };
+ DeckLayout {
+ pages: vec![DeckPage {
+ id: "main".into(),
+ name: "Main".into(),
+ tiles: vec![
+ tile("play_pause", deck_kinds::MEDIA_PLAY_PAUSE),
+ tile("prev_track", deck_kinds::MEDIA_PREVIOUS),
+ tile("next_track", deck_kinds::MEDIA_NEXT),
+ tile("vol_down", deck_kinds::VOLUME_DOWN),
+ tile("vol_up", deck_kinds::VOLUME_UP),
+ tile("vol_mute", deck_kinds::VOLUME_MUTE),
+ tile("mic_mute", deck_kinds::MIC_MUTE),
+ tile("show_desktop", deck_kinds::SHOW_DESKTOP),
+ tile("switch_window", deck_kinds::SWITCH_WINDOW),
+ tile("screenshot", deck_kinds::SCREENSHOT),
+ tile("lock_pc", deck_kinds::LOCK_PC),
+ ],
+ }],
+ }
+ }
+}
+
+impl Default for DeckLayout {
+ fn default() -> Self {
+ Self::default_layout()
+ }
+}
+
+/// Body of `deck.state`: live PC state reflected on Deck tiles (`docs/protocol/deck.md` §2.2).
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckState {
+ #[serde(default)]
+ pub playing: bool,
+ #[serde(default)]
+ pub volume: u8,
+ #[serde(default)]
+ pub muted: bool,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub mic_muted: Option<bool>,
+}
+
+impl DeckState {
+ pub fn is_valid(&self) -> bool {
+ self.volume <= 100
+ }
+
+ pub fn sanitized(mut self) -> Option<Self> {
+ self.volume = self.volume.min(100);
+ Some(self)
+ }
+
+ /// Short live status text for a tile of `kind`, if `kind` is a live tile.
+ pub fn tile_status(&self, kind: &str) -> Option<String> {
+ match kind {
+ deck_kinds::MEDIA_PLAY_PAUSE => {
+ Some(if self.playing { "Playing".into() } else { "Paused".into() })
+ }
+ deck_kinds::VOLUME_UP | deck_kinds::VOLUME_DOWN => Some(if self.muted {
+ format!("Muted · {}%", self.volume)
+ } else {
+ format!("{}%", self.volume)
+ }),
+ deck_kinds::VOLUME_MUTE => {
+ Some(if self.muted { "Muted".into() } else { format!("{}%", self.volume) })
+ }
+ deck_kinds::MIC_MUTE => match self.mic_muted {
+ Some(true) => Some("Muted".into()),
+ Some(false) => Some("Live".into()),
+ None => Some("No mic".into()),
+ },
+ _ => None,
+ }
+ }
+}
+
+/// Body of `deck.press`: asks the PC to run a tile's action (`docs/protocol/deck.md` §2.3).
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct DeckPress {
+ pub tile: String,
+}
+
+impl DeckPress {
+ pub fn is_valid(&self) -> bool {
+ is_valid_deck_id(&self.tile)
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -2779,4 +3219,74 @@ mod tests {
assert_eq!(messy.macs, vec!["38:a7:46:37:2e:64"]);
assert_eq!(messy.broadcasts, vec!["192.168.1.255"]);
}
+
+ #[test]
+ fn deck_layout_state_and_press_validate_sanitize_and_round_trip() {
+ let layout = DeckLayout::default_layout();
+ assert!(layout.is_valid());
+ assert_eq!(layout.pages.len(), 1);
+ assert!(layout.tile("play_pause").is_some());
+ assert!(layout.tile("mic_mute").is_some());
+ assert!(layout.tile("lock_pc").is_some());
+ assert!(layout.tile("screenshot").is_some());
+ assert!(layout.tile("show_desktop").is_some());
+
+ // Debug output hides user labels and page names.
+ let dbg = format!("{layout:?}");
+ assert!(!dbg.contains("Play / Pause") && !dbg.contains("Main"), "{dbg}");
+
+ let env = Envelope::new(types::DECK_LAYOUT, &layout).unwrap();
+ let back: DeckLayout = Envelope::from_cbor(&env.to_cbor()).unwrap().body().unwrap();
+ assert_eq!(back, layout);
+
+ // Duplicate tile IDs across pages are invalid and deduplicated by sanitized().
+ let dup_tile = layout.pages[0].tiles[0].clone();
+ let with_dup = DeckLayout {
+ pages: vec![
+ layout.pages[0].clone(),
+ DeckPage { id: "page2".into(), name: "Second".into(), tiles: vec![dup_tile] },
+ ],
+ };
+ assert!(!with_dup.is_valid());
+ let clean = with_dup.sanitized().unwrap();
+ assert!(clean.is_valid());
+ assert!(clean.pages[1].tiles.is_empty());
+
+ // Unknown icon/color fall back to the action kind's default in sanitized().
+ let fallback = DeckTile {
+ id: "cmd1".into(),
+ label: " Build\nnow ".into(),
+ icon: "unknown_icon".into(),
+ color: "unknown_color".into(),
+ kind: deck_kinds::RUN_COMMAND.into(),
+ }
+ .sanitized()
+ .unwrap();
+ assert_eq!(fallback.label, "Buildnow");
+ assert_eq!(fallback.icon, deck_icons::TERMINAL);
+ assert_eq!(fallback.color, deck_colors::CORAL);
+
+ // Empty pages list is rejected.
+ assert!(!DeckLayout { pages: vec![] }.is_valid());
+ assert_eq!(DeckLayout { pages: vec![] }.sanitized(), None);
+
+ // Live state round-trip and status formatting.
+ let state = DeckState { playing: true, volume: 72, muted: false, mic_muted: Some(true) };
+ assert!(state.is_valid());
+ assert_eq!(state.tile_status(deck_kinds::MEDIA_PLAY_PAUSE).as_deref(), Some("Playing"));
+ assert_eq!(state.tile_status(deck_kinds::VOLUME_UP).as_deref(), Some("72%"));
+ assert_eq!(state.tile_status(deck_kinds::MIC_MUTE).as_deref(), Some("Muted"));
+ assert_eq!(state.tile_status(deck_kinds::LOCK_PC), None);
+ let env = Envelope::new(types::DECK_STATE, &state).unwrap();
+ let back: DeckState = Envelope::from_cbor(&env.to_cbor()).unwrap().body().unwrap();
+ assert_eq!(back, state);
+
+ // Press validation.
+ let press = DeckPress { tile: "play_pause".into() };
+ assert!(press.is_valid());
+ let env = Envelope::new(types::DECK_PRESS, &press).unwrap();
+ assert_eq!(Envelope::from_cbor(&env.to_cbor()).unwrap().body::<DeckPress>().unwrap(), press);
+ assert!(!DeckPress { tile: String::new() }.is_valid());
+ assert!(!DeckPress { tile: "bad tile!".into() }.is_valid());
+ }
}
diff --git a/desktop/app/Cargo.toml b/desktop/app/Cargo.toml
index 77761ce..6dd1fb2 100644
--- a/desktop/app/Cargo.toml
+++ b/desktop/app/Cargo.toml
@@ -68,6 +68,7 @@ windows = { workspace = true, features = [
"Win32_System_Variant",
"Win32_Networking_WinSock",
"Win32_Media_Audio",
+ "Win32_Media_Audio_Endpoints",
"Win32_Media_MediaFoundation",
] }
diff --git a/desktop/app/build.rs b/desktop/app/build.rs
index b53c6e5..4b0b8ea 100644
--- a/desktop/app/build.rs
+++ b/desktop/app/build.rs
@@ -49,6 +49,7 @@ const QML: &[&str] = &[
"qml/components/TransferItem.qml",
"qml/components/Txt.qml",
"qml/pages/CallsPage.qml",
+ "qml/pages/DeckPage.qml",
"qml/pages/HomePage.qml",
"qml/pages/MessagesPage.qml",
"qml/pages/PairingPanel.qml",
diff --git a/desktop/app/qml/Icons.qml b/desktop/app/qml/Icons.qml
index 324996f..659cac9 100644
--- a/desktop/app/qml/Icons.qml
+++ b/desktop/app/qml/Icons.qml
@@ -67,4 +67,13 @@ QtObject {
readonly property string flashlight: "M8 3h8l-2 5v11a2 2 0 0 1-4 0V8zM8 5.5h8M12 11v2"
readonly property string bluetooth: "M6.5 6.5l11 11L12 22V2l5.5 5.5-11 11"
readonly property string brightness: "M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"
+ readonly property string window: "M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5zM3 9h18M7 6h.01M10 6h.01"
+ readonly property string camera: "M4 8a2 2 0 0 1 2-2h2.5l1.5-2h4l1.5 2H18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8zM12 10a3 3 0 1 0 0 6 3 3 0 0 0 0-6z"
+ readonly property string keyboard: "M4 6h16a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2zM6 10h.01M10 10h.01M14 10h.01M18 10h.01M8 14h8"
+ readonly property string globe: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM2 12h20M12 2a15 15 0 0 1 0 20M12 2a15 15 0 0 0 0 20"
+ readonly property string text: "M4 6V4h16v2M12 4v16M9 20h6"
+ readonly property string terminal: "M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6zM7 9l3 3-3 3M12 15h5"
+ readonly property string bolt: "M13 2L4 14h7l-1 8 9-12h-7l1-8z"
+ readonly property string trash: "M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3"
+ readonly property string edit: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"
}
diff --git a/desktop/app/qml/MainWindow.qml b/desktop/app/qml/MainWindow.qml
index 9f60140..175ddc7 100644
--- a/desktop/app/qml/MainWindow.qml
+++ b/desktop/app/qml/MainWindow.qml
@@ -128,6 +128,12 @@ NativeWindow {
selected: window.page === "photos"
onClicked: window.page = "photos"
}
+ NavItem {
+ iconPath: Icons.deck
+ text: qsTr("Deck")
+ selected: window.page === "deck"
+ onClicked: window.page = "deck"
+ }
NavItem {
iconPath: Icons.settings
text: qsTr("Settings")
@@ -168,6 +174,7 @@ NativeWindow {
: window.page === "messages" ? qsTr("Messages")
: window.page === "calls" ? qsTr("Calls")
: window.page === "photos" ? qsTr("Photos")
+ : window.page === "deck" ? qsTr("Deck")
: qsTr("Settings")
role: "headline"
size: 20
@@ -233,6 +240,10 @@ NativeWindow {
deviceId: homePage.currentDeviceId
deviceName: homePage.currentDeviceName
}
+ DeckPage {
+ anchors.fill: parent
+ active: window.page === "deck"
+ }
SettingsPage {
anchors.fill: parent
active: window.page === "settings"
diff --git a/desktop/app/qml/pages/DeckPage.qml b/desktop/app/qml/pages/DeckPage.qml
new file mode 100644
index 0000000..765ea8c
--- /dev/null
+++ b/desktop/app/qml/pages/DeckPage.qml
@@ -0,0 +1,1058 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+import QtQuick
+import QtQuick.Dialogs
+import app.nectarlink
+
+// Deck editor: configure pages of one-tap control tiles for paired phones,
+// preview live PC states (volume, mic mute, media), and test actions locally.
+Item {
+ id: page
+ property bool active: false
+
+ opacity: active ? 1 : 0
+ visible: opacity > 0
+ Behavior on opacity { NumberAnimation { duration: Theme.fadeNormal } }
+ transform: Translate {
+ y: page.active || Theme.reduceMotion ? 0 : 12
+ Behavior on y { SpringAnimation { spring: Theme.springGentle; damping: Theme.dampingGentle } }
+ }
+
+ readonly property var pagesList: {
+ try {
+ const parsed = JSON.parse(DeckController.pagesJson)
+ return Array.isArray(parsed) && parsed.length > 0 ? parsed : [{ id: "main", name: "Main", tiles: [] }]
+ } catch (e) {
+ return [{ id: "main", name: "Main", tiles: [] }]
+ }
+ }
+ property int currentPageIndex: 0
+ readonly property var currentPage: pagesList[Math.min(currentPageIndex, Math.max(0, pagesList.length - 1))] || { id: "main", name: "Main", tiles: [] }
+ readonly property var currentTiles: currentPage.tiles || []
+ property int draggedTileIndex: -1
+
+ onPagesListChanged: {
+ if (currentPageIndex >= pagesList.length)
+ currentPageIndex = Math.max(0, pagesList.length - 1)
+ }
+
+ function iconPathFor(name, kind) {
+ if (kind === "media_play_pause" && DeckController.playing)
+ return Icons.pause
+ if (kind === "mic_mute" && DeckController.micState === 1)
+ return Icons.micOff
+ if ((kind === "volume_mute" || kind === "volume_up" || kind === "volume_down") && DeckController.muted)
+ return Icons.soundOff
+ switch (name) {
+ case "play": return Icons.play
+ case "pause": return Icons.pause
+ case "skip_next":
+ case "next": return Icons.skipNext
+ case "skip_previous":
+ case "prev": return Icons.skipPrevious
+ case "volume_up": return Icons.volumeUp
+ case "volume_down": return Icons.volumeDown
+ case "volume_off":
+ case "volume_mute": return Icons.soundOff
+ case "mic": return Icons.mic
+ case "mic_off": return Icons.micOff
+ case "lock": return Icons.lock
+ case "desktop": return Icons.desktop
+ case "switch_window":
+ case "window": return Icons.window
+ case "screenshot":
+ case "camera": return Icons.camera
+ case "shortcut":
+ case "keyboard": return Icons.keyboard
+ case "globe": return Icons.globe
+ case "text": return Icons.text
+ case "app": return Icons.apps
+ case "terminal": return Icons.terminal
+ case "sparkle": return Icons.sparkle
+ case "bolt": return Icons.bolt
+ case "star": return Icons.star
+ case "music": return Icons.music
+ case "folder": return Icons.folder
+ case "video": return Icons.video
+ case "bell": return Icons.bell
+ default: return Icons.deck
+ }
+ }
+
+ // Curated tile color palette for Light and Dark modes (matches deck_colors::ALL).
+ function tilePalette(colorName) {
+ const dark = Theme.dark
+ const map = {
+ amber: dark ? { bg: "#3B2A14", fg: "#FFDDB3", accent: "#F5A623", border: "#6A4B24" }
+ : { bg: "#FFF0D6", fg: "#4A2E00", accent: "#C97A00", border: "#F0D199" },
+ coral: dark ? { bg: "#3E221D", fg: "#FFDAD3", accent: "#FF7E67", border: "#6E3D34" }
+ : { bg: "#FFE6E0", fg: "#521A10", accent: "#C84B31", border: "#F4BFB3" },
+ red: dark ? { bg: "#3D1F24", fg: "#FFD9DE", accent: "#F45B69", border: "#6D353E" }
+ : { bg: "#FFE4E8", fg: "#51121B", accent: "#C92A37", border: "#F2B6BE" },
+ teal: dark ? { bg: "#153230", fg: "#C4F3EE", accent: "#38CFC3", border: "#285B57" }
+ : { bg: "#DCF7F4", fg: "#083B37", accent: "#0D9488", border: "#A3E5DF" },
+ green: dark ? { bg: "#183324", fg: "#C9F5DA", accent: "#4ADE80", border: "#2C5C41" }
+ : { bg: "#E0F8EA", fg: "#0C3B22", accent: "#16A34A", border: "#A9E8C2" },
+ blue: dark ? { bg: "#172E3D", fg: "#CEE7FF", accent: "#56B4F9", border: "#2B536E" }
+ : { bg: "#E0F2FE", fg: "#0B324D", accent: "#0284C7", border: "#AEDBFA" },
+ violet: dark ? { bg: "#2E2340", fg: "#E9DDFF", accent: "#A985FF", border: "#523F73" }
+ : { bg: "#EFE7FF", fg: "#2E1557", accent: "#6B46C1", border: "#D3C0FA" },
+ slate: dark ? { bg: "#222934", fg: "#DCE4F0", accent: "#8FA3BF", border: "#3E4B5E" }
+ : { bg: "#EAEEF4", fg: "#1E293B", accent: "#475569", border: "#CBD5E1" }
+ }
+ return map[colorName] || map.amber
+ }
+
+ readonly property var colorChoices: [
+ { id: "amber", label: qsTr("Amber") },
+ { id: "coral", label: qsTr("Coral") },
+ { id: "red", label: qsTr("Red") },
+ { id: "teal", label: qsTr("Teal") },
+ { id: "green", label: qsTr("Green") },
+ { id: "blue", label: qsTr("Blue") },
+ { id: "violet", label: qsTr("Violet") },
+ { id: "slate", label: qsTr("Slate") }
+ ]
+
+ readonly property var iconChoices: [
+ "play", "pause", "skip_next", "skip_previous",
+ "volume_up", "volume_down", "volume_off", "mic",
+ "mic_off", "lock", "desktop", "switch_window",
+ "screenshot", "shortcut", "globe", "text",
+ "app", "terminal", "sparkle", "star"
+ ]
+
+ readonly property var actionChoices: [
+ { id: "media_play_pause", group: qsTr("Media"), label: qsTr("Play / Pause") },
+ { id: "media_previous", group: qsTr("Media"), label: qsTr("Previous track") },
+ { id: "media_next", group: qsTr("Media"), label: qsTr("Next track") },
+ { id: "volume_down", group: qsTr("Audio"), label: qsTr("Volume down") },
+ { id: "volume_up", group: qsTr("Audio"), label: qsTr("Volume up") },
+ { id: "volume_mute", group: qsTr("Audio"), label: qsTr("Mute speaker") },
+ { id: "mic_mute", group: qsTr("Audio"), label: qsTr("Mute microphone") },
+ { id: "show_desktop", group: qsTr("System"), label: qsTr("Show desktop (Win+D)") },
+ { id: "switch_window", group: qsTr("System"), label: qsTr("Switch window (Alt+Tab)") },
+ { id: "screenshot", group: qsTr("System"), label: qsTr("Screenshot (Win+Shift+S)") },
+ { id: "lock_pc", group: qsTr("System"), label: qsTr("Lock PC") },
+ { id: "shortcut", group: qsTr("Custom"), label: qsTr("Keyboard shortcut") },
+ { id: "open_url", group: qsTr("Custom"), label: qsTr("Open website") },
+ { id: "type_text", group: qsTr("Custom"), label: qsTr("Type text snippet") },
+ { id: "launch_app", group: qsTr("Apps"), label: qsTr("Launch application (.exe / .lnk)") },
+ { id: "run_command", group: qsTr("Apps"), label: qsTr("Run shell command") }
+ ]
+
+ function openAddTile() {
+ editorSheet.tileId = ""
+ editorSheet.actionKind = "shortcut"
+ editorSheet.tileLabel = DeckController.defaultLabelFor("shortcut")
+ editorSheet.labelCustomized = false
+ editorSheet.tileIcon = DeckController.defaultIconFor("shortcut")
+ editorSheet.tileColor = DeckController.defaultColorFor("shortcut")
+ editorSheet.paramValue = "c"
+ editorSheet.modCtrl = true
+ editorSheet.modAlt = false
+ editorSheet.modShift = false
+ editorSheet.modWin = false
+ editorSheet.errorText = ""
+ editorSheet.open()
+ }
+
+ function openEditTile(tile) {
+ editorSheet.tileId = tile.id
+ editorSheet.actionKind = tile.kind
+ editorSheet.tileLabel = tile.label
+ editorSheet.labelCustomized = true
+ editorSheet.tileIcon = tile.icon
+ editorSheet.tileColor = tile.color
+ editorSheet.paramValue = tile.param || ""
+ editorSheet.modCtrl = !!tile.ctrl
+ editorSheet.modAlt = !!tile.alt
+ editorSheet.modShift = !!tile.shift
+ editorSheet.modWin = !!tile.win
+ editorSheet.errorText = ""
+ editorSheet.open()
+ }
+
+ FileDialog {
+ id: appFilePicker
+ title: qsTr("Choose an application or shortcut")
+ nameFilters: [qsTr("Applications and shortcuts (*.exe *.lnk)")]
+ onAccepted: {
+ const localPath = DeckController.urlToLocalPath(selectedFile.toString())
+ if (localPath.length > 0) {
+ editorSheet.paramValue = localPath
+ if (!editorSheet.labelCustomized || editorSheet.tileLabel.length === 0 || editorSheet.tileLabel === qsTr("Launch App")) {
+ const parts = localPath.split(/[\\/]/)
+ const file = parts[parts.length - 1] || ""
+ const stem = file.replace(/\.(exe|lnk)$/i, "")
+ if (stem.length > 0)
+ editorSheet.tileLabel = stem
+ }
+ }
+ }
+ }
+
+ Flickable {
+ anchors.fill: parent
+ contentHeight: mainCol.height + Theme.contentPadding * 2
+ boundsBehavior: Flickable.StopAtBounds
+ clip: true
+
+ Column {
+ id: mainCol
+ width: Math.min(960, parent.width - Theme.contentPadding * 2)
+ x: Math.max(Theme.contentPadding, (parent.width - width) / 2)
+ y: Theme.contentPadding
+ spacing: Theme.gutter
+
+ // ---- Header & Live PC Status ----
+ Card {
+ width: parent.width
+ Column {
+ width: parent.width
+ spacing: 14
+
+ Row {
+ width: parent.width
+ spacing: 12
+ Column {
+ width: parent.width - headerActions.width - 12
+ spacing: 4
+ Txt { text: qsTr("Control Deck"); role: "title" }
+ Txt {
+ width: parent.width
+ wrapMode: Text.WordWrap
+ role: "bodySmall"
+ muted: true
+ text: qsTr("Big, one-tap buttons on your phone for media, volume, mic mute, window management, shortcuts, and apps. Drag tiles to reorder them or click any tile to customize it.")
+ }
+ }
+ Row {
+ id: headerActions
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 8
+ Button {
+ variant: "outline"
+ size: "sm"
+ iconPath: Icons.refresh
+ text: qsTr("Reset defaults")
+ onClicked: resetConfirmSheet.open()
+ }
+ Button {
+ variant: "fill"
+ size: "sm"
+ iconPath: Icons.plus
+ text: qsTr("Add tile")
+ onClicked: page.openAddTile()
+ }
+ }
+ }
+
+ Divider { width: parent.width }
+
+ // Live status pills showing what phones see right now
+ Flow {
+ width: parent.width
+ spacing: 10
+
+ Chip {
+ iconPath: DeckController.muted ? Icons.soundOff : Icons.speaker
+ selected: !DeckController.muted
+ text: DeckController.muted
+ ? qsTr("Speaker: Muted (%1%)").arg(DeckController.volume)
+ : qsTr("Speaker: %1%").arg(DeckController.volume)
+ }
+ Chip {
+ iconPath: DeckController.micState === 1 ? Icons.micOff : Icons.mic
+ selected: DeckController.micState === 0
+ text: DeckController.micState === 1 ? qsTr("Mic: Muted")
+ : DeckController.micState === 0 ? qsTr("Mic: Live")
+ : qsTr("Mic: None")
+ }
+ Chip {
+ iconPath: DeckController.playing ? Icons.play : Icons.pause
+ selected: DeckController.playing
+ text: DeckController.playing ? qsTr("Media: Playing") : qsTr("Media: Paused")
+ }
+ }
+ }
+ }
+
+ // ---- Page Tabs & Page Management ----
+ Item {
+ width: parent.width
+ height: 38
+
+ Row {
+ id: pageTabsRow
+ anchors.left: parent.left
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 8
+
+ Repeater {
+ model: page.pagesList
+ delegate: Chip {
+ required property var modelData
+ required property int index
+ selected: index === page.currentPageIndex
+ text: "%1 (%2)".arg(modelData.name).arg((modelData.tiles || []).length)
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: page.currentPageIndex = index }
+ }
+ }
+
+ Button {
+ visible: page.pagesList.length < 8
+ variant: "tonal"
+ size: "sm"
+ iconPath: Icons.plus
+ text: qsTr("New page")
+ onClicked: {
+ pageNameSheet.isNew = true
+ pageNameInput.text = qsTr("Page %1").arg(page.pagesList.length + 1)
+ pageNameSheet.open()
+ }
+ }
+ }
+
+ Row {
+ anchors.right: parent.right
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 8
+
+ Button {
+ variant: "text"
+ size: "sm"
+ iconPath: Icons.edit
+ text: qsTr("Rename page")
+ onClicked: {
+ pageNameSheet.isNew = false
+ pageNameInput.text = page.currentPage.name
+ pageNameSheet.open()
+ }
+ }
+ Button {
+ visible: page.pagesList.length > 1
+ variant: "text"
+ size: "sm"
+ iconPath: Icons.trash
+ text: qsTr("Delete page")
+ onClicked: DeckController.removePage(page.currentPage.id)
+ }
+ }
+ }
+
+ // ---- Tile Grid (Phone Preview & Interactive Editor) ----
+ Grid {
+ id: tileGrid
+ width: parent.width
+ columns: width >= 760 ? 4 : 3
+ spacing: 14
+
+ readonly property real cellWidth: (width - spacing * (columns - 1)) / columns
+
+ Repeater {
+ model: page.currentTiles
+ delegate: Item {
+ id: tileSlot
+ required property var modelData
+ required property int index
+
+ width: tileGrid.cellWidth
+ height: 118
+
+ readonly property var pal: page.tilePalette(modelData.color)
+ readonly property bool isBeingDragged: page.draggedTileIndex === index
+
+ Rectangle {
+ id: tileCard
+ anchors.fill: parent
+ radius: Theme.radiusMd
+ color: Theme.graphite ? Theme.surfaceContainer : tileSlot.pal.bg
+ border.width: isBeingDragged ? 2 : (Theme.graphite ? 1 : 1)
+ border.color: isBeingDragged ? Theme.primary
+ : Theme.graphite ? tileSlot.pal.accent : tileSlot.pal.border
+ scale: isBeingDragged ? 0.96 : (tileHover.hovered ? 1.01 : 1.0)
+ Behavior on scale { NumberAnimation { duration: Theme.fadeFast } }
+
+ // Left accent bar in Graphite so tile color is clear without heavy fill
+ Rectangle {
+ visible: Theme.graphite
+ width: 4
+ height: parent.height - 24
+ x: 8
+ anchors.verticalCenter: parent.verticalCenter
+ radius: 2
+ color: tileSlot.pal.accent
+ }
+
+ // Top row: Icon badge + live status pill + quick test button
+ Item {
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.top: parent.top
+ anchors.margins: 14
+ anchors.leftMargin: Theme.graphite ? 18 : 14
+ height: 34
+
+ Rectangle {
+ id: iconBadge
+ width: 34; height: 34
+ radius: Theme.radiusSm
+ color: Theme.graphite ? Theme.surfaceContainerHigh
+ : Qt.rgba(tileSlot.pal.accent.r, tileSlot.pal.accent.g, tileSlot.pal.accent.b, 0.18)
+ Icon {
+ anchors.centerIn: parent
+ width: 18; height: 18
+ path: page.iconPathFor(tileSlot.modelData.icon, tileSlot.modelData.kind)
+ color: Theme.graphite ? tileSlot.pal.accent : tileSlot.pal.fg
+ }
+ }
+
+ // Live status pill (e.g. "74%", "Muted", "Playing", "Live")
+ Rectangle {
+ visible: (tileSlot.modelData.status || "").length > 0
+ anchors.left: iconBadge.right
+ anchors.leftMargin: 8
+ anchors.verticalCenter: parent.verticalCenter
+ height: 22
+ width: statusLabel.implicitWidth + 14
+ radius: 11
+ color: Theme.graphite ? Theme.surfaceContainerHigh
+ : Qt.rgba(0, 0, 0, Theme.dark ? 0.28 : 0.08)
+ Txt {
+ id: statusLabel
+ anchors.centerIn: parent
+ text: tileSlot.modelData.status || ""
+ role: "mono"
+ size: 11
+ color: Theme.graphite ? Theme.surfaceContent : tileSlot.pal.fg
+ }
+ }
+
+ // Quick "Test" button in top-right corner
+ Rectangle {
+ id: testBtn
+ anchors.right: parent.right
+ anchors.verticalCenter: parent.verticalCenter
+ width: 28; height: 28
+ radius: 14
+ color: testHover.hovered
+ ? (Theme.graphite ? Theme.surfaceContainerHighest : Qt.rgba(0, 0, 0, Theme.dark ? 0.35 : 0.14))
+ : "transparent"
+ opacity: tileHover.hovered || testHover.hovered ? 1 : 0.65
+ Accessible.role: Accessible.Button
+ Accessible.name: qsTr("Test %1").arg(tileSlot.modelData.label)
+ Accessible.onPressAction: DeckController.testTile(tileSlot.modelData.id)
+
+ Icon {
+ anchors.centerIn: parent
+ width: 14; height: 14
+ path: Icons.bolt
+ color: Theme.graphite ? Theme.surfaceContentVariant : tileSlot.pal.fg
+ }
+ HoverHandler { id: testHover; cursorShape: Qt.PointingHandCursor }
+ TapHandler {
+ onTapped: DeckController.testTile(tileSlot.modelData.id)
+ }
+ }
+ }
+
+ // Bottom labels: Tile label + action subtitle
+ Column {
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ anchors.margins: 14
+ anchors.leftMargin: Theme.graphite ? 18 : 14
+ spacing: 2
+
+ Txt {
+ width: parent.width
+ text: tileSlot.modelData.label
+ role: "title"
+ size: 15
+ elide: Text.ElideRight
+ color: Theme.graphite ? Theme.surfaceContent : tileSlot.pal.fg
+ }
+ Txt {
+ width: parent.width
+ text: tileSlot.modelData.subtitle || ""
+ role: "bodySmall"
+ size: 11
+ elide: Text.ElideRight
+ color: Theme.graphite ? Theme.surfaceContentVariant : tileSlot.pal.fg
+ opacity: Theme.graphite ? 1.0 : 0.76
+ }
+ }
+
+ HoverHandler { id: tileHover; cursorShape: Qt.PointingHandCursor }
+
+ // Drag-to-reorder and click-to-edit
+ MouseArea {
+ anchors.fill: parent
+ anchors.rightMargin: 36 // Leave top-right test button clickable
+ acceptedButtons: Qt.LeftButton
+ pressAndHoldInterval: 180
+ property point pressPos: Qt.point(0, 0)
+ property bool dragging: false
+
+ onPressed: (mouse) => {
+ pressPos = Qt.point(mouse.x, mouse.y)
+ dragging = false
+ }
+ onPositionChanged: (mouse) => {
+ if (!pressed) return
+ const dx = mouse.x - pressPos.x
+ const dy = mouse.y - pressPos.y
+ if (!dragging && (dx * dx + dy * dy > 64)) {
+ dragging = true
+ page.draggedTileIndex = tileSlot.index
+ }
+ if (dragging) {
+ const inGrid = tileSlot.mapToItem(tileGrid, mouse.x, mouse.y)
+ const col = Math.floor(inGrid.x / (tileGrid.cellWidth + tileGrid.spacing))
+ const row = Math.floor(inGrid.y / (tileSlot.height + tileGrid.spacing))
+ if (col >= 0 && col < tileGrid.columns && row >= 0) {
+ const targetIdx = row * tileGrid.columns + col
+ if (targetIdx >= 0 && targetIdx < page.currentTiles.length && targetIdx !== tileSlot.index) {
+ DeckController.moveTile(page.currentPage.id, tileSlot.index, targetIdx)
+ page.draggedTileIndex = targetIdx
+ }
+ }
+ }
+ }
+ onReleased: {
+ if (!dragging) {
+ page.openEditTile(tileSlot.modelData)
+ }
+ dragging = false
+ page.draggedTileIndex = -1
+ }
+ onCanceled: {
+ dragging = false
+ page.draggedTileIndex = -1
+ }
+ }
+ }
+ }
+ }
+
+ // Add-tile card at the end of the grid
+ Rectangle {
+ visible: page.currentTiles.length < 24
+ width: tileGrid.cellWidth
+ height: 118
+ radius: Theme.radiusMd
+ color: addHover.hovered ? Theme.surfaceContainerHigh : "transparent"
+ border.width: 1
+ border.color: Theme.outlineVariant
+
+ Column {
+ anchors.centerIn: parent
+ spacing: 6
+ Icon {
+ anchors.horizontalCenter: parent.horizontalCenter
+ path: Icons.plus
+ color: Theme.surfaceContentVariant
+ }
+ Txt {
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: qsTr("Add tile")
+ role: "bodySmall"
+ muted: true
+ }
+ }
+ HoverHandler { id: addHover; cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: page.openAddTile() }
+ }
+ }
+ }
+ }
+
+ // ---- Add / Edit Tile Sheet ----
+ Sheet {
+ id: editorSheet
+ cardWidth: 680
+
+ property string tileId: ""
+ property string actionKind: "shortcut"
+ property string tileLabel: ""
+ property bool labelCustomized: false
+ property string tileIcon: "keyboard"
+ property string tileColor: "amber"
+ property string paramValue: ""
+ property bool modCtrl: false
+ property bool modAlt: false
+ property bool modShift: false
+ property bool modWin: false
+ property string errorText: ""
+
+ readonly property var previewPal: page.tilePalette(tileColor)
+
+ function selectKind(kind) {
+ actionKind = kind
+ if (!labelCustomized || tileLabel.trim().length === 0) {
+ tileLabel = DeckController.defaultLabelFor(kind)
+ }
+ tileIcon = DeckController.defaultIconFor(kind)
+ tileColor = DeckController.defaultColorFor(kind)
+ errorText = ""
+ if (kind === "shortcut" && paramValue.length === 0) {
+ paramValue = "c"
+ modCtrl = true
+ } else if (kind === "open_url" && paramValue.length === 0) {
+ paramValue = "https://"
+ }
+ }
+
+ Column {
+ width: parent.width
+ spacing: 10
+
+ // Sheet Header + Live Tile Preview
+ Row {
+ width: parent.width
+ spacing: 14
+
+ Column {
+ width: parent.width - previewBox.width - 14
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 4
+ Txt {
+ text: editorSheet.tileId.length === 0 ? qsTr("Add tile") : qsTr("Edit tile")
+ role: "headline"
+ }
+ Txt {
+ width: parent.width
+ wrapMode: Text.WordWrap
+ role: "bodySmall"
+ muted: true
+ text: qsTr("Phones only receive the tile's label, icon, color, and action kind. File paths and commands stay on this PC.")
+ }
+ }
+
+ // Live miniature tile preview
+ Rectangle {
+ id: previewBox
+ width: 148; height: 64
+ radius: Theme.radiusMd
+ color: Theme.graphite ? Theme.surfaceContainer : editorSheet.previewPal.bg
+ border.width: 1
+ border.color: Theme.graphite ? editorSheet.previewPal.accent : editorSheet.previewPal.border
+
+ Icon {
+ x: 12; y: 10
+ width: 16; height: 16
+ path: page.iconPathFor(editorSheet.tileIcon, editorSheet.actionKind)
+ color: Theme.graphite ? editorSheet.previewPal.accent : editorSheet.previewPal.fg
+ }
+ Txt {
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ anchors.margins: 10
+ text: editorSheet.tileLabel.length > 0 ? editorSheet.tileLabel : DeckController.defaultLabelFor(editorSheet.actionKind)
+ role: "title"
+ size: 13
+ elide: Text.ElideRight
+ color: Theme.graphite ? Theme.surfaceContent : editorSheet.previewPal.fg
+ }
+ }
+ }
+
+ Divider { width: parent.width }
+
+ // Action Picker
+ Column {
+ width: parent.width
+ spacing: 6
+ Txt { text: qsTr("Action"); role: "label"; muted: true }
+ Flow {
+ id: actionFlow
+ width: parent.width
+ spacing: 6
+
+ Repeater {
+ model: page.actionChoices
+ delegate: Chip {
+ required property var modelData
+ selected: editorSheet.actionKind === modelData.id
+ text: modelData.label
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.selectKind(modelData.id) }
+ }
+ }
+ }
+ }
+
+ // Parameter inputs for parameterized actions
+ Column {
+ width: parent.width
+ spacing: 6
+ visible: editorSheet.actionKind === "shortcut"
+ || editorSheet.actionKind === "open_url"
+ || editorSheet.actionKind === "type_text"
+ || editorSheet.actionKind === "launch_app"
+ || editorSheet.actionKind === "run_command"
+
+ // Modifiers for Shortcut
+ Row {
+ visible: editorSheet.actionKind === "shortcut"
+ spacing: 8
+ Chip {
+ selected: editorSheet.modCtrl
+ text: "Ctrl"
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.modCtrl = !editorSheet.modCtrl }
+ }
+ Chip {
+ selected: editorSheet.modAlt
+ text: "Alt"
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.modAlt = !editorSheet.modAlt }
+ }
+ Chip {
+ selected: editorSheet.modShift
+ text: "Shift"
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.modShift = !editorSheet.modShift }
+ }
+ Chip {
+ selected: editorSheet.modWin
+ text: "Win"
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.modWin = !editorSheet.modWin }
+ }
+ }
+
+ Txt {
+ role: "bodySmall"
+ muted: true
+ text: editorSheet.actionKind === "shortcut" ? qsTr("Key (e.g. c, v, z, f5, tab, enter, space, escape, up, down):")
+ : editorSheet.actionKind === "open_url" ? qsTr("Website address (https://…):")
+ : editorSheet.actionKind === "type_text" ? qsTr("Text snippet to type:")
+ : editorSheet.actionKind === "launch_app" ? qsTr("Application or shortcut path (.exe or .lnk):")
+ : qsTr("Shell command to run on this PC:")
+ }
+
+ Row {
+ width: parent.width
+ spacing: 8
+
+ Rectangle {
+ width: editorSheet.actionKind === "launch_app" ? parent.width - browseBtn.width - 8 : parent.width
+ height: 36
+ radius: Theme.radiusSm
+ color: Theme.surfaceContainerHigh
+ border.width: paramInput.activeFocus ? 2 : 1
+ border.color: paramInput.activeFocus ? Theme.primary : Theme.outlineVariant
+
+ TextInput {
+ id: paramInput
+ anchors.fill: parent
+ anchors.leftMargin: 12
+ anchors.rightMargin: 12
+ verticalAlignment: TextInput.AlignVCenter
+ clip: true
+ color: Theme.surfaceContent
+ selectionColor: Theme.primaryContainer
+ selectedTextColor: Theme.primaryContainerContent
+ font.family: editorSheet.actionKind === "run_command" || editorSheet.actionKind === "shortcut"
+ ? Theme.fontMono : Theme.fontUi
+ font.pixelSize: 13
+ text: editorSheet.paramValue
+ onTextEdited: editorSheet.paramValue = text
+ }
+ }
+
+ Button {
+ id: browseBtn
+ visible: editorSheet.actionKind === "launch_app"
+ variant: "tonal"
+ size: "sm"
+ iconPath: Icons.folder
+ text: qsTr("Browse…")
+ onClicked: appFilePicker.open()
+ }
+ }
+
+ Txt {
+ visible: editorSheet.actionKind === "run_command"
+ width: parent.width
+ wrapMode: Text.WordWrap
+ role: "bodySmall"
+ color: Theme.warning
+ text: qsTr("Requires \"Allow running Deck commands\" to be turned on for the phone in Settings → Devices.")
+ }
+ }
+
+ // Tile Label Input + Color Swatches side-by-side
+ Row {
+ width: parent.width
+ spacing: 16
+
+ Column {
+ width: parent.width - colorCol.width - 16
+ spacing: 6
+ Txt { text: qsTr("Label"); role: "label"; muted: true }
+ Rectangle {
+ width: parent.width
+ height: 36
+ radius: Theme.radiusSm
+ color: Theme.surfaceContainerHigh
+ border.width: labelInput.activeFocus ? 2 : 1
+ border.color: labelInput.activeFocus ? Theme.primary : Theme.outlineVariant
+
+ TextInput {
+ id: labelInput
+ anchors.fill: parent
+ anchors.leftMargin: 12
+ anchors.rightMargin: 12
+ verticalAlignment: TextInput.AlignVCenter
+ clip: true
+ color: Theme.surfaceContent
+ selectionColor: Theme.primaryContainer
+ selectedTextColor: Theme.primaryContainerContent
+ font.family: Theme.fontUi
+ font.pixelSize: 14
+ text: editorSheet.tileLabel
+ onTextEdited: {
+ editorSheet.tileLabel = text
+ editorSheet.labelCustomized = true
+ }
+ }
+ }
+ }
+
+ Column {
+ id: colorCol
+ spacing: 6
+ Txt { text: qsTr("Color"); role: "label"; muted: true }
+ Row {
+ height: 36
+ spacing: 8
+ Repeater {
+ model: page.colorChoices
+ delegate: Rectangle {
+ required property var modelData
+ readonly property var pal: page.tilePalette(modelData.id)
+ readonly property bool chosen: editorSheet.tileColor === modelData.id
+ anchors.verticalCenter: parent.verticalCenter
+ width: 26; height: 26; radius: 13
+ color: pal.accent
+ border.width: chosen ? 3 : 1
+ border.color: chosen ? Theme.surfaceContent : pal.border
+ Accessible.role: Accessible.RadioButton
+ Accessible.name: modelData.label
+ Accessible.checked: chosen
+ Accessible.onPressAction: editorSheet.tileColor = modelData.id
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.tileColor = modelData.id }
+ }
+ }
+ }
+ }
+ }
+
+ // Icon Picker
+ Column {
+ width: parent.width
+ spacing: 6
+ Txt { text: qsTr("Icon"); role: "label"; muted: true }
+ Flow {
+ width: parent.width
+ spacing: 5
+ Repeater {
+ model: page.iconChoices
+ delegate: Rectangle {
+ required property string modelData
+ readonly property bool chosen: editorSheet.tileIcon === modelData
+ width: 27; height: 27
+ radius: Theme.radiusSm
+ color: chosen ? Theme.secondaryContainer : Theme.surfaceContainerHigh
+ border.width: chosen ? 2 : 0
+ border.color: Theme.primary
+ Icon {
+ anchors.centerIn: parent
+ width: 15; height: 15
+ path: page.iconPathFor(modelData, "")
+ color: chosen ? Theme.secondaryContainerContent : Theme.surfaceContent
+ }
+ HoverHandler { cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: editorSheet.tileIcon = modelData }
+ }
+ }
+ }
+ }
+
+ Txt {
+ visible: editorSheet.errorText.length > 0
+ width: parent.width
+ wrapMode: Text.WordWrap
+ role: "bodySmall"
+ color: Theme.error
+ text: editorSheet.errorText
+ }
+
+ // Sheet Actions
+ Item {
+ width: parent.width
+ height: 38
+
+ Row {
+ anchors.left: parent.left
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 8
+ visible: editorSheet.tileId.length > 0
+
+ Button {
+ variant: "outline"
+ size: "sm"
+ iconPath: Icons.trash
+ text: qsTr("Delete")
+ onClicked: {
+ DeckController.removeTile(page.currentPage.id, editorSheet.tileId)
+ editorSheet.close()
+ }
+ }
+ Button {
+ variant: "tonal"
+ size: "sm"
+ iconPath: Icons.bolt
+ text: qsTr("Test")
+ onClicked: DeckController.testTile(editorSheet.tileId)
+ }
+ }
+
+ Row {
+ anchors.right: parent.right
+ anchors.verticalCenter: parent.verticalCenter
+ spacing: 8
+
+ Button {
+ variant: "text"
+ text: qsTr("Cancel")
+ onClicked: editorSheet.close()
+ }
+ Button {
+ variant: "fill"
+ text: qsTr("Save")
+ onClicked: {
+ const err = DeckController.saveTile(
+ page.currentPage.id,
+ editorSheet.tileId,
+ editorSheet.tileLabel,
+ editorSheet.tileIcon,
+ editorSheet.tileColor,
+ editorSheet.actionKind,
+ editorSheet.paramValue,
+ editorSheet.modCtrl,
+ editorSheet.modAlt,
+ editorSheet.modShift,
+ editorSheet.modWin
+ )
+ if (err.length > 0) {
+ editorSheet.errorText = err
+ } else {
+ editorSheet.close()
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // ---- Add / Rename Page Sheet ----
+ Sheet {
+ id: pageNameSheet
+ property bool isNew: true
+ cardWidth: 380
+
+ Column {
+ width: parent.width
+ spacing: 14
+
+ Txt {
+ text: pageNameSheet.isNew ? qsTr("New page") : qsTr("Rename page")
+ role: "headline"
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 38
+ radius: Theme.radiusSm
+ color: Theme.surfaceContainerHigh
+ border.width: pageNameInput.activeFocus ? 2 : 1
+ border.color: pageNameInput.activeFocus ? Theme.primary : Theme.outlineVariant
+
+ TextInput {
+ id: pageNameInput
+ anchors.fill: parent
+ anchors.leftMargin: 12
+ anchors.rightMargin: 12
+ verticalAlignment: TextInput.AlignVCenter
+ clip: true
+ color: Theme.surfaceContent
+ selectionColor: Theme.primaryContainer
+ selectedTextColor: Theme.primaryContainerContent
+ font.family: Theme.fontUi
+ font.pixelSize: 14
+ }
+ }
+
+ Row {
+ anchors.right: parent.right
+ spacing: 8
+ Button { variant: "text"; text: qsTr("Cancel"); onClicked: pageNameSheet.close() }
+ Button {
+ variant: "fill"
+ text: pageNameSheet.isNew ? qsTr("Create") : qsTr("Save")
+ onClicked: {
+ const trimmed = pageNameInput.text.trim()
+ if (trimmed.length === 0) return
+ if (pageNameSheet.isNew) {
+ DeckController.addPage(trimmed)
+ page.currentPageIndex = page.pagesList.length - 1
+ } else {
+ DeckController.renamePage(page.currentPage.id, trimmed)
+ }
+ pageNameSheet.close()
+ }
+ }
+ }
+ }
+ }
+
+ // ---- Reset Confirmation Sheet ----
+ Sheet {
+ id: resetConfirmSheet
+ cardWidth: 400
+ Column {
+ width: parent.width
+ spacing: 14
+ Txt { text: qsTr("Reset Deck to defaults?"); role: "headline" }
+ Txt {
+ width: parent.width
+ wrapMode: Text.WordWrap
+ role: "body"
+ muted: true
+ text: qsTr("This replaces your custom pages and tiles with the default 11-tile Deck.")
+ }
+ Row {
+ anchors.right: parent.right
+ spacing: 8
+ Button { variant: "text"; text: qsTr("Cancel"); onClicked: resetConfirmSheet.close() }
+ Button {
+ variant: "fill"
+ text: qsTr("Reset")
+ onClicked: {
+ DeckController.resetDefault()
+ page.currentPageIndex = 0
+ resetConfirmSheet.close()
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/desktop/app/qml/pages/SettingsPage.qml b/desktop/app/qml/pages/SettingsPage.qml
index b687158..7d85ae9 100644
--- a/desktop/app/qml/pages/SettingsPage.qml
+++ b/desktop/app/qml/pages/SettingsPage.qml
@@ -30,10 +30,15 @@ Item {
photos: qsTr("Photos"),
toggles: qsTr("Phone controls"),
pc_actions: qsTr("Lock, sleep and wake this PC"),
- remote_input: qsTr("Control this PC's mouse and keyboard"),
+ remote_input: qsTr("Control this PC's mouse, keyboard and Deck"),
+ commands: qsTr("Allow running Deck commands"),
remote_files: qsTr("Browse this PC's files while away")
})
+ readonly property var toggleDescriptions: ({
+ commands: qsTr("Lets this phone trigger Deck tiles that run shell commands configured on this PC. Off by default — only enable for a phone you control.")
+ })
+
FolderDialog {
id: recordingsFolderPicker
title: qsTr("Save recordings in")
@@ -454,6 +459,7 @@ Item {
required property var modelData
width: parent.width
title: page.toggleNames[modelData.name] || modelData.name
+ description: page.toggleDescriptions[modelData.name] || ""
Toggle {
label: page.toggleNames[modelData.name] || modelData.name
checked: modelData.on
diff --git a/desktop/app/src/bridge/deck.rs b/desktop/app/src/bridge/deck.rs
new file mode 100644
index 0000000..7528cc3
--- /dev/null
+++ b/desktop/app/src/bridge/deck.rs
@@ -0,0 +1,249 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+//! `DeckController`: QML bridge for the PC-owned Deck editor and live preview.
+
+#![allow(clippy::too_many_arguments)]
+
+use std::pin::Pin;
+
+use cxx_qt::Threading;
+use cxx_qt_lib::{QString, QUrl};
+use nectarlink_core::{DeckAction, KeyMod, deck_kinds};
+use serde::Serialize;
+
+use super::prefs::qobject;
+use crate::{bridge::app::show_message, deck, state::Changes};
+
+#[derive(Default)]
+pub struct DeckControllerRust {
+ pub(super) pages_json: QString,
+ pub(super) volume: i32,
+ pub(super) muted: bool,
+ pub(super) mic_state: i32,
+ pub(super) playing: bool,
+}
+
+#[derive(Serialize)]
+struct UiTile {
+ id: String,
+ label: String,
+ icon: String,
+ color: String,
+ kind: String,
+ param: String,
+ ctrl: bool,
+ alt: bool,
+ shift: bool,
+ win: bool,
+ status: String,
+ subtitle: String,
+}
+
+#[derive(Serialize)]
+struct UiPage {
+ id: String,
+ name: String,
+ tiles: Vec<UiTile>,
+}
+
+fn action_fields(action: &DeckAction) -> (String, bool, bool, bool, bool, String) {
+ match action {
+ DeckAction::MediaPlayPause => (String::new(), false, false, false, false, "Play / Pause".into()),
+ DeckAction::MediaNext => (String::new(), false, false, false, false, "Next track".into()),
+ DeckAction::MediaPrevious => (String::new(), false, false, false, false, "Previous track".into()),
+ DeckAction::VolumeUp => (String::new(), false, false, false, false, "Volume +2%".into()),
+ DeckAction::VolumeDown => (String::new(), false, false, false, false, "Volume -2%".into()),
+ DeckAction::VolumeMute => (String::new(), false, false, false, false, "Toggle speaker mute".into()),
+ DeckAction::MicMute => (String::new(), false, false, false, false, "Toggle mic mute".into()),
+ DeckAction::LockPc => (String::new(), false, false, false, false, "Lock workstation".into()),
+ DeckAction::ShowDesktop => (String::new(), false, false, false, false, "Win + D".into()),
+ DeckAction::SwitchWindow => (String::new(), false, false, false, false, "Alt + Tab".into()),
+ DeckAction::Screenshot => (String::new(), false, false, false, false, "Win + Shift + S".into()),
+ DeckAction::Shortcut { key, mods } => {
+ let ctrl = mods.contains(&KeyMod::Ctrl);
+ let alt = mods.contains(&KeyMod::Alt);
+ let shift = mods.contains(&KeyMod::Shift);
+ let win = mods.contains(&KeyMod::Win);
+ let mut parts = Vec::new();
+ if ctrl {
+ parts.push("Ctrl".to_owned());
+ }
+ if alt {
+ parts.push("Alt".to_owned());
+ }
+ if shift {
+ parts.push("Shift".to_owned());
+ }
+ if win {
+ parts.push("Win".to_owned());
+ }
+ parts.push(key.to_ascii_uppercase());
+ (key.clone(), ctrl, alt, shift, win, parts.join(" + "))
+ }
+ DeckAction::OpenUrl { url } => (url.clone(), false, false, false, false, url.clone()),
+ DeckAction::TypeText { text } => {
+ let preview: String = text.chars().take(28).collect();
+ (text.clone(), false, false, false, false, format!("\"{preview}\""))
+ }
+ DeckAction::LaunchApp { path } => {
+ let file_name =
+ std::path::Path::new(path).file_name().and_then(|s| s.to_str()).unwrap_or(path).to_owned();
+ (path.clone(), false, false, false, false, file_name)
+ }
+ DeckAction::RunCommand { command } => {
+ let preview: String = command.chars().take(28).collect();
+ (command.clone(), false, false, false, false, format!("cmd · {preview}"))
+ }
+ }
+}
+
+impl cxx_qt::Initialize for qobject::DeckController {
+ fn initialize(mut self: Pin<&mut Self>) {
+ self.as_mut().refresh();
+ super::subscribe(self.qt_thread(), Changes::DECK, Self::refresh);
+ }
+}
+
+impl qobject::DeckController {
+ fn refresh(mut self: Pin<&mut Self>) {
+ let cfg = deck::config();
+ let st = deck::state();
+ let ui_pages: Vec<UiPage> = cfg
+ .pages
+ .iter()
+ .map(|p| UiPage {
+ id: p.id.clone(),
+ name: p.name.clone(),
+ tiles: p
+ .tiles
+ .iter()
+ .map(|t| {
+ let kind = t.action.kind().to_owned();
+ let (param, ctrl, alt, shift, win, subtitle) = action_fields(&t.action);
+ let status = st.tile_status(&kind).unwrap_or_default();
+ UiTile {
+ id: t.id.clone(),
+ label: t.label.clone(),
+ icon: t.icon.clone(),
+ color: t.color.clone(),
+ kind,
+ param,
+ ctrl,
+ alt,
+ shift,
+ win,
+ status,
+ subtitle,
+ }
+ })
+ .collect(),
+ })
+ .collect();
+ let json = serde_json::to_string(&ui_pages).unwrap_or_else(|_| "[]".into());
+ self.as_mut().set_pages_json(QString::from(&json));
+ self.as_mut().set_volume(i32::from(st.volume));
+ self.as_mut().set_muted(st.muted);
+ self.as_mut().set_mic_state(match st.mic_muted {
+ None => -1,
+ Some(false) => 0,
+ Some(true) => 1,
+ });
+ self.as_mut().set_playing(st.playing);
+ }
+
+ pub fn default_label_for(&self, kind: &QString) -> QString {
+ QString::from(deck_kinds::default_label(&String::from(kind)))
+ }
+
+ pub fn default_icon_for(&self, kind: &QString) -> QString {
+ QString::from(deck_kinds::default_icon(&String::from(kind)))
+ }
+
+ pub fn default_color_for(&self, kind: &QString) -> QString {
+ QString::from(deck_kinds::default_color(&String::from(kind)))
+ }
+
+ pub fn add_page(self: Pin<&mut Self>, name: &QString) -> QString {
+ let id = deck::add_page(&String::from(name));
+ self.refresh();
+ QString::from(&id)
+ }
+
+ pub fn rename_page(self: Pin<&mut Self>, page_id: &QString, name: &QString) {
+ deck::rename_page(&String::from(page_id), &String::from(name));
+ self.refresh();
+ }
+
+ pub fn remove_page(self: Pin<&mut Self>, page_id: &QString) {
+ deck::remove_page(&String::from(page_id));
+ self.refresh();
+ }
+
+ pub fn reset_default(self: Pin<&mut Self>) {
+ deck::reset_default();
+ self.refresh();
+ }
+
+ pub fn move_tile(self: Pin<&mut Self>, page_id: &QString, from_index: i32, to_index: i32) {
+ if let (Ok(from), Ok(to)) = (usize::try_from(from_index), usize::try_from(to_index)) {
+ deck::move_tile(&String::from(page_id), from, to);
+ self.refresh();
+ }
+ }
+
+ pub fn remove_tile(self: Pin<&mut Self>, page_id: &QString, tile_id: &QString) {
+ deck::remove_tile(&String::from(page_id), &String::from(tile_id));
+ self.refresh();
+ }
+
+ #[allow(clippy::too_many_arguments)]
+ pub fn save_tile(
+ self: Pin<&mut Self>,
+ page_id: &QString,
+ tile_id: &QString,
+ label: &QString,
+ icon: &QString,
+ color: &QString,
+ kind: &QString,
+ param: &QString,
+ ctrl: bool,
+ alt: bool,
+ shift: bool,
+ win_mod: bool,
+ ) -> QString {
+ let action =
+ match deck::build_action(&String::from(kind), &String::from(param), ctrl, alt, shift, win_mod) {
+ Ok(a) => a,
+ Err(e) => return QString::from(&e),
+ };
+ match deck::save_tile(
+ &String::from(page_id),
+ &String::from(tile_id),
+ &String::from(label),
+ &String::from(icon),
+ &String::from(color),
+ action,
+ ) {
+ Ok(_) => {
+ self.refresh();
+ QString::from("")
+ }
+ Err(e) => QString::from(&e),
+ }
+ }
+
+ pub fn test_tile(self: Pin<&mut Self>, tile_id: &QString) {
+ let id = String::from(tile_id);
+ if let Err(e) = deck::execute_tile(&id) {
+ show_message(e);
+ }
+ }
+
+ pub fn url_to_local_path(&self, url: &QString) -> QString {
+ let raw = QUrl::from(url)
+ .to_local_file()
+ .map(|p| String::from(&p))
+ .filter(|s| !s.is_empty())
+ .unwrap_or_else(|| String::from(url));
+ QString::from(raw.trim())
+ }
+}
diff --git a/desktop/app/src/bridge/mod.rs b/desktop/app/src/bridge/mod.rs
index fd3cfbd..b3fbef3 100644
--- a/desktop/app/src/bridge/mod.rs
+++ b/desktop/app/src/bridge/mod.rs
@@ -10,6 +10,8 @@ pub mod app;
#[allow(unsafe_code)]
pub mod calls;
#[allow(unsafe_code)]
+pub mod deck;
+#[allow(unsafe_code)]
pub mod devices;
#[allow(unsafe_code)]
pub mod history;
diff --git a/desktop/app/src/bridge/prefs.rs b/desktop/app/src/bridge/prefs.rs
index e86409a..1c2be15 100644
--- a/desktop/app/src/bridge/prefs.rs
+++ b/desktop/app/src/bridge/prefs.rs
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
-//! `Preferences`: the app's look and behavior, saved whenever it changes.
+//! `Preferences` and `DeckController`: the app's look, behavior and PC-owned Deck.
+
+#![allow(clippy::too_many_arguments)]
use std::{
path::PathBuf,
@@ -18,6 +20,8 @@ use crate::{
settings::{ColorMode, RecordingFormat, Settings, Theme},
};
+pub use super::deck::DeckControllerRust;
+
#[cxx_qt::bridge]
pub mod qobject {
unsafe extern "C++" {
@@ -64,9 +68,60 @@ pub mod qobject {
/// Resets the recordings folder to `Documents\Nectarlink Recordings`.
#[qinvokable]
fn reset_recordings_folder(self: Pin<&mut Preferences>);
+
+ #[qobject]
+ #[qml_element]
+ #[qml_singleton]
+ #[qproperty(QString, pages_json)]
+ #[qproperty(i32, volume)]
+ #[qproperty(bool, muted)]
+ /// `-1`: no mic, `0`: live, `1`: muted.
+ #[qproperty(i32, mic_state)]
+ #[qproperty(bool, playing)]
+ type DeckController = super::DeckControllerRust;
+
+ #[qinvokable]
+ fn default_label_for(self: &DeckController, kind: &QString) -> QString;
+ #[qinvokable]
+ fn default_icon_for(self: &DeckController, kind: &QString) -> QString;
+ #[qinvokable]
+ fn default_color_for(self: &DeckController, kind: &QString) -> QString;
+ #[qinvokable]
+ fn add_page(self: Pin<&mut DeckController>, name: &QString) -> QString;
+ #[qinvokable]
+ fn rename_page(self: Pin<&mut DeckController>, page_id: &QString, name: &QString);
+ #[qinvokable]
+ fn remove_page(self: Pin<&mut DeckController>, page_id: &QString);
+ #[qinvokable]
+ fn reset_default(self: Pin<&mut DeckController>);
+ #[qinvokable]
+ fn move_tile(self: Pin<&mut DeckController>, page_id: &QString, from_index: i32, to_index: i32);
+ #[qinvokable]
+ fn remove_tile(self: Pin<&mut DeckController>, page_id: &QString, tile_id: &QString);
+ #[qinvokable]
+ fn save_tile(
+ self: Pin<&mut DeckController>,
+ page_id: &QString,
+ tile_id: &QString,
+ label: &QString,
+ icon: &QString,
+ color: &QString,
+ kind: &QString,
+ param: &QString,
+ ctrl: bool,
+ alt: bool,
+ shift: bool,
+ win_mod: bool,
+ ) -> QString;
+ #[qinvokable]
+ fn test_tile(self: Pin<&mut DeckController>, tile_id: &QString);
+ #[qinvokable]
+ fn url_to_local_path(self: &DeckController, url: &QString) -> QString;
}
impl cxx_qt::Initialize for Preferences {}
+ impl cxx_qt::Threading for DeckController {}
+ impl cxx_qt::Initialize for DeckController {}
}
#[derive(Default)]
diff --git a/desktop/app/src/core_host.rs b/desktop/app/src/core_host.rs
index 1f9d7ec..51f4483 100644
--- a/desktop/app/src/core_host.rs
+++ b/desktop/app/src/core_host.rs
@@ -107,6 +107,7 @@ async fn run(data_dir: PathBuf, platform: Arc<dyn Platform>) {
nectarlink_core::MIRROR_VIEW.into(),
nectarlink_core::MIRROR_LISTEN.into(),
nectarlink_core::INPUT_INJECT.into(),
+ nectarlink_core::DECK_ACTIONS.into(),
nectarlink_core::RECORDER.into(),
nectarlink_core::TOGGLES_SHOW.into(),
];
diff --git a/desktop/app/src/deck.rs b/desktop/app/src/deck.rs
new file mode 100644
index 0000000..1e2c31b
--- /dev/null
+++ b/desktop/app/src/deck.rs
@@ -0,0 +1,519 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+//! PC-owned Deck configuration, live state syncing, and action execution
+//! (`docs/protocol/deck.md`).
+
+use std::{
+ path::{Path, PathBuf},
+ sync::{
+ Mutex, MutexGuard,
+ atomic::{AtomicBool, Ordering},
+ },
+ time::{Duration, SystemTime},
+};
+
+use nectarlink_core::{
+ DeckAction, DeckConfig, DeckPageConfig, DeckState, DeckTileConfig, DeviceId, KeyMod, deck_colors,
+ deck_icons, deck_kinds,
+};
+
+use crate::{core_host, links, state::Changes, win};
+
+const FILE_NAME: &str = "deck.json";
+
+struct RuntimeState {
+ config: DeckConfig,
+ state: DeckState,
+ path: Option<PathBuf>,
+ last_mtime: Option<SystemTime>,
+}
+
+static DECK: Mutex<Option<RuntimeState>> = Mutex::new(None);
+static MEDIA_PLAYING: AtomicBool = AtomicBool::new(false);
+static HAS_MEDIA_SESSION: AtomicBool = AtomicBool::new(false);
+
+fn lock<T>(m: &Mutex<T>) -> MutexGuard<'_, T> {
+ m.lock().unwrap_or_else(|e| e.into_inner())
+}
+
+fn file_mtime(path: &Path) -> Option<SystemTime> {
+ std::fs::metadata(path).and_then(|m| m.modified()).ok()
+}
+
+fn sample_live_state() -> DeckState {
+ let (volume, muted) = win::audio::speaker_state().unwrap_or((50, false));
+ let mic_muted = win::audio::mic_muted();
+ let playing = MEDIA_PLAYING.load(Ordering::Relaxed);
+ DeckState { volume, muted, mic_muted, playing }
+}
+
+/// Loads `deck.json` from `data_dir` and starts the background poller that
+/// keeps speaker volume, microphone mute, and external `deck.json` edits in sync.
+pub fn init(data_dir: &Path) {
+ let path = data_dir.join(FILE_NAME);
+ if !path.exists() {
+ let default = DeckConfig::default_deck();
+ let _ = default.save(&path);
+ }
+ let config = DeckConfig::load(&path);
+ let mtime = file_mtime(&path);
+ let initial_state = sample_live_state();
+ let wire_layout = config.to_wire_layout();
+ {
+ let mut guard = lock(&DECK);
+ *guard =
+ Some(RuntimeState { config, state: initial_state.clone(), path: Some(path), last_mtime: mtime });
+ }
+ core_host::host().hub.update(|_| Changes::DECK);
+
+ core_host::spawn(async move {
+ if let Some(node) = core_host::wait_for_node().await {
+ let _ = node.set_deck_layout(wire_layout).await;
+ let _ = node.set_deck_state(initial_state).await;
+ }
+ let mut interval = tokio::time::interval(Duration::from_millis(1200));
+ loop {
+ interval.tick().await;
+ reload_from_disk_if_modified();
+ refresh_live_state().await;
+ }
+ });
+}
+
+fn reload_from_disk_if_modified() {
+ let updated_wire = {
+ let mut guard = lock(&DECK);
+ let Some(rt) = guard.as_mut() else { return };
+ let Some(path) = rt.path.as_ref() else { return };
+ let mtime = file_mtime(path);
+ if mtime.is_none() || mtime == rt.last_mtime {
+ return;
+ }
+ rt.last_mtime = mtime;
+ let fresh = DeckConfig::load(path);
+ if fresh == rt.config {
+ return;
+ }
+ rt.config = fresh;
+ Some(rt.config.to_wire_layout())
+ };
+ if let Some(wire) = updated_wire {
+ core_host::host().hub.update(|_| Changes::DECK);
+ core_host::spawn(async move {
+ if let Some(node) = core_host::node() {
+ let _ = node.set_deck_layout(wire).await;
+ }
+ });
+ }
+}
+
+/// Re-reads the PC's speaker and mic states and broadcasts `deck.state` if changed.
+pub async fn refresh_live_state() {
+ let next = sample_live_state();
+ let changed = {
+ let mut guard = lock(&DECK);
+ match guard.as_mut() {
+ Some(rt) if rt.state != next => {
+ rt.state = next.clone();
+ true
+ }
+ _ => false,
+ }
+ };
+ if changed {
+ core_host::host().hub.update(|_| Changes::DECK);
+ if let Some(node) = core_host::node() {
+ let _ = node.set_deck_state(next).await;
+ }
+ }
+}
+
+/// Called by `crate::media::local_changed` when the PC's SMTC media sessions change.
+pub fn on_local_media_changed(players: &[nectarlink_core::MediaPlayer]) {
+ HAS_MEDIA_SESSION.store(!players.is_empty(), Ordering::Relaxed);
+ let playing = players.iter().any(|p| p.playing);
+ MEDIA_PLAYING.store(playing, Ordering::Relaxed);
+ core_host::spawn(async {
+ refresh_live_state().await;
+ });
+}
+
+/// Returns the current [`DeckConfig`].
+pub fn config() -> DeckConfig {
+ lock(&DECK).as_ref().map(|rt| rt.config.clone()).unwrap_or_else(DeckConfig::default_deck)
+}
+
+/// Returns the current [`DeckState`].
+pub fn state() -> DeckState {
+ lock(&DECK).as_ref().map(|rt| rt.state.clone()).unwrap_or_else(sample_live_state)
+}
+
+fn commit_config(mutate: impl FnOnce(&mut DeckConfig)) {
+ let wire = {
+ let mut guard = lock(&DECK);
+ let rt = guard.get_or_insert_with(|| RuntimeState {
+ config: DeckConfig::default_deck(),
+ state: sample_live_state(),
+ path: Some(core_host::host().data_dir.join(FILE_NAME)),
+ last_mtime: None,
+ });
+ mutate(&mut rt.config);
+ if let Some(clean) = rt.config.clone().sanitized() {
+ rt.config = clean;
+ }
+ if let Some(path) = &rt.path {
+ if let Err(e) = rt.config.save(path) {
+ tracing::warn!(error = %e, "failed to save deck.json");
+ }
+ rt.last_mtime = file_mtime(path);
+ }
+ rt.config.to_wire_layout()
+ };
+ core_host::host().hub.update(|_| Changes::DECK);
+ core_host::spawn(async move {
+ if let Some(node) = core_host::node() {
+ let _ = node.set_deck_layout(wire).await;
+ }
+ });
+}
+
+/// Called when a paired phone presses a Deck tile (`Platform::deck_press`).
+pub fn handle_press(_peer: &DeviceId, tile_id: &str) -> Result<(), String> {
+ execute_tile(tile_id)
+}
+
+/// Executes a tile's action by ID (used both for remote `deck.press` and the
+/// desktop Deck editor's "Test" button).
+pub fn execute_tile(tile_id: &str) -> Result<(), String> {
+ let action = {
+ let guard = lock(&DECK);
+ let rt = guard.as_ref().ok_or_else(|| "deck not initialized".to_owned())?;
+ rt.config
+ .tile(tile_id)
+ .map(|t| t.action.clone())
+ .ok_or_else(|| format!("unknown tile {tile_id:?}"))?
+ };
+ let res = execute_action(&action);
+ core_host::spawn(async {
+ refresh_live_state().await;
+ });
+ res
+}
+
+fn execute_action(action: &DeckAction) -> Result<(), String> {
+ match action {
+ DeckAction::MediaPlayPause => {
+ win::input::press_key("play_pause", &[]);
+ if !HAS_MEDIA_SESSION.load(Ordering::Relaxed) {
+ let prev = MEDIA_PLAYING.load(Ordering::Relaxed);
+ MEDIA_PLAYING.store(!prev, Ordering::Relaxed);
+ }
+ Ok(())
+ }
+ DeckAction::MediaNext => {
+ win::input::press_key("next_track", &[]);
+ Ok(())
+ }
+ DeckAction::MediaPrevious => {
+ win::input::press_key("prev_track", &[]);
+ Ok(())
+ }
+ DeckAction::VolumeUp => win::audio::speaker_volume_up().map(|_| ()),
+ DeckAction::VolumeDown => win::audio::speaker_volume_down().map(|_| ()),
+ DeckAction::VolumeMute => win::audio::toggle_speaker_mute().map(|_| ()),
+ DeckAction::MicMute => win::audio::toggle_mic_mute().map(|_| ()),
+ DeckAction::LockPc => win::shell::lock(),
+ DeckAction::ShowDesktop => {
+ win::input::press_key("d", &[KeyMod::Win]);
+ Ok(())
+ }
+ DeckAction::SwitchWindow => {
+ win::input::press_key("tab", &[KeyMod::Alt]);
+ Ok(())
+ }
+ DeckAction::Screenshot => {
+ win::input::press_key("s", &[KeyMod::Win, KeyMod::Shift]);
+ Ok(())
+ }
+ DeckAction::Shortcut { key, mods } => {
+ win::input::press_key(key, mods);
+ Ok(())
+ }
+ DeckAction::OpenUrl { url } => links::open_here(url),
+ DeckAction::TypeText { text } => {
+ win::input::type_text(text);
+ Ok(())
+ }
+ DeckAction::LaunchApp { path } => win::shell::launch_app(Path::new(path)),
+ DeckAction::RunCommand { command } => win::shell::run_command(command),
+ }
+}
+
+fn next_unique_id(prefix: &str, existing: &[String]) -> String {
+ for n in 1..=999 {
+ let candidate = format!("{prefix}_{n}");
+ if !existing.contains(&candidate) {
+ return candidate;
+ }
+ }
+ format!("{prefix}_x")
+}
+
+/// Adds a new page and returns its ID.
+pub fn add_page(name: &str) -> String {
+ let trimmed = name.trim();
+ let page_name = if trimmed.is_empty() { "New Page" } else { trimmed };
+ let mut created_id = String::new();
+ commit_config(|cfg| {
+ if cfg.pages.len() >= nectarlink_core::MAX_DECK_PAGES {
+ return;
+ }
+ let ids: Vec<String> = cfg.pages.iter().map(|p| p.id.clone()).collect();
+ let id = next_unique_id("page", &ids);
+ created_id = id.clone();
+ cfg.pages.push(DeckPageConfig { id, name: page_name.to_owned(), tiles: Vec::new() });
+ });
+ created_id
+}
+
+/// Renames an existing page.
+pub fn rename_page(page_id: &str, name: &str) {
+ let trimmed = name.trim();
+ if trimmed.is_empty() {
+ return;
+ }
+ commit_config(|cfg| {
+ if let Some(page) = cfg.pages.iter_mut().find(|p| p.id == page_id) {
+ page.name = trimmed.to_owned();
+ }
+ });
+}
+
+/// Removes a page (unless it is the last remaining page).
+pub fn remove_page(page_id: &str) {
+ commit_config(|cfg| {
+ if cfg.pages.len() <= 1 {
+ return;
+ }
+ cfg.pages.retain(|p| p.id != page_id);
+ });
+}
+
+/// Resets the Deck to the default layout.
+pub fn reset_default() {
+ commit_config(|cfg| {
+ *cfg = DeckConfig::default_deck();
+ });
+}
+
+/// Moves a tile within `page_id` from `from_index` to `to_index`.
+pub fn move_tile(page_id: &str, from_index: usize, to_index: usize) {
+ commit_config(|cfg| {
+ let Some(page) = cfg.pages.iter_mut().find(|p| p.id == page_id) else { return };
+ if from_index >= page.tiles.len() || to_index >= page.tiles.len() || from_index == to_index {
+ return;
+ }
+ let tile = page.tiles.remove(from_index);
+ page.tiles.insert(to_index, tile);
+ });
+}
+
+/// Removes a tile by ID from `page_id`.
+pub fn remove_tile(page_id: &str, tile_id: &str) {
+ commit_config(|cfg| {
+ if let Some(page) = cfg.pages.iter_mut().find(|p| p.id == page_id) {
+ page.tiles.retain(|t| t.id != tile_id);
+ }
+ });
+}
+
+/// Builds a [`DeckAction`] from editor fields.
+pub fn build_action(
+ kind: &str,
+ param: &str,
+ ctrl: bool,
+ alt: bool,
+ shift: bool,
+ win_mod: bool,
+) -> Result<DeckAction, String> {
+ let p = param.trim();
+ let action = match kind {
+ deck_kinds::MEDIA_PLAY_PAUSE => DeckAction::MediaPlayPause,
+ deck_kinds::MEDIA_NEXT => DeckAction::MediaNext,
+ deck_kinds::MEDIA_PREVIOUS => DeckAction::MediaPrevious,
+ deck_kinds::VOLUME_UP => DeckAction::VolumeUp,
+ deck_kinds::VOLUME_DOWN => DeckAction::VolumeDown,
+ deck_kinds::VOLUME_MUTE => DeckAction::VolumeMute,
+ deck_kinds::MIC_MUTE => DeckAction::MicMute,
+ deck_kinds::LOCK_PC => DeckAction::LockPc,
+ deck_kinds::SHOW_DESKTOP => DeckAction::ShowDesktop,
+ deck_kinds::SWITCH_WINDOW => DeckAction::SwitchWindow,
+ deck_kinds::SCREENSHOT => DeckAction::Screenshot,
+ deck_kinds::SHORTCUT => {
+ let key = p.to_ascii_lowercase();
+ if key.is_empty() {
+ return Err("Choose a key for the shortcut.".into());
+ }
+ let mut mods = Vec::new();
+ if ctrl {
+ mods.push(KeyMod::Ctrl);
+ }
+ if alt {
+ mods.push(KeyMod::Alt);
+ }
+ if shift {
+ mods.push(KeyMod::Shift);
+ }
+ if win_mod {
+ mods.push(KeyMod::Win);
+ }
+ DeckAction::Shortcut { key, mods }
+ }
+ deck_kinds::OPEN_URL => {
+ if p.is_empty() {
+ return Err("Enter an http:// or https:// web address.".into());
+ }
+ let url = if p.starts_with("http://") || p.starts_with("https://") {
+ p.to_owned()
+ } else {
+ format!("https://{p}")
+ };
+ DeckAction::OpenUrl { url }
+ }
+ deck_kinds::TYPE_TEXT => {
+ if param.is_empty() {
+ return Err("Enter the text snippet to type.".into());
+ }
+ DeckAction::TypeText { text: param.to_owned() }
+ }
+ deck_kinds::LAUNCH_APP => {
+ let unquoted = p.trim_matches('"');
+ if unquoted.is_empty() {
+ return Err("Choose an application (.exe or .lnk) on this PC.".into());
+ }
+ DeckAction::LaunchApp { path: unquoted.to_owned() }
+ }
+ deck_kinds::RUN_COMMAND => {
+ if p.is_empty() {
+ return Err("Enter a command to run on this PC.".into());
+ }
+ DeckAction::RunCommand { command: p.to_owned() }
+ }
+ _ => return Err(format!("Unknown action type {kind:?}.")),
+ };
+ if !action.is_valid() {
+ return Err(match kind {
+ deck_kinds::LAUNCH_APP => "Application path must end with .exe or .lnk.".into(),
+ deck_kinds::OPEN_URL => "Web address must start with http:// or https://.".into(),
+ deck_kinds::SHORTCUT => {
+ "Use a single key (a-z, 0-9, f1-f12, enter, tab, space, escape, arrows, etc.).".into()
+ }
+ _ => "Invalid action configuration.".into(),
+ });
+ }
+ Ok(action)
+}
+
+/// Adds or updates a tile on `page_id`. If `tile_id` is empty, creates a new tile.
+pub fn save_tile(
+ page_id: &str,
+ tile_id: &str,
+ label: &str,
+ icon: &str,
+ color: &str,
+ action: DeckAction,
+) -> Result<String, String> {
+ let kind = action.kind();
+ let final_label = if label.trim().is_empty() {
+ deck_kinds::default_label(kind).to_owned()
+ } else {
+ label.trim().to_owned()
+ };
+ let final_icon = if deck_icons::ALL.contains(&icon) {
+ icon.to_owned()
+ } else {
+ deck_kinds::default_icon(kind).to_owned()
+ };
+ let final_color = if deck_colors::ALL.contains(&color) {
+ color.to_owned()
+ } else {
+ deck_kinds::default_color(kind).to_owned()
+ };
+
+ let mut saved_id = String::new();
+ let mut err: Option<String> = None;
+ commit_config(|cfg| {
+ let all_ids: Vec<String> =
+ cfg.pages.iter().flat_map(|p| p.tiles.iter().map(|t| t.id.clone())).collect();
+ let Some(page) = cfg.pages.iter_mut().find(|p| p.id == page_id) else {
+ err = Some("Page not found.".into());
+ return;
+ };
+ if tile_id.is_empty() {
+ if page.tiles.len() >= nectarlink_core::MAX_DECK_TILES_PER_PAGE {
+ err = Some("This page already has the maximum number of tiles (24).".into());
+ return;
+ }
+ let new_id = next_unique_id("tile", &all_ids);
+ let tile = DeckTileConfig {
+ id: new_id.clone(),
+ label: final_label.clone(),
+ icon: final_icon.clone(),
+ color: final_color.clone(),
+ action: action.clone(),
+ };
+ if let Some(clean) = tile.sanitized() {
+ saved_id = clean.id.clone();
+ page.tiles.push(clean);
+ } else {
+ err = Some("Invalid tile properties.".into());
+ }
+ } else if let Some(existing) = page.tiles.iter_mut().find(|t| t.id == tile_id) {
+ let updated = DeckTileConfig {
+ id: existing.id.clone(),
+ label: final_label.clone(),
+ icon: final_icon.clone(),
+ color: final_color.clone(),
+ action: action.clone(),
+ };
+ if let Some(clean) = updated.sanitized() {
+ saved_id = clean.id.clone();
+ *existing = clean;
+ } else {
+ err = Some("Invalid tile properties.".into());
+ }
+ } else {
+ err = Some("Tile not found.".into());
+ }
+ });
+ if let Some(e) = err { Err(e) } else { Ok(saved_id) }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn builds_and_validates_editor_actions() {
+ let sc = build_action("shortcut", "K", true, false, true, false).unwrap();
+ assert_eq!(sc, DeckAction::Shortcut { key: "k".into(), mods: vec![KeyMod::Ctrl, KeyMod::Shift] });
+ assert!(build_action("shortcut", "not_a_key", true, false, false, false).is_err());
+
+ let url = build_action("open_url", "example.com/docs", false, false, false, false).unwrap();
+ assert_eq!(url, DeckAction::OpenUrl { url: "https://example.com/docs".into() });
+
+ let app =
+ build_action("launch_app", "\"C:\\Windows\\System32\\calc.exe\"", false, false, false, false)
+ .unwrap();
+ assert_eq!(app, DeckAction::LaunchApp { path: "C:\\Windows\\System32\\calc.exe".into() });
+ assert!(build_action("launch_app", "C:\\script.bat", false, false, false, false).is_err());
+
+ let cmd = build_action("run_command", " echo hello ", false, false, false, false).unwrap();
+ assert_eq!(cmd, DeckAction::RunCommand { command: "echo hello".into() });
+ }
+
+ #[test]
+ fn unique_ids_skip_existing_ones() {
+ let existing = vec!["tile_1".to_owned(), "tile_2".to_owned()];
+ assert_eq!(next_unique_id("tile", &existing), "tile_3");
+ }
+}
diff --git a/desktop/app/src/main.rs b/desktop/app/src/main.rs
index f822f82..8c76c03 100644
--- a/desktop/app/src/main.rs
+++ b/desktop/app/src/main.rs
@@ -13,6 +13,7 @@ mod bridge;
mod calls;
mod clipboard;
mod core_host;
+mod deck;
mod doctor;
mod icons;
mod launch;
@@ -104,6 +105,9 @@ impl Platform for DesktopPlatform {
remote::handle_input(peer, input);
Ok(())
}
+ fn deck_press(&self, peer: &nectarlink_core::DeviceId, tile: &str) -> Result<(), String> {
+ deck::handle_press(peer, tile)
+ }
}
/// Command-line options (also used by shortcuts and autostart).
@@ -254,6 +258,7 @@ fn main() -> ExitCode {
clipboard::start();
win::smtc::start(media::on_flyout);
win::media_sessions::start(media::local_changed);
+ deck::init(&data_dir);
let settings = settings::Settings::load(&data_dir);
recordings::init(&settings);
send_to::set_enabled(settings.send_to_menu);
diff --git a/desktop/app/src/media.rs b/desktop/app/src/media.rs
index 08d9292..c2ce4aa 100644
--- a/desktop/app/src/media.rs
+++ b/desktop/app/src/media.rs
@@ -148,6 +148,7 @@ pub fn on_event(event: &NodeEvent) {
/// What plays on this PC changed: tell the phones.
pub fn local_changed(players: Vec<nectarlink_core::MediaPlayer>) {
+ crate::deck::on_local_media_changed(&players);
core_host::spawn(async move {
if let Some(node) = core_host::wait_for_node().await {
node.media_changed(players).await;
diff --git a/desktop/app/src/state.rs b/desktop/app/src/state.rs
index 461a4a8..182e1fb 100644
--- a/desktop/app/src/state.rs
+++ b/desktop/app/src/state.rs
@@ -49,6 +49,8 @@ impl Changes {
pub const REMOTE: Changes = Changes(1 << 16);
/// A phone's quick settings toggles.
pub const TOGGLES: Changes = Changes(1 << 17);
+ /// This PC's Deck layout or live state (kept by crate::deck).
+ pub const DECK: Changes = Changes(1 << 18);
pub fn is_empty(self) -> bool {
self.0 == 0
@@ -435,7 +437,9 @@ impl AppState {
| NodeEvent::ContactsChanged { .. }
| NodeEvent::SmsChanged { .. }
| NodeEvent::Mirroring { .. }
- | NodeEvent::WakeInfoChanged { .. } => Changes::NONE,
+ | NodeEvent::WakeInfoChanged { .. }
+ | NodeEvent::DeckLayout { .. }
+ | NodeEvent::DeckState { .. } => Changes::NONE,
// The gallery's own downloads (for its viewer, or the clipboard)
// aren't files the user keeps.
NodeEvent::Transfer(transfer) if crate::photos::is_private(&transfer.id) => {
diff --git a/desktop/app/src/win/audio.rs b/desktop/app/src/win/audio.rs
new file mode 100644
index 0000000..883e491
--- /dev/null
+++ b/desktop/app/src/win/audio.rs
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+//! Speaker volume and microphone mute control and state via Windows Core Audio
+//! (`IMMDeviceEnumerator` + `IAudioEndpointVolume`).
+
+use windows::Win32::{
+ Media::Audio::{
+ EDataFlow, Endpoints::IAudioEndpointVolume, IMMDeviceEnumerator, MMDeviceEnumerator, eCapture,
+ eConsole, eRender,
+ },
+ System::Com::{CLSCTX_ALL, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx, CoUninitialize},
+};
+
+struct ComGuard(bool);
+
+impl ComGuard {
+ fn new() -> Self {
+ // SAFETY: Initializes COM on the current thread if not already initialized.
+ let hr = unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) };
+ Self(hr.is_ok())
+ }
+}
+
+impl Drop for ComGuard {
+ fn drop(&mut self) {
+ if self.0 {
+ // SAFETY: Matches a successful `CoInitializeEx` on this thread.
+ unsafe { CoUninitialize() };
+ }
+ }
+}
+
+fn endpoint_volume(flow: EDataFlow) -> windows::core::Result<IAudioEndpointVolume> {
+ // SAFETY: Standard Core Audio COM activation on the default console endpoint.
+ unsafe {
+ let enumerator: IMMDeviceEnumerator = CoCreateInstance(&MMDeviceEnumerator, None, CLSCTX_ALL)?;
+ let device = enumerator.GetDefaultAudioEndpoint(flow, eConsole)?;
+ device.Activate::<IAudioEndpointVolume>(CLSCTX_ALL, None)
+ }
+}
+
+/// Reads the default speaker endpoint's `(volume_percent, muted)`.
+pub fn speaker_state() -> Option<(u8, bool)> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eRender).ok()?;
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe {
+ let scalar = ep.GetMasterVolumeLevelScalar().ok()?;
+ let muted = ep.GetMute().ok()?.as_bool();
+ let pct = (scalar * 100.0).round().clamp(0.0, 100.0) as u8;
+ Some((pct, muted))
+ }
+}
+
+/// Steps the default speaker volume up by one increment (2%) and unmutes if muted.
+pub fn speaker_volume_up() -> Result<(u8, bool), String> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eRender).map_err(|e| format!("no speaker device: {e}"))?;
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe {
+ ep.VolumeStepUp(std::ptr::null()).map_err(|e| e.to_string())?;
+ if ep.GetMute().map(|b| b.as_bool()).unwrap_or(false) {
+ let _ = ep.SetMute(false, std::ptr::null());
+ }
+ let scalar = ep.GetMasterVolumeLevelScalar().unwrap_or(0.0);
+ let muted = ep.GetMute().map(|b| b.as_bool()).unwrap_or(false);
+ Ok(((scalar * 100.0).round().clamp(0.0, 100.0) as u8, muted))
+ }
+}
+
+/// Steps the default speaker volume down by one increment (2%).
+pub fn speaker_volume_down() -> Result<(u8, bool), String> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eRender).map_err(|e| format!("no speaker device: {e}"))?;
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe {
+ ep.VolumeStepDown(std::ptr::null()).map_err(|e| e.to_string())?;
+ let scalar = ep.GetMasterVolumeLevelScalar().unwrap_or(0.0);
+ let muted = ep.GetMute().map(|b| b.as_bool()).unwrap_or(false);
+ Ok(((scalar * 100.0).round().clamp(0.0, 100.0) as u8, muted))
+ }
+}
+
+/// Toggles mute on the default speaker endpoint and returns the new muted state.
+pub fn toggle_speaker_mute() -> Result<bool, String> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eRender).map_err(|e| format!("no speaker device: {e}"))?;
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe {
+ let cur = ep.GetMute().map_err(|e| e.to_string())?.as_bool();
+ let next = !cur;
+ ep.SetMute(next, std::ptr::null()).map_err(|e| e.to_string())?;
+ Ok(next)
+ }
+}
+
+/// Reads whether the default capture (microphone) endpoint is muted, or `None`
+/// if this PC has no default capture endpoint.
+pub fn mic_muted() -> Option<bool> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eCapture).ok()?;
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe { Some(ep.GetMute().ok()?.as_bool()) }
+}
+
+/// Toggles mute on the default capture (microphone) endpoint and returns the
+/// new muted state.
+pub fn toggle_mic_mute() -> Result<bool, String> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eCapture).map_err(|e| format!("no microphone found: {e}"))?;
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe {
+ let cur = ep.GetMute().map_err(|e| e.to_string())?.as_bool();
+ let next = !cur;
+ ep.SetMute(next, std::ptr::null()).map_err(|e| e.to_string())?;
+ Ok(next)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn reads_speaker_and_mic_state_without_mutating() {
+ if let Some((vol, _muted)) = speaker_state() {
+ assert!(vol <= 100);
+ }
+ let _ = mic_muted();
+ }
+}
diff --git a/desktop/app/src/win/mod.rs b/desktop/app/src/win/mod.rs
index 57c540b..590ff3e 100644
--- a/desktop/app/src/win/mod.rs
+++ b/desktop/app/src/win/mod.rs
@@ -5,6 +5,7 @@
#![allow(unsafe_code)]
+pub mod audio;
pub mod audio_out;
pub mod autostart;
pub mod clipboard;
diff --git a/desktop/app/src/win/shell.rs b/desktop/app/src/win/shell.rs
index 4d59961..0b8baf3 100644
--- a/desktop/app/src/win/shell.rs
+++ b/desktop/app/src/win/shell.rs
@@ -50,3 +50,45 @@ pub fn sleep() -> Result<(), String> {
Err("SetSuspendState failed".into())
}
}
+
+/// Launches a `.exe` or `.lnk` file on the PC via `ShellExecuteW` with no
+/// command-line arguments (`lpParameters = None`).
+pub fn launch_app(path: &std::path::Path) -> Result<(), String> {
+ let ext = path.extension().and_then(|e| e.to_str()).map(str::to_ascii_lowercase).unwrap_or_default();
+ if ext != "exe" && ext != "lnk" {
+ return Err("only .exe and .lnk files can be launched".into());
+ }
+ let file = HSTRING::from(path.as_os_str());
+ let dir = path.parent().map(|p| HSTRING::from(p.as_os_str()));
+ // SAFETY: plain ShellExecuteW with `lpParameters = None` so no arguments are passed.
+ let result = unsafe {
+ match &dir {
+ Some(d) => ShellExecuteW(None, w!("open"), &file, None, d, SW_SHOWNORMAL),
+ None => ShellExecuteW(None, w!("open"), &file, None, None, SW_SHOWNORMAL),
+ }
+ };
+ if result.0 as isize > 32 { Ok(()) } else { Err(format!("ShellExecute returned {}", result.0 as isize)) }
+}
+
+/// Runs a PC-configured shell command (`cmd.exe /C <command>`) without flashing
+/// a console window.
+pub fn run_command(command: &str) -> Result<(), String> {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+ let trimmed = command.trim();
+ if trimmed.is_empty() {
+ return Err("empty command".into());
+ }
+ // Exactly as typed: Rust's usual argument quoting is for programs that
+ // parse their command line like C programs do, which cmd.exe doesn't.
+ std::process::Command::new("cmd.exe")
+ .raw_arg("/C ")
+ .raw_arg(trimmed)
+ .creation_flags(CREATE_NO_WINDOW)
+ .stdin(std::process::Stdio::null())
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .spawn()
+ .map(|_| ())
+ .map_err(|e| format!("failed to run command: {e}"))
+}
diff --git a/docs/PLAN.md b/docs/PLAN.md
index 8f2d98e..54cf2d1 100644
--- a/docs/PLAN.md
+++ b/docs/PLAN.md
@@ -203,10 +203,10 @@ current Android. Talking through the PC comes with the HFP item above.
| **Air mouse**: point the phone and its gyroscope moves the PC cursor, for presentations and couch use ✅ | P1 🟢 |
| **Voice typing into PC**: hold a button on the phone, speak, and the text (from the phone's own speech engine) is typed into the PC's focused field ✅ | P1 🟢 |
| Type on the phone with the PC keyboard (without mirroring) | P1 🟣 |
-| **Deck**: the phone becomes a Stream-Deck-style macro pad for the PC with live tiles: mic mute, media, app launchers, scripts, OBS scenes, window switching, multiple pages, haptic feedback | P1 🟢 |
+| **Deck**: the phone becomes a Stream-Deck-style macro pad for the PC with live tiles: mic mute, media, app launchers, scripts, OBS scenes, window switching, multiple pages, haptic feedback ✅ | P1 🟢 |
| **Flow**: move the PC mouse off the screen edge onto the phone/tablet and back, with clipboard following | P2 🟣 |
| Phone toggles from PC: Wi-Fi, BT, DND, ringer, flashlight, volume, brightness ✅ (the hotspot has no shell command to switch it; see Instant Hotspot) | P1 (partly 🟣) |
-| PC actions from phone: lock, sleep, shutdown, mute, custom commands/scripts | P0 (lock/sleep), P1 (custom, off by default) |
+| PC actions from phone: lock, sleep, shutdown, mute, custom commands/scripts ✅ | P0 (lock/sleep), P1 (custom, off by default) |
| Wake-on-LAN ✅ | P1 |
| **Unlock PC with phone fingerprint**: the PC lock screen offers "Unlock with phone" → the phone shows a biometric prompt → a signed challenge unlocks Windows. Built as a Windows credential provider. Keys live in Android Keystore (StrongBox where available) and are bound to biometrics. Works only when paired and nearby (BLE proximity + LAN). Rate-limited, revocable, and **external security review before release** | P2 (dedicated workstream) |
diff --git a/docs/architecture/capabilities.md b/docs/architecture/capabilities.md
index c2f1137..5ee3c63 100644
--- a/docs/architecture/capabilities.md
+++ b/docs/architecture/capabilities.md
@@ -122,7 +122,7 @@ the OS (`android` → phone, `windows`/`macos` → desktop).
`notifications`, `messages`, `calls`, `contacts`, `clipboard`, `files`,
`media`, `photos`, `recordings`, `toggles`, `pc_actions`, `mirroring` (on by
-default) and `remote_input`, `remote_files` (off by default). Toggles are this
+default) and `remote_input`, `commands`, `remote_files` (off by default). Toggles are this
device's policy for that peer and are stored locally, so a feature the PC
user switched off is Locked on the PC while the phone may still show it as
Available. Everything else in the matrix is identical on both devices.
diff --git a/docs/protocol/capabilities.md b/docs/protocol/capabilities.md
index e27eaf9..4c64d96 100644
--- a/docs/protocol/capabilities.md
+++ b/docs/protocol/capabilities.md
@@ -77,5 +77,5 @@ capability is missing.
| `files.browse` | Lets a paired phone browse and fetch its files | app update |
| `input.inject` | Accepts pointer, keyboard and presentation input ([remote input](remote.md)) | app update |
| `recorder` | Saves and converts voice recordings from a phone ([recorder](recorder.md)) | app update |
-| `deck.actions` | Runs Deck actions | app update |
+| `deck.actions` | Shares its Deck layout and live tile state and runs Deck actions ([deck](deck.md)) | app update |
| `addon.vcam` | The virtual camera add-on is installed | installing the add-on |
diff --git a/docs/protocol/deck.md b/docs/protocol/deck.md
new file mode 100644
index 0000000..03fb192
--- /dev/null
+++ b/docs/protocol/deck.md
@@ -0,0 +1,107 @@
+# Deck service (protocol v0)
+
+> Status: **draft.** Builds on [protocol v0](v0.md); breaking changes are
+> allowed until v1. License: CC BY 4.0.
+
+The phone acts as a macro pad for a paired PC, showing pages of large tiles
+that trigger PC actions and reflect live PC state (playing/paused media,
+speaker volume and mute, microphone mute).
+
+The PC owns the Deck layout and action definitions: the phone receives only
+page and tile display metadata (`id`, `label`, `icon`, `color`, `kind`) and
+triggers actions by sending `deck.press { tile }` with the tile ID. The phone
+never sends commands, file paths, or URLs.
+
+## 1. Capability and permissions
+
+| ID | Offered by | Meaning |
+|---|---|---|
+| `deck.actions` | desktop | Shares its Deck layout (`deck.layout`) and live state (`deck.state`) and accepts `deck.press` requests (`input.deck`) |
+
+- **Per-device toggles on the PC:**
+ - `remote_input` (**off by default**): required for all `deck.press` requests. When a paired phone presses a tile (or calls `remote.check`) while `remote_input` is off, the PC refuses with `DENIED` and emits a one-time consent prompt (`RemoteInputRequested`) for that phone.
+ - `commands` (**off by default**): additionally required for tiles whose `kind` is `"run_command"`. Even when `remote_input` is on, pressing a `"run_command"` tile while `commands` is off for that phone is refused with `DENIED`.
+
+## 2. Messages
+
+All on the control stream.
+
+```
+t = "deck.layout" b = DeckLayout // PC → phone, no reply
+t = "deck.state" b = DeckState // PC → phone, no reply
+t = "deck.press" id = n b = { tile: text } // phone → PC
+t = "ok" re = n
+```
+
+### 2.1 `deck.layout`
+
+Sent by a PC that offers `deck.actions` when a session starts and whenever the
+user edits the Deck on the PC.
+
+```
+DeckLayout = {
+ pages: [DeckPage], // 1..=8 pages
+}
+
+DeckPage = {
+ id: text, // 1..=64 ASCII alphanumeric / '_' / '-' / '.', unique per layout
+ name: text, // 1..=64 UTF-8 bytes, no control chars
+ tiles: [DeckTile], // 0..=24 tiles
+}
+
+DeckTile = {
+ id: text, // 1..=64 ASCII alphanumeric / '_' / '-' / '.', unique across the layout
+ label: text, // 1..=64 UTF-8 bytes, no control chars
+ icon: text, // from the fixed icon set (§2.4)
+ color: text, // from the fixed color set (§2.4)
+ kind: text, // action kind (§2.4); never contains paths, URLs, or commands
+}
+```
+
+### 2.2 `deck.state`
+
+Sent by a PC that offers `deck.actions` when a session starts and whenever
+the PC's media playback state, speaker volume/mute, or microphone mute state
+changes.
+
+```
+DeckState = {
+ playing: bool, // PC media is currently playing (`media_play_pause` tiles)
+ volume: uint, // PC speaker volume, 0..=100 (`volume_*` tiles)
+ muted: bool, // PC speaker is muted (`volume_*` tiles)
+ mic_muted?: bool, // default PC microphone is muted (`mic_mute` tiles); omitted when no capture device exists
+}
+```
+
+### 2.3 `deck.press`
+
+Asks the PC to run the action bound to `tile`.
+
+```
+DeckPress = {
+ tile: text, // 1..=64 ASCII alphanumeric / '_' / '-' / '.'
+}
+```
+
+Errors:
+- `BAD_MESSAGE` when `tile` is empty, longer than 64 bytes, or contains disallowed characters.
+- `UNSUPPORTED` when the PC does not offer `deck.actions`.
+- `DENIED` when `remote_input` is off for the phone, or when the tile's `kind` is `"run_command"` and `commands` is off for the phone.
+- `NOT_FOUND` when no tile with ID `tile` exists in the PC's current Deck layout.
+- `INTERNAL` when the platform action fails on the PC.
+
+### 2.4 Action kinds, icons, and colors
+
+- **Action kinds (`kind`):**
+ - Media: `"media_play_pause"`, `"media_next"`, `"media_previous"`
+ - Volume: `"volume_up"`, `"volume_down"`, `"volume_mute"`
+ - Microphone: `"mic_mute"`
+ - System & windows: `"lock_pc"`, `"show_desktop"`, `"switch_window"`, `"screenshot"`
+ - Parameterized on the PC (parameters stay on the PC and are never sent over the wire):
+ - `"shortcut"` (custom keyboard shortcut: key + modifiers)
+ - `"open_url"` (`http` or `https` URL)
+ - `"type_text"` (text snippet typed into the focused field)
+ - `"launch_app"` (`.exe` or `.lnk` picked on the PC, launched via `ShellExecuteW` without arguments)
+ - `"run_command"` (command written on the PC; requires the per-device `commands` toggle)
+- **Icons (`icon`):** `"play"`, `"pause"`, `"skip_next"`, `"skip_previous"`, `"volume_up"`, `"volume_down"`, `"volume_off"`, `"mic"`, `"mic_off"`, `"lock"`, `"desktop"`, `"switch_window"`, `"screenshot"`, `"shortcut"`, `"globe"`, `"text"`, `"app"`, `"terminal"`, `"sparkle"`, `"star"`.
+- **Colors (`color`):** `"amber"`, `"coral"`, `"red"`, `"teal"`, `"green"`, `"blue"`, `"violet"`, `"slate"`.