Skip to content

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

Clip suggestions, and the PC's sound from the phone

Bee9520c599bbd7
diff --git a/Cargo.lock b/Cargo.lock
index 40f6edd..ec0326e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2378,6 +2378,7 @@ dependencies = [
"tracing",
"tracing-subscriber",
"windows",
+ "windows-core",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 94707bf..e59a52e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -61,6 +61,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
url = "2.5"
windows = "0.62"
+windows-core = "0.62"
[workspace.lints.rust]
unsafe_code = "deny"
diff --git a/README.md b/README.md
index f4a1cc3..3e6c781 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,11 @@ tests; there are no releases yet.
- **Clipboard**: text and images you copy on the PC are ready to paste on the
phone. From the phone, send them with the Quick Settings tile, the share
sheet or a button in the app (Android lets only the app in front read the
- clipboard). Both apps keep an optional encrypted **Clipboard history** of the
+ clipboard). When a web link, street address, phone number, parcel tracking
+ number or email address arrives from a paired device, Nectarlink offers a
+ fitting context chip (**Open**, **Open in Maps**, **Call**, **Track**, or
+ **Email**) right on the confirmation (can be turned off in Settings). Both
+ apps keep an optional encrypted **Clipboard history** of the
last 50 text and image clips shared between your devices (with search, copy
again, pin, delete and clear all). Passwords that password managers mark
private and one-time codes are never sent or saved in history.
@@ -164,9 +168,11 @@ 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,
+- **Deck (macro pad) and PC audio**: 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, a live PC master volume slider, mute
+ button and active audio output device indicator (both on the PC card on Home
+ and in the Deck header), 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,
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 db20fba..785cb20 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
@@ -162,6 +162,7 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
private val remoteOps = Channel<suspend (NectarlinkNode) -> Unit>(Channel.UNLIMITED)
private val _state = MutableStateFlow(CoreState())
private val _messages = MutableSharedFlow<String>(extraBufferCapacity = 8)
+ private val _clipSuggestions = MutableSharedFlow<ClipSuggestionNotice>(extraBufferCapacity = 4)
private var node: NectarlinkNode? = null
private var startJob: Job? = null
private var networkChange: Job? = null
@@ -193,6 +194,15 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
/** Short messages for the user (a command failed). */
val messages: SharedFlow<String> = _messages.asSharedFlow()
+ /** Context action suggestions for newly received clipboard text. */
+ val clipSuggestions: SharedFlow<ClipSuggestionNotice> = _clipSuggestions.asSharedFlow()
+
+ data class ClipSuggestionNotice(
+ val message: String,
+ val actionLabel: String,
+ val suggestion: app.nectarlink.core.ClipSuggestion,
+ )
+
/** Starts the node (once). Safe to call repeatedly. */
fun start() {
if (startJob != null) return
@@ -398,11 +408,28 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
if (_state.value.devices.isEmpty()) ConnectionService.stop(context)
}
is Event.Paired -> ConnectionService.start(context)
+ is Event.ClipboardReceived -> onClipboardReceived(event.id)
is Event.ClipboardHistoryChanged -> refreshClipboardHistory()
else -> {}
}
}
+ private fun onClipboardReceived(pcId: String) {
+ if (!app.nectarlink.android.ui.Preferences.isSuggestClipboardActionsEnabled(context)) return
+ val suggestion = runCatching { node?.lastClipSuggestion() }.getOrNull() ?: return
+ val pcName = _state.value.nameOf(pcId).orEmpty()
+ val from = pcName.ifEmpty { context.getString(R.string.your_pc) }
+ val message = context.getString(R.string.clip_received_from, from)
+ val actionLabel = LinkNotifications.actionLabel(context, suggestion.kind)
+ _clipSuggestions.tryEmit(ClipSuggestionNotice(message, actionLabel, suggestion))
+ LinkNotifications.showClipSuggestion(context, pcName, suggestion)
+ }
+
+ /** Executes the action for a smart clipboard suggestion. */
+ fun runClipSuggestion(suggestion: app.nectarlink.core.ClipSuggestion) {
+ LinkNotifications.runSuggestion(context, suggestion)
+ }
+
// ---- Files & Recordings ----
private fun onTransfer(transfer: Transfer) {
@@ -961,6 +988,40 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
}
}
+ /** Sets the PC's master volume (`0..=100`) and/or mute state (`pc.audio.set`). */
+ fun setPcAudio(id: String, volume: Int? = null, muted: Boolean? = null) {
+ val clampedVol = volume?.coerceIn(0, 100)?.toUByte()
+ // Optimistic local state update so the slider and mute button don't snap back while the RPC runs.
+ _state.update { s ->
+ val current = s.device(id)?.deckState
+ if (current != null) {
+ s.reduce(
+ Event.DeckState(
+ id = id,
+ state = current.copy(
+ volume = clampedVol ?: current.volume,
+ muted = muted ?: current.muted,
+ ),
+ ),
+ )
+ } else {
+ s
+ }
+ }
+ remoteOps.trySend { node ->
+ try {
+ node.setPcAudio(id, clampedVol, muted)
+ } catch (e: NectarlinkException) {
+ if (e is NectarlinkException.Denied) {
+ val name = _state.value.nameOf(id).orEmpty()
+ _messages.tryEmit(context.getString(R.string.remote_denied_title, name))
+ } else if (e !is NectarlinkException.Offline) {
+ _messages.tryEmit(describe(e))
+ }
+ }
+ }
+ }
+
// ---- Phone storage (File Explorer on PC) ----
/** Turns phone storage access in File Explorer on or off for `pcId` (off by default). */
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt b/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt
index 1c08579..488517e 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt
@@ -8,19 +8,27 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
+import android.net.Uri
import androidx.core.net.toUri
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import app.nectarlink.android.R
+import app.nectarlink.core.ClipKind
+import app.nectarlink.core.ClipSuggestion
+import app.nectarlink.core.mapsWebUrl
+import app.nectarlink.core.trackingSearchUrl
/**
- * Links a PC sent: Android doesn't let an app in the background open
- * screens, so each link waits in a notification the user taps to open.
+ * Links and smart clipboard actions from a PC: Android doesn't let an app in
+ * the background open screens, so links and background clip suggestions wait
+ * in a notification on the same channel.
*/
object LinkNotifications {
private const val CHANNEL = "links"
private const val TAG = "link"
+ private const val CLIP_TAG = "clip_suggestion"
+ private const val CLIP_NOTIFICATION_ID = 0x434C4950 // "CLIP"
fun createChannel(context: Context) {
context.getSystemService(NotificationManager::class.java).createNotificationChannel(
@@ -56,4 +64,97 @@ object LinkNotifications {
.build()
return runCatching { NotificationManagerCompat.from(context).notify(TAG, url.hashCode(), notification) }.isSuccess
}
+
+ /** Short action chip label for a [ClipKind]. */
+ fun actionLabel(context: Context, kind: ClipKind): String = when (kind) {
+ ClipKind.WEB_LINK -> context.getString(R.string.clip_action_open)
+ ClipKind.STREET_ADDRESS -> context.getString(R.string.clip_action_maps)
+ ClipKind.PHONE_NUMBER -> context.getString(R.string.clip_action_call)
+ ClipKind.TRACKING_NUMBER -> context.getString(R.string.clip_action_track)
+ ClipKind.EMAIL -> context.getString(R.string.clip_action_email)
+ }
+
+ /** Builds the Android [Intent] for a [ClipSuggestion]. */
+ fun intentForSuggestion(context: Context, suggestion: ClipSuggestion): Intent = when (suggestion.kind) {
+ ClipKind.WEB_LINK -> Intent(Intent.ACTION_VIEW, suggestion.target.toUri())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ ClipKind.STREET_ADDRESS -> {
+ val geoIntent = Intent(
+ Intent.ACTION_VIEW,
+ Uri.parse("geo:0,0?q=${Uri.encode(suggestion.target)}"),
+ ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ if (geoIntent.resolveActivity(context.packageManager) != null) {
+ geoIntent
+ } else {
+ Intent(Intent.ACTION_VIEW, mapsWebUrl(suggestion.target).toUri())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+ }
+ ClipKind.PHONE_NUMBER -> Intent(
+ Intent.ACTION_DIAL,
+ Uri.fromParts("tel", suggestion.target, null),
+ ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ ClipKind.TRACKING_NUMBER -> Intent(
+ Intent.ACTION_VIEW,
+ trackingSearchUrl(suggestion.target).toUri(),
+ ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ ClipKind.EMAIL -> Intent(
+ Intent.ACTION_SENDTO,
+ Uri.fromParts("mailto", suggestion.target, null),
+ ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+
+ /** Runs a [ClipSuggestion] action on this phone, with web/view fallback if needed. */
+ fun runSuggestion(context: Context, suggestion: ClipSuggestion) {
+ dismissClipSuggestion(context)
+ val primary = intentForSuggestion(context, suggestion)
+ if (runCatching { context.startActivity(primary) }.isSuccess) return
+ val fallback = when (suggestion.kind) {
+ ClipKind.STREET_ADDRESS -> Intent(Intent.ACTION_VIEW, mapsWebUrl(suggestion.target).toUri())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ ClipKind.EMAIL -> Intent(Intent.ACTION_VIEW, Uri.fromParts("mailto", suggestion.target, null))
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ else -> null
+ }
+ if (fallback != null) {
+ runCatching { context.startActivity(fallback) }
+ }
+ }
+
+ /** Shows a silent notification with the suggested action chip for a received clip. */
+ fun showClipSuggestion(context: Context, pcName: String, suggestion: ClipSuggestion): Boolean {
+ if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=
+ PackageManager.PERMISSION_GRANTED
+ ) {
+ return false
+ }
+ val intent = intentForSuggestion(context, suggestion)
+ val pending = PendingIntent.getActivity(
+ context,
+ CLIP_NOTIFICATION_ID,
+ intent,
+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
+ )
+ val label = actionLabel(context, suggestion.kind)
+ val from = pcName.ifEmpty { context.getString(R.string.your_pc) }
+ val notification = NotificationCompat.Builder(context, CHANNEL)
+ .setSmallIcon(R.drawable.ic_notification)
+ .setContentTitle(context.getString(R.string.clip_received_from, from))
+ .setContentText(label)
+ .setContentIntent(pending)
+ .addAction(0, label, pending)
+ .setSilent(true)
+ .setAutoCancel(true)
+ .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION)
+ .setPriority(NotificationCompat.PRIORITY_DEFAULT)
+ .build()
+ return runCatching {
+ NotificationManagerCompat.from(context).notify(CLIP_TAG, CLIP_NOTIFICATION_ID, notification)
+ }.isSuccess
+ }
+
+ fun dismissClipSuggestion(context: Context) {
+ runCatching { NotificationManagerCompat.from(context).cancel(CLIP_TAG, CLIP_NOTIFICATION_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 8a6cd6f..8822071 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
@@ -37,6 +37,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
+import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import app.nectarlink.android.NectarlinkApplication
import app.nectarlink.android.R
@@ -266,6 +267,18 @@ private fun App(
var webcamInitialCamera by rememberSaveable { mutableStateOf<String?>(null) }
val snackbar = remember { SnackbarHostState() }
LaunchedEffect(Unit) { core.messages.collect { snackbar.showSnackbar(it) } }
+ LaunchedEffect(Unit) {
+ core.clipSuggestions.collectLatest { notice ->
+ val result = snackbar.showSnackbar(
+ message = notice.message,
+ actionLabel = notice.actionLabel,
+ duration = androidx.compose.material3.SnackbarDuration.Short,
+ )
+ if (result == androidx.compose.material3.SnackbarResult.ActionPerformed) {
+ core.runClipSuggestion(notice.suggestion)
+ }
+ }
+ }
LaunchedEffect(requestedRemotePc, state.devices) {
val req = requestedRemotePc ?: return@LaunchedEffect
@@ -475,6 +488,7 @@ private fun App(
onDeleteClipboardHistory = core::deleteClipboardHistory,
onClearClipboardHistory = core::clearClipboardHistory,
loadClipboardHistoryImage = core::clipboardHistoryImage,
+ onSetPcAudio = core::setPcAudio,
modifier = modifier,
)
Tab.Settings -> SettingsScreen(
@@ -492,6 +506,8 @@ private fun App(
onRemoveSafFolder = core::removeSafFolder,
onSetClipboardHistoryEnabled = core::setClipboardHistoryEnabled,
onClearClipboardHistory = core::clearClipboardHistory,
+ suggestClipboardActions = preferences.suggestClipboardActions.collectAsStateWithLifecycle().value,
+ onSetSuggestClipboardActions = preferences::updateSuggestClipboardActions,
modifier = modifier,
)
}
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/Preferences.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/Preferences.kt
index fb91bdb..58b93f9 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/Preferences.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/Preferences.kt
@@ -17,6 +17,9 @@ class Preferences(context: Context) {
private val _touchpadSensitivity = MutableStateFlow(prefs.getFloat(TOUCHPAD_SENSITIVITY, 1.0f).coerceIn(0.4f, 3.0f))
val touchpadSensitivity: StateFlow<Float> = _touchpadSensitivity.asStateFlow()
+ private val _suggestClipboardActions = MutableStateFlow(prefs.getBoolean(SUGGEST_CLIPBOARD_ACTIONS, true))
+ val suggestClipboardActions: StateFlow<Boolean> = _suggestClipboardActions.asStateFlow()
+
private fun load(): Appearance {
val defaults = Appearance()
return Appearance(
@@ -44,11 +47,28 @@ class Preferences(context: Context) {
_touchpadSensitivity.value = clamped
}
- private companion object {
- const val THEME = "theme"
- const val MODE = "mode"
- const val SEED = "seed"
- const val DYNAMIC = "dynamic_color"
- const val TOUCHPAD_SENSITIVITY = "touchpad_sensitivity"
+ fun updateSuggestClipboardActions(enabled: Boolean) {
+ prefs.edit { putBoolean(SUGGEST_CLIPBOARD_ACTIONS, enabled) }
+ _suggestClipboardActions.value = enabled
+ if (!enabled) {
+ app.nectarlink.android.links.LinkNotifications.dismissClipSuggestion(appContext)
+ }
+ }
+
+ private val appContext = context.applicationContext
+
+ companion object {
+ private const val THEME = "theme"
+ private const val MODE = "mode"
+ private const val SEED = "seed"
+ private const val DYNAMIC = "dynamic_color"
+ private const val TOUCHPAD_SENSITIVITY = "touchpad_sensitivity"
+ private const val SUGGEST_CLIPBOARD_ACTIONS = "suggest_clipboard_actions"
+
+ fun isSuggestClipboardActionsEnabled(context: Context): Boolean =
+ context.applicationContext
+ .getSharedPreferences("appearance", Context.MODE_PRIVATE)
+ .getBoolean(SUGGEST_CLIPBOARD_ACTIONS, true)
}
}
+
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
index a331cd8..fa5bddc 100644
--- 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
@@ -10,6 +10,7 @@ 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.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
@@ -31,11 +32,13 @@ 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.FilledTonalButton
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
+import androidx.compose.material3.Slider
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
@@ -80,10 +83,12 @@ 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.android.ui.home.PcAudioOutputsDialog
import app.nectarlink.core.DeckLayout
import app.nectarlink.core.DeckPage
import app.nectarlink.core.DeckState
import app.nectarlink.core.DeckTile
+import kotlin.math.roundToInt
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@@ -152,6 +157,7 @@ fun DeckScreen(
volume = 50u,
muted = false,
micMuted = false,
+ outputDevices = emptyList(),
)
val pages = layout.pages.ifEmpty { fallbackDefaultLayout().pages }
val pagerState = rememberPagerState(pageCount = { pages.size })
@@ -213,6 +219,15 @@ fun DeckScreen(
}
}
+ // Compact PC audio header bar (volume, mute, and active output device)
+ if (!fullScreen && device.online) {
+ DeckAudioHeaderBar(
+ pcName = device.name,
+ liveState = liveState,
+ onSetPcAudio = { vol, muted -> core.setPcAudio(device.id, vol, muted) },
+ )
+ }
+
// Status / permission banners
if (!device.online) {
DeckBanner(
@@ -332,6 +347,99 @@ private object MaterialResource {
fun onSurfaceVariant(): Color = MaterialTheme.colorScheme.onSurfaceVariant
}
+@Composable
+private fun DeckAudioHeaderBar(
+ pcName: String,
+ liveState: DeckState,
+ onSetPcAudio: (volume: Int?, muted: Boolean?) -> Unit,
+) {
+ var draggingVolume by remember { mutableStateOf<Float?>(null) }
+ var showOutputs by remember { mutableStateOf(false) }
+ val shownVolume = draggingVolume?.roundToInt() ?: liveState.volume.toInt()
+ val defaultOutput = liveState.outputDevices.firstOrNull { it.isDefault } ?: liveState.outputDevices.firstOrNull()
+
+ Surface(
+ shape = MaterialTheme.shapes.large,
+ color = MaterialTheme.colorScheme.surfaceContainer,
+ modifier = Modifier.fillMaxWidth(),
+ ) {
+ Column(
+ modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 6.dp),
+ verticalArrangement = Arrangement.spacedBy(2.dp),
+ ) {
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ FilledTonalButton(
+ onClick = { onSetPcAudio(null, !liveState.muted) },
+ contentPadding = PaddingValues(horizontal = 10.dp, vertical = 4.dp),
+ ) {
+ Text(
+ stringResource(if (liveState.muted) R.string.pc_audio_unmute else R.string.pc_audio_mute),
+ style = MaterialTheme.typography.labelMedium,
+ maxLines = 1,
+ )
+ }
+ Slider(
+ value = (draggingVolume ?: liveState.volume.toFloat()).coerceIn(0f, 100f),
+ onValueChange = { v ->
+ draggingVolume = v
+ onSetPcAudio(v.roundToInt(), null)
+ },
+ onValueChangeFinished = { draggingVolume = null },
+ valueRange = 0f..100f,
+ modifier = Modifier.weight(1f),
+ )
+ Text(
+ text = if (liveState.muted) {
+ stringResource(R.string.pc_audio_muted)
+ } else {
+ stringResource(R.string.deck_volume_percent, shownVolume)
+ },
+ style = MaterialTheme.typography.labelMedium,
+ )
+ }
+ if (defaultOutput != null) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .clickable { showOutputs = true }
+ .padding(horizontal = 4.dp, vertical = 2.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.SpaceBetween,
+ ) {
+ Text(
+ text = stringResource(R.string.pc_audio_output, defaultOutput.name),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.weight(1f),
+ )
+ if (liveState.outputDevices.size > 1) {
+ Spacer(Modifier.width(8.dp))
+ Text(
+ text = "${liveState.outputDevices.size}",
+ style = MaterialTheme.typography.labelSmall,
+ color = MaterialTheme.colorScheme.primary,
+ )
+ }
+ }
+ }
+ }
+ }
+
+ if (showOutputs && liveState.outputDevices.isNotEmpty()) {
+ PcAudioOutputsDialog(
+ pcName = pcName,
+ devices = liveState.outputDevices,
+ onDismiss = { showOutputs = false },
+ )
+ }
+}
+
@Composable
private fun DeckBanner(
title: String,
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 f920cbf..23dbcad 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
@@ -36,6 +36,8 @@ import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Slider
+import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
@@ -48,6 +50,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.graphicsLayer
@@ -73,12 +76,15 @@ import app.nectarlink.android.photos.RecentPhotos
import app.nectarlink.android.sms.PhoneSms
import app.nectarlink.android.update.AppUpdater
import app.nectarlink.android.update.UpdateCard
+import app.nectarlink.core.AudioOutputDevice
import app.nectarlink.core.ClipboardHistoryEntry
import app.nectarlink.core.ClipboardItemKind
+import app.nectarlink.core.DeckState
import app.nectarlink.core.Link
import app.nectarlink.core.Transfer
import app.nectarlink.core.TransferDirection
import app.nectarlink.core.TransferStatus
+import kotlin.math.roundToInt
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -114,6 +120,7 @@ fun HomeScreen(
onDeleteClipboardHistory: (id: String) -> Unit = {},
onClearClipboardHistory: () -> Unit = {},
loadClipboardHistoryImage: suspend (id: String) -> ByteArray? = { null },
+ onSetPcAudio: (pcId: String, volume: Int?, muted: Boolean?) -> Unit = { _, _, _ -> },
modifier: Modifier = Modifier,
) {
var showClipboardHistory by remember { mutableStateOf(false) }
@@ -301,6 +308,7 @@ fun HomeScreen(
onDeck = onDeck,
onRecord = onRecord,
onWebcam = onWebcam,
+ onSetPcAudio = onSetPcAudio,
)
}
if (state.clipboardHistoryEnabled && state.clipboardHistory.isNotEmpty()) {
@@ -370,6 +378,7 @@ private fun PcCard(
onDeck: (String) -> Unit,
onRecord: (String) -> Unit,
onWebcam: (String) -> Unit,
+ onSetPcAudio: (String, Int?, Boolean?) -> Unit,
) {
val pickFiles = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris ->
if (uris.isNotEmpty()) onSendFiles(device.id, uris)
@@ -437,7 +446,18 @@ private fun PcCard(
val outlined = ButtonDefaults.outlinedButtonColors(contentColor = ink, disabledContentColor = ink.copy(alpha = 0.38f))
val outline = BorderStroke(1.dp, ink.copy(alpha = if (device.online) 0.45f else 0.15f))
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- if (!device.online && device.canWake) {
+ if (!device.online && device.wakeState == WakeState.Idle && device.canWake) {
+ Button(
+ enabled = device.wakeState != WakeState.Waking,
+ onClick = { onWake(device.id) },
+ modifier = Modifier.fillMaxWidth(),
+ ) {
+ Text(
+ if (device.wakeState == WakeState.Waking) stringResource(R.string.wake_waking, device.name)
+ else stringResource(R.string.action_wake_pc),
+ )
+ }
+ } else if (!device.online && device.canWake) {
Button(
enabled = device.wakeState != WakeState.Waking,
onClick = { onWake(device.id) },
@@ -489,6 +509,18 @@ private fun PcCard(
}
}
+ // Live PC master volume, mute, and active output device bar
+ val deckState = device.deckState
+ if (device.online && deckState != null) {
+ PcAudioCardSection(
+ pcName = device.name,
+ deckState = deckState,
+ ink = ink,
+ tonal = tonal,
+ onSetPcAudio = { vol, muted -> onSetPcAudio(device.id, vol, muted) },
+ )
+ }
+
val expanded = showMoreActions || ringing
Row(
modifier = Modifier.fillMaxWidth(),
@@ -631,6 +663,171 @@ private fun PcCard(
}
}
+@Composable
+private fun PcAudioCardSection(
+ pcName: String,
+ deckState: DeckState,
+ ink: Color,
+ tonal: androidx.compose.material3.ButtonColors,
+ onSetPcAudio: (volume: Int?, muted: Boolean?) -> Unit,
+) {
+ var draggingVolume by remember { mutableStateOf<Float?>(null) }
+ var showOutputs by remember { mutableStateOf(false) }
+ val shownVolume = draggingVolume?.roundToInt() ?: deckState.volume.toInt()
+ val defaultOutput = deckState.outputDevices.firstOrNull { it.isDefault } ?: deckState.outputDevices.firstOrNull()
+
+ Surface(
+ shape = MaterialTheme.shapes.large,
+ color = ink.copy(alpha = 0.06f),
+ contentColor = ink,
+ ) {
+ Column(
+ modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 10.dp),
+ verticalArrangement = Arrangement.spacedBy(4.dp),
+ ) {
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ FilledTonalButton(
+ colors = tonal,
+ onClick = { onSetPcAudio(null, !deckState.muted) },
+ contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 12.dp, vertical = 6.dp),
+ ) {
+ Text(
+ stringResource(if (deckState.muted) R.string.pc_audio_unmute else R.string.pc_audio_mute),
+ style = MaterialTheme.typography.labelLarge,
+ maxLines = 1,
+ )
+ }
+ Slider(
+ value = (draggingVolume ?: deckState.volume.toFloat()).coerceIn(0f, 100f),
+ onValueChange = { v ->
+ draggingVolume = v
+ onSetPcAudio(v.roundToInt(), null)
+ },
+ onValueChangeFinished = { draggingVolume = null },
+ valueRange = 0f..100f,
+ colors = SliderDefaults.colors(
+ thumbColor = ink,
+ activeTrackColor = ink,
+ inactiveTrackColor = ink.copy(alpha = 0.22f),
+ ),
+ modifier = Modifier.weight(1f),
+ )
+ Text(
+ text = if (deckState.muted) {
+ stringResource(R.string.pc_audio_muted)
+ } else {
+ stringResource(R.string.deck_volume_percent, shownVolume)
+ },
+ style = MaterialTheme.typography.labelLarge,
+ )
+ }
+ if (defaultOutput != null) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .clickable { showOutputs = true }
+ .padding(horizontal = 4.dp, vertical = 4.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.SpaceBetween,
+ ) {
+ Text(
+ text = stringResource(R.string.pc_audio_output, defaultOutput.name),
+ style = MaterialTheme.typography.bodySmall,
+ color = ink.copy(alpha = 0.85f),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.weight(1f),
+ )
+ if (deckState.outputDevices.size > 1) {
+ Spacer(Modifier.width(8.dp))
+ Text(
+ text = "${deckState.outputDevices.size}",
+ style = MaterialTheme.typography.labelSmall,
+ color = ink.copy(alpha = 0.7f),
+ )
+ }
+ }
+ }
+ }
+ }
+
+ if (showOutputs && deckState.outputDevices.isNotEmpty()) {
+ PcAudioOutputsDialog(
+ pcName = pcName,
+ devices = deckState.outputDevices,
+ onDismiss = { showOutputs = false },
+ )
+ }
+}
+
+@Composable
+internal fun PcAudioOutputsDialog(
+ pcName: String,
+ devices: List<AudioOutputDevice>,
+ onDismiss: () -> Unit,
+) {
+ AlertDialog(
+ onDismissRequest = onDismiss,
+ title = { Text(stringResource(R.string.pc_audio_outputs_title, pcName)) },
+ text = {
+ Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
+ Text(
+ stringResource(R.string.pc_audio_outputs_hint, pcName),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ devices.forEach { out ->
+ Surface(
+ shape = MaterialTheme.shapes.medium,
+ color = if (out.isDefault) {
+ MaterialTheme.colorScheme.secondaryContainer
+ } else {
+ MaterialTheme.colorScheme.surfaceContainerHigh
+ },
+ modifier = Modifier.fillMaxWidth(),
+ ) {
+ Row(
+ modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 12.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.SpaceBetween,
+ ) {
+ Text(
+ text = out.name,
+ style = MaterialTheme.typography.bodyMedium,
+ color = if (out.isDefault) {
+ MaterialTheme.colorScheme.onSecondaryContainer
+ } else {
+ MaterialTheme.colorScheme.onSurface
+ },
+ maxLines = 2,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.weight(1f),
+ )
+ if (out.isDefault) {
+ Spacer(Modifier.width(8.dp))
+ Text(
+ text = stringResource(R.string.pc_audio_default_badge),
+ style = MaterialTheme.typography.labelMedium,
+ color = MaterialTheme.colorScheme.primary,
+ )
+ }
+ }
+ }
+ }
+ }
+ },
+ confirmButton = {
+ TextButton(onClick = onDismiss) {
+ Text(stringResource(R.string.clipboard_history_done))
+ }
+ },
+ )
+}
+
@Composable
private fun ClipboardHistoryCard(
entries: List<ClipboardHistoryEntry>,
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/settings/SettingsScreen.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/settings/SettingsScreen.kt
index 36e6171..5182f4f 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/settings/SettingsScreen.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/settings/SettingsScreen.kt
@@ -83,6 +83,8 @@ fun SettingsScreen(
onRemoveSafFolder: (String) -> Unit = {},
onSetClipboardHistoryEnabled: (Boolean) -> Unit = {},
onClearClipboardHistory: () -> Unit = {},
+ suggestClipboardActions: Boolean = true,
+ onSetSuggestClipboardActions: (Boolean) -> Unit = {},
modifier: Modifier = Modifier,
) {
var confirmUnpair by remember { mutableStateOf<Device?>(null) }
@@ -102,6 +104,21 @@ fun SettingsScreen(
}
Section(stringResource(R.string.settings_clipboard_title)) {
+ Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
+ Column(Modifier.weight(1f).padding(end = 12.dp)) {
+ Text(stringResource(R.string.settings_clipboard_suggestions), style = MaterialTheme.typography.titleSmall)
+ Text(
+ stringResource(R.string.settings_clipboard_suggestions_hint),
+ style = MaterialTheme.typography.bodySmall,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ )
+ }
+ Switch(
+ checked = suggestClipboardActions,
+ onCheckedChange = onSetSuggestClipboardActions,
+ )
+ }
+ SettingRowDivider()
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
Column(Modifier.weight(1f).padding(end = 12.dp)) {
Text(stringResource(R.string.settings_clipboard_history), style = MaterialTheme.typography.titleSmall)
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index bb3b0b8..8dd8f9d 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -175,8 +175,16 @@
<string name="clipboard_history_clear">Clear history</string>
<string name="clipboard_history_done">Done</string>
<string name="settings_clipboard_title">Clipboard</string>
+ <string name="settings_clipboard_suggestions">Suggest actions for copied text</string>
+ <string name="settings_clipboard_suggestions_hint">Offer to open links, look up addresses in Maps, call numbers, track parcels, or compose emails when text arrives from your PC.</string>
<string name="settings_clipboard_history">Keep clipboard history</string>
<string name="settings_clipboard_history_hint">Keep the last 50 text and image clips shared with your PCs, encrypted on this phone. Passwords and one-time codes are never saved.</string>
+ <string name="clip_received_from">Copied from %1$s</string>
+ <string name="clip_action_open">Open</string>
+ <string name="clip_action_maps">Open in Maps</string>
+ <string name="clip_action_call">Call</string>
+ <string name="clip_action_track">Track</string>
+ <string name="clip_action_email">Email</string>
<string name="background_title">Stay reachable in the background</string>
<string name="background_text">Your phone pauses Nectarlink to save battery, so your PC can’t reach it, and replies and dismissals from the PC time out. Let it run in the background.</string>
<string name="action_manage">Manage</string>
@@ -337,6 +345,15 @@
<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">Customize tiles in Deck on %1$s</string>
+ <string name="pc_audio_title">PC audio</string>
+ <string name="pc_audio_volume">Volume</string>
+ <string name="pc_audio_mute">Mute</string>
+ <string name="pc_audio_unmute">Unmute</string>
+ <string name="pc_audio_muted">Muted</string>
+ <string name="pc_audio_output">Output: %1$s</string>
+ <string name="pc_audio_outputs_title">Audio outputs on %1$s</string>
+ <string name="pc_audio_default_badge">Default</string>
+ <string name="pc_audio_outputs_hint">Active playback devices on %1$s.</string>
<!-- Phone storage in File Explorer -->
<string name="settings_storage">Storage in File Explorer</string>
diff --git a/android/app/src/test/kotlin/app/nectarlink/android/core/CoreStateTest.kt b/android/app/src/test/kotlin/app/nectarlink/android/core/CoreStateTest.kt
index 57108d0..53e3305 100644
--- a/android/app/src/test/kotlin/app/nectarlink/android/core/CoreStateTest.kt
+++ b/android/app/src/test/kotlin/app/nectarlink/android/core/CoreStateTest.kt
@@ -89,4 +89,30 @@ class CoreStateTest {
assertEquals(state, state.reduce(Event.NotificationRemoved("a", "k")))
assertEquals(state, state.reduce(Event.NotificationsReset("a", listOf(note))))
assertTrue("access is off until the listener connects", !state.notificationAccess)
- }}
+ }
+
+ @Test
+ fun deckStateCarriesPcVolumeMuteAndOutputDevices() {
+ val outputs = listOf(
+ app.nectarlink.core.AudioOutputDevice("out-1", "Speakers (Realtek Audio)", true),
+ app.nectarlink.core.AudioOutputDevice("out-2", "Headphones", false),
+ )
+ val deckState = app.nectarlink.core.DeckState(
+ playing = true,
+ volume = 72u,
+ muted = false,
+ micMuted = true,
+ outputDevices = outputs,
+ )
+ val state = CoreState()
+ .reduce(Event.DeviceAdded(pc("a", "Desk", 10)))
+ .reduce(Event.DeckState("a", deckState))
+ val dev = state.device("a")!!
+ val ds = dev.deckState!!
+ assertEquals(72.toUByte(), ds.volume)
+ assertEquals(false, ds.muted)
+ assertEquals(2, ds.outputDevices.size)
+ assertEquals("Speakers (Realtek Audio)", ds.outputDevices.first { it.isDefault }.name)
+ }
+}
+
diff --git a/core/nectarlink-cli/src/main.rs b/core/nectarlink-cli/src/main.rs
index 2286cc6..4bcfb89 100644
--- a/core/nectarlink-cli/src/main.rs
+++ b/core/nectarlink-cli/src/main.rs
@@ -627,6 +627,10 @@ enum TogglesArg {
enum DeckArg {
/// Press a tile on the PC's deck by its ID.
Press { tile: String },
+ /// Set the PC's master speaker volume (`0..=100`).
+ Volume { level: u8 },
+ /// Mute (`on`) or unmute (`off`) the PC's speakers.
+ Mute { state: OnOff },
}
#[derive(Debug, Subcommand)]
@@ -1959,6 +1963,10 @@ impl Platform for TerminalPlatform {
println!("A paired device pressed deck tile {tile}");
Ok(())
}
+ fn set_pc_audio(&self, _peer: &DeviceId, volume: Option<u8>, muted: Option<bool>) -> Result<(), String> {
+ println!("A paired device set PC audio: volume={volume:?} muted={muted:?}");
+ Ok(())
+ }
fn storage_list(
&self,
path: &str,
@@ -2105,6 +2113,7 @@ async fn start_node(cli: &Cli) -> Result<Node> {
config.capabilities.push(nectarlink_core::TOGGLES_SHOW.into());
config.capabilities.push(nectarlink_core::PC_WAKE.into());
config.capabilities.push(nectarlink_core::DECK_ACTIONS.into());
+ config.capabilities.push(nectarlink_core::PC_AUDIO.into());
config.capabilities.push(nectarlink_core::STORAGE_MOUNT.into());
config.capabilities.push(nectarlink_core::WEBCAM_VIRTUAL.into());
config.capabilities.push(nectarlink_core::WEBCAM_ADDON_VCAM.into());
@@ -2120,6 +2129,19 @@ async fn start_node(cli: &Cli) -> Result<Node> {
broadcasts: vec!["192.168.31.255".into()],
})
.await;
+ let _ = node
+ .set_deck_state(nectarlink_core::DeckState {
+ playing: false,
+ volume: 75,
+ muted: false,
+ mic_muted: Some(false),
+ output_devices: vec![nectarlink_core::AudioOutputDevice {
+ id: "cli:speakers".into(),
+ name: "Speakers (CLI)".into(),
+ is_default: true,
+ }],
+ })
+ .await;
}
if !cli.offers.is_empty() {
let mut offers = extra_caps;
@@ -2567,6 +2589,21 @@ async fn run(cli: &Cli, node: &Node) -> Result<()> {
.with_context(|| format!("the PC refused deck tile {tile:?}"))?;
println!("Pressed {tile}.");
}
+ Command::Deck { device, action: Some(DeckArg::Volume { level }) } => {
+ let id = resolve(node, device)?;
+ wait_until_online(node, id).await?;
+ node.set_pc_audio(id, Some(*level), None)
+ .await
+ .with_context(|| format!("couldn't set PC volume to {level}%"))?;
+ println!("PC volume set to {level}%.");
+ }
+ Command::Deck { device, action: Some(DeckArg::Mute { state }) } => {
+ let muted = matches!(state, OnOff::On);
+ let id = resolve(node, device)?;
+ wait_until_online(node, id).await?;
+ node.set_pc_audio(id, None, Some(muted)).await.context("couldn't set PC mute")?;
+ println!("PC speakers {}.", if muted { "muted" } else { "unmuted" });
+ }
Command::Storage { device, at, action } => {
let id = resolve(node, device)?;
if !at.is_empty() {
@@ -3850,7 +3887,14 @@ fn print_event(node: &Node, event: &NodeEvent) {
NodeEvent::NotificationRemoved { device, .. } => {
println!("{}: a notification went away", name(device))
}
- NodeEvent::ClipboardReceived { device } => println!("{}: sent its clipboard", name(device)),
+ NodeEvent::ClipboardReceived { device } => {
+ let chip = node
+ .last_clip_suggestion()
+ .filter(|(from, _)| from == device)
+ .map(|(_, s)| format!(" [chip: {} ({})]", s.action_label(), s.kind.as_str()))
+ .unwrap_or_default();
+ println!("{}: sent its clipboard{chip}", name(device));
+ }
NodeEvent::Call { device, call } => println!(
"{}: {} call {} {}{}{}",
name(device),
@@ -4019,18 +4063,26 @@ 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 vol = if state.muted { format!("muted ({}%)", state.volume) } 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}")
+ let out = state.default_output_name().map(|n| format!(" output={n:?}")).unwrap_or_default();
+ format!("vol={vol} mic={mic} media={media}{out}")
}
fn print_deck(layout: &nectarlink_core::DeckLayout, state: &nectarlink_core::DeckState) {
println!("State: {}", summarize_deck_state(state));
+ if !state.output_devices.is_empty() {
+ println!("Audio outputs:");
+ for d in &state.output_devices {
+ let mark = if d.is_default { "* " } else { " " };
+ println!(" {mark}{}", d.name);
+ }
+ }
for (idx, page) in layout.pages.iter().enumerate() {
if idx > 0 {
println!();
diff --git a/core/nectarlink-core/src/clip_kind.rs b/core/nectarlink-core/src/clip_kind.rs
new file mode 100644
index 0000000..2ca62fa
--- /dev/null
+++ b/core/nectarlink-core/src/clip_kind.rs
@@ -0,0 +1,1071 @@
+// SPDX-License-Identifier: MPL-2.0
+//! Smart clipboard classification ("context chips").
+//!
+//! Inspects plain-text clipboard items and suggests at most one fitting
+//! action (`Open`, `Open in Maps`, `Call`, `Track`, `Email`). One-time
+//! verification codes ([`crate::otp::is_otp_clip`]) keep their own handling
+//! and never produce a chip.
+//!
+//! Privacy: [`ClipSuggestion`]'s [`fmt::Debug`] implementation intentionally
+//! prints only the [`ClipKind`], never the clipboard text or target.
+
+use std::fmt;
+
+use serde::{Deserialize, Serialize};
+
+/// Kind of actionable content recognized in a plain-text clipboard item.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum ClipKind {
+ /// `http://` or `https://` web link -> `"Open"`.
+ WebLink,
+ /// Street address -> `"Open in Maps"`.
+ StreetAddress,
+ /// Phone number -> `"Call"`.
+ PhoneNumber,
+ /// Parcel tracking number from a known carrier format -> `"Track"`.
+ TrackingNumber,
+ /// Email address -> `"Email"`.
+ Email,
+}
+
+impl ClipKind {
+ /// Short chip label shown on the confirmation toast or banner.
+ pub fn action_label(self) -> &'static str {
+ match self {
+ Self::WebLink => "Open",
+ Self::StreetAddress => "Open in Maps",
+ Self::PhoneNumber => "Call",
+ Self::TrackingNumber => "Track",
+ Self::Email => "Email",
+ }
+ }
+
+ /// Stable snake_case identifier for QML/Kotlin bridges and logs.
+ pub fn as_str(self) -> &'static str {
+ match self {
+ Self::WebLink => "web_link",
+ Self::StreetAddress => "street_address",
+ Self::PhoneNumber => "phone_number",
+ Self::TrackingNumber => "tracking_number",
+ Self::Email => "email",
+ }
+ }
+}
+
+/// Actionable suggestion for a plain-text clipboard item.
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct ClipSuggestion {
+ pub kind: ClipKind,
+ /// Normalized action target:
+ /// - [`ClipKind::WebLink`]: full `http://` or `https://` URL
+ /// - [`ClipKind::StreetAddress`]: single-line street address
+ /// - [`ClipKind::PhoneNumber`]: dialable phone number (`+` and digits)
+ /// - [`ClipKind::TrackingNumber`]: uppercase tracking code
+ /// - [`ClipKind::Email`]: email address (`user@domain`)
+ pub target: String,
+}
+
+impl ClipSuggestion {
+ /// Short chip label shown on the confirmation toast or banner.
+ pub fn action_label(&self) -> &'static str {
+ self.kind.action_label()
+ }
+}
+
+impl fmt::Debug for ClipSuggestion {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("ClipSuggestion").field("kind", &self.kind).finish_non_exhaustive()
+ }
+}
+
+/// Maximum clipboard text length considered for smart suggestions.
+const MAX_CLIP_LEN: usize = 512;
+
+/// Classifies `text` and returns at most one [`ClipSuggestion`].
+///
+/// Returns `None` for empty strings, long prose, file paths, currency amounts,
+/// dates, ordinary numbers, and one-time verification codes.
+pub fn classify_clip(text: &str) -> Option<ClipSuggestion> {
+ let trimmed = text.trim();
+ if trimmed.is_empty() || trimmed.len() > MAX_CLIP_LEN {
+ return None;
+ }
+
+ // One-time verification codes keep their own handling and get no chip.
+ if crate::otp::is_otp_clip(trimmed) {
+ return None;
+ }
+
+ if let Some(url) = detect_web_link(trimmed) {
+ return Some(ClipSuggestion { kind: ClipKind::WebLink, target: url });
+ }
+ if let Some(email) = detect_email(trimmed) {
+ return Some(ClipSuggestion { kind: ClipKind::Email, target: email });
+ }
+ if let Some(tracking) = detect_tracking_number(trimmed) {
+ return Some(ClipSuggestion { kind: ClipKind::TrackingNumber, target: tracking });
+ }
+ if let Some(phone) = detect_phone_number(trimmed) {
+ return Some(ClipSuggestion { kind: ClipKind::PhoneNumber, target: phone });
+ }
+ if let Some(address) = detect_street_address(trimmed) {
+ return Some(ClipSuggestion { kind: ClipKind::StreetAddress, target: address });
+ }
+
+ None
+}
+
+/// Builds a web search URL for a parcel tracking number (no carrier-specific APIs).
+pub fn tracking_search_url(tracking_number: &str) -> String {
+ format!("https://www.google.com/search?q={}", percent_encode(tracking_number.trim()))
+}
+
+/// Builds a web Maps search URL for a street address.
+pub fn maps_web_url(address: &str) -> String {
+ format!("https://www.google.com/maps/search/?api=1&query={}", percent_encode(address.trim()))
+}
+
+/// Percent-encodes a UTF-8 query parameter component (RFC 3986 unreserved characters kept).
+pub fn percent_encode(input: &str) -> String {
+ let mut out = String::with_capacity(input.len() + 16);
+ for &b in input.as_bytes() {
+ match b {
+ b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
+ out.push(b as char);
+ }
+ b' ' => out.push_str("%20"),
+ _ => {
+ use std::fmt::Write;
+ let _ = write!(&mut out, "%{b:02X}");
+ }
+ }
+ }
+ out
+}
+
+fn detect_web_link(s: &str) -> Option<String> {
+ if s.chars().any(|c| c.is_whitespace() || c.is_control() || c == '\\') {
+ return None;
+ }
+ // Reject Windows drive paths (`C:/foo`), UNC paths, and Unix paths.
+ if s.starts_with('/') || s.starts_with('~') {
+ return None;
+ }
+ if s.len() >= 3
+ && s.as_bytes()[0].is_ascii_alphabetic()
+ && s.as_bytes()[1] == b':'
+ && s.as_bytes()[2] == b'/'
+ {
+ return None;
+ }
+
+ let (normalized, rest) = if let Some(r) = strip_ascii_case_prefix(s, "https://") {
+ (format!("https://{r}"), r)
+ } else if let Some(r) = strip_ascii_case_prefix(s, "http://") {
+ (format!("http://{r}"), r)
+ } else {
+ let r = strip_ascii_case_prefix(s, "www.")?;
+ (format!("https://www.{r}"), s)
+ };
+
+ let host_port = rest.split(['/', '?', '#']).next().unwrap_or("");
+ let host = host_port.split('@').next_back().unwrap_or(host_port);
+ let host = if host.starts_with('[') {
+ // IPv6 literal
+ host.split(']').next().map(|h| &h[1..]).unwrap_or("")
+ } else {
+ host.split(':').next().unwrap_or("")
+ };
+ if !is_valid_url_host(host) {
+ return None;
+ }
+ Some(normalized)
+}
+
+fn strip_ascii_case_prefix<'a>(s: &'a str, prefix: &str) -> Option<&'a str> {
+ if s.len() >= prefix.len() && s[..prefix.len()].eq_ignore_ascii_case(prefix) {
+ Some(&s[prefix.len()..])
+ } else {
+ None
+ }
+}
+
+fn is_valid_url_host(host: &str) -> bool {
+ if host.is_empty() || host.len() > 253 {
+ return false;
+ }
+ if host.eq_ignore_ascii_case("localhost") {
+ return true;
+ }
+ if host.starts_with('.') || host.ends_with('.') || !host.contains('.') {
+ return false;
+ }
+ let labels: Vec<&str> = host.split('.').collect();
+ if labels.len() < 2 {
+ return false;
+ }
+ let all_digits = labels.iter().all(|l| !l.is_empty() && l.bytes().all(|b| b.is_ascii_digit()));
+ if all_digits {
+ // IPv4 address: 4 octets 0..=255
+ return labels.len() == 4 && labels.iter().all(|l| l.parse::<u8>().is_ok());
+ }
+ for label in &labels {
+ if label.is_empty()
+ || label.len() > 63
+ || label.starts_with('-')
+ || label.ends_with('-')
+ || !label.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-')
+ {
+ return false;
+ }
+ }
+ let tld = labels.last().copied().unwrap_or("");
+ tld.len() >= 2 && tld.bytes().all(|b| b.is_ascii_alphabetic())
+}
+
+fn detect_email(s: &str) -> Option<String> {
+ let raw = strip_ascii_case_prefix(s, "mailto:").unwrap_or(s);
+ // Strip optional mailto query string if mailto: was used.
+ let candidate = if s.len() != raw.len() { raw.split('?').next().unwrap_or(raw) } else { raw };
+ if candidate.is_empty()
+ || candidate.len() > 254
+ || candidate.chars().any(|c| c.is_whitespace() || c.is_control())
+ || candidate.contains('/')
+ || candidate.contains('\\')
+ || candidate.contains(':')
+ {
+ return None;
+ }
+ let (local, domain) = candidate.split_once('@')?;
+ if domain.contains('@') {
+ return None;
+ }
+ if local.is_empty()
+ || local.len() > 64
+ || local.starts_with('.')
+ || local.ends_with('.')
+ || local.contains("..")
+ || !local.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b'_' | b'%' | b'+' | b'-'))
+ {
+ return None;
+ }
+ if !is_valid_url_host(domain) || domain.eq_ignore_ascii_case("localhost") {
+ return None;
+ }
+ let labels: Vec<&str> = domain.split('.').collect();
+ let tld = labels.last().copied().unwrap_or("");
+ if tld.len() < 2 || !tld.bytes().all(|b| b.is_ascii_alphabetic()) {
+ return None;
+ }
+ // Reject common image/source filenames like `[email protected]` or `[email protected]`.
+ if matches!(
+ tld.to_ascii_lowercase().as_str(),
+ "png" | "jpg" | "jpeg" | "gif" | "webp" | "svg" | "bmp" | "ico" | "pdf" | "zip" | "exe" | "dll"
+ ) {
+ return None;
+ }
+ Some(candidate.to_owned())
+}
+
+/// ISO-3166-1 alpha-2 country codes commonly used at the end of UPU S10 tracking numbers.
+const S10_COUNTRY_CODES: &[&str] = &[
+ "AD", "AE", "AR", "AT", "AU", "BE", "BG", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CY", "CZ", "DE",
+ "DK", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "HK", "HR", "HU", "ID", "IE", "IL", "IN", "IS", "IT",
+ "JP", "KR", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NL", "NO", "NZ", "PE", "PH", "PK", "PL", "PT",
+ "RO", "RS", "RU", "SA", "SE", "SG", "SI", "SK", "TH", "TR", "TW", "UA", "US", "UY", "VN", "ZA",
+];
+
+fn detect_tracking_number(s: &str) -> Option<String> {
+ if s.contains('\n') || s.contains('\r') {
+ return None;
+ }
+ // Allow only ASCII alphanumeric, spaces, and hyphens, with at most 4 separator runs.
+ if !s.bytes().all(|b| b.is_ascii_alphanumeric() || b == b' ' || b == b'-') {
+ return None;
+ }
+ if s.starts_with('-') || s.ends_with('-') {
+ return None;
+ }
+ let compact: String =
+ s.bytes().filter(|b| b.is_ascii_alphanumeric()).map(|b| (b as char).to_ascii_uppercase()).collect();
+ if compact.len() < 12 || compact.len() > 26 {
+ return None;
+ }
+
+ // 1. UPS: `1Z` + 16 alphanumeric characters (total 18), containing at least 8 digits.
+ if compact.len() == 18
+ && compact.starts_with("1Z")
+ && compact[2..].bytes().all(|b| b.is_ascii_alphanumeric())
+ && compact[2..].bytes().filter(|b| b.is_ascii_digit()).count() >= 8
+ {
+ return Some(compact);
+ }
+
+ // 2. UPU S10 international postal format: 2 letters + 9 digits + 2-letter ISO country code (total 13).
+ // Valid S10 service indicator first letters: A..=Z (standard postal services use C, E, H, L, R, S, U, V).
+ if compact.len() == 13 {
+ let bytes = compact.as_bytes();
+ let first_two_alpha = bytes[0].is_ascii_uppercase() && bytes[1].is_ascii_uppercase();
+ let middle_nine_digits = bytes[2..11].iter().all(|b| b.is_ascii_digit());
+ let country = &compact[11..13];
+ let service = bytes[0];
+ if first_two_alpha
+ && middle_nine_digits
+ && matches!(service, b'C' | b'E' | b'H' | b'L' | b'R' | b'S' | b'U' | b'V')
+ && S10_COUNTRY_CODES.binary_search(&country).is_ok()
+ {
+ return Some(compact);
+ }
+ }
+
+ // 3. Amazon Logistics: `TBA` + 12 digits (15 chars).
+ if compact.len() == 15 && compact.starts_with("TBA") && compact[3..].bytes().all(|b| b.is_ascii_digit()) {
+ return Some(compact);
+ }
+
+ // 4. FedEx Door Tag: `DT` + 12 digits (14 chars), or LaserShip `1LS` + 12 digits (15 chars).
+ if (compact.len() == 14 && compact.starts_with("DT") && compact[2..].bytes().all(|b| b.is_ascii_digit()))
+ || (compact.len() == 15
+ && compact.starts_with("1LS")
+ && compact[3..].bytes().all(|b| b.is_ascii_digit()))
+ {
+ return Some(compact);
+ }
+
+ // 5. DHL Germany / Europe parcel (`JJD` + 10..=18 digits) or DHL eCommerce (`GM` + 16..=18 digits).
+ if let Some(rest) = compact.strip_prefix("JJD")
+ && (10..=18).contains(&rest.len())
+ && rest.bytes().all(|b| b.is_ascii_digit())
+ {
+ return Some(compact);
+ }
+ if let Some(rest) = compact.strip_prefix("GM")
+ && (16..=18).contains(&rest.len())
+ && rest.bytes().all(|b| b.is_ascii_digit())
+ {
+ return Some(compact);
+ }
+
+ // 6. USPS domestic (20..=22 digits starting with known USPS prefixes 92, 93, 94, 95)
+ // and FedEx Ground / SmartPost 20..=22 digits starting with 9611, 9612, 9622, 6129.
+ if (20..=22).contains(&compact.len()) && compact.bytes().all(|b| b.is_ascii_digit()) {
+ let known_prefix = compact.starts_with("940")
+ || compact.starts_with("941")
+ || compact.starts_with("947")
+ || compact.starts_with("920")
+ || compact.starts_with("927")
+ || compact.starts_with("930")
+ || compact.starts_with("936")
+ || compact.starts_with("937")
+ || compact.starts_with("950")
+ || compact.starts_with("9611")
+ || compact.starts_with("9612")
+ || compact.starts_with("9622")
+ || compact.starts_with("6129");
+ // Reject trivially repetitive digit strings like `94000000000000000000` if all trailing digits are identical.
+ let non_trivial = compact.as_bytes()[4..].windows(2).any(|w| w[0] != w[1]);
+ if known_prefix && non_trivial {
+ return Some(compact);
+ }
+ }
+
+ None
+}
+
+fn detect_phone_number(s: &str) -> Option<String> {
+ if s.contains('\n') || s.contains('\r') {
+ return None;
+ }
+ let raw = strip_ascii_case_prefix(s, "tel:").map(str::trim).unwrap_or(s);
+ if raw.is_empty() || raw.len() > 32 {
+ return None;
+ }
+
+ // Reject anything with letters, currency symbols, slashes, colons, commas, or percent signs.
+ for ch in raw.chars() {
+ if !(ch.is_ascii_digit() || matches!(ch, '+' | '-' | ' ' | '(' | ')' | '.')) {
+ return None;
+ }
+ }
+
+ let has_plus = raw.starts_with('+');
+ // `+` is only valid as the very first character.
+ if raw[usize::from(has_plus)..].contains('+') {
+ return None;
+ }
+
+ // Parentheses must be balanced and contain 2..=5 digits (area code).
+ let open_parens = raw.bytes().filter(|&b| b == b'(').count();
+ let close_parens = raw.bytes().filter(|&b| b == b')').count();
+ if open_parens != close_parens || open_parens > 1 {
+ return None;
+ }
+ if open_parens == 1 {
+ let after_open = raw.split_once('(')?.1;
+ let (inside, _) = after_open.split_once(')')?;
+ let inside_digits = inside.bytes().filter(|b| b.is_ascii_digit()).count();
+ if !(2..=5).contains(&inside_digits) || !inside.bytes().all(|b| b.is_ascii_digit() || b == b' ') {
+ return None;
+ }
+ }
+
+ // Dots are only allowed in NANP `NNN.NNN.NNNN` or `+1.NNN.NNN.NNNN`, never decimals/IPs/dates.
+ let dot_count = raw.bytes().filter(|&b| b == b'.').count();
+ if dot_count > 0 {
+ let parts: Vec<&str> = raw.trim_start_matches('+').split('.').collect();
+ let valid_dot_nanp = match parts.as_slice() {
+ [a, b, c] => a.len() == 3 && b.len() == 3 && c.len() == 4,
+ ["1", a, b, c] => a.len() == 3 && b.len() == 3 && c.len() == 4,
+ _ => false,
+ } && parts.iter().all(|p| p.bytes().all(|b| b.is_ascii_digit()));
+ if !valid_dot_nanp {
+ return None;
+ }
+ }
+
+ // Reject ISO or numeric dates like `2026-10-08` or `10-08-2026`.
+ let hyphen_parts: Vec<&str> = raw.split('-').collect();
+ if hyphen_parts.len() == 3
+ && hyphen_parts.iter().all(|p| p.bytes().all(|b| b.is_ascii_digit()))
+ && ((hyphen_parts[0].len() == 4 && hyphen_parts[1].len() <= 2 && hyphen_parts[2].len() <= 2)
+ || (hyphen_parts[0].len() <= 2 && hyphen_parts[1].len() <= 2 && hyphen_parts[2].len() == 4))
+ {
+ return None;
+ }
+
+ // Reject SSN-like `NNN-NN-NNNN` (9 digits) and 8-digit hyphenated codes `NNNN-NNNN`.
+ if !has_plus
+ && hyphen_parts.len() == 3
+ && hyphen_parts[0].len() == 3
+ && hyphen_parts[1].len() == 2
+ && hyphen_parts[2].len() == 4
+ {
+ return None;
+ }
+ if !has_plus && hyphen_parts.len() == 2 && hyphen_parts[0].len() == 4 && hyphen_parts[1].len() == 4 {
+ return None;
+ }
+
+ let digits: String = raw.chars().filter(char::is_ascii_digit).collect();
+ let digit_count = digits.len();
+
+ if has_plus {
+ // International E.164: country code starts with 1..=9, total 8..=15 digits.
+ if !(8..=15).contains(&digit_count) || digits.starts_with('0') {
+ return None;
+ }
+ return Some(format!("+{digits}"));
+ }
+
+ let has_separators = raw.bytes().any(|b| matches!(b, b'-' | b' ' | b'(' | b')' | b'.'));
+ if has_separators {
+ // Formatted national / domestic number: 10..=11 digits (e.g. `(415) 555-0199`, `1-800-555-0199`, `020 7946 0958`).
+ if !(10..=11).contains(&digit_count) {
+ return None;
+ }
+ if digit_count == 11 && !digits.starts_with(['0', '1']) {
+ return None;
+ }
+ if digit_count == 10 && digits.starts_with('1') {
+ // 10-digit national numbers in NANP/IN start with 2..=9, or 0 in UK/EU/AU/JP.
+ return None;
+ }
+ return Some(digits);
+ }
+
+ // Bare unseparated digits: only accept unambiguous 10-digit national numbers starting with 2..=9
+ // (or 11-digit UK/domestic numbers starting with `07` / `01` / `02` / `03` / `04`),
+ // and reject all-identical digit runs or sequential runs.
+ let all_same = digits.as_bytes().windows(2).all(|w| w[0] == w[1]);
+ if all_same || digits == "0123456789" || digits == "1234567890" || digits == "9876543210" {
+ return None;
+ }
+ if digit_count == 10 && matches!(digits.as_bytes()[0], b'2'..=b'9') {
+ // NANP / India 10-digit mobile/landline: second-to-fourth digit should not make it look like a round integer `2000000000`.
+ let trailing_zeros = digits.bytes().rev().take_while(|&b| b == b'0').count();
+ if trailing_zeros >= 6 {
+ return None;
+ }
+ return Some(digits);
+ }
+ if digit_count == 11 && matches!(&digits[..2], "01" | "02" | "03" | "04" | "07" | "08" | "09") {
+ let trailing_zeros = digits.bytes().rev().take_while(|&b| b == b'0').count();
+ if trailing_zeros >= 6 {
+ return None;
+ }
+ return Some(digits);
+ }
+
+ None
+}
+
+/// Street/road designator words across English, French, German, Spanish, Italian, and Indian addresses.
+const STREET_DESIGNATORS: &[&str] = &[
+ "allee",
+ "allée",
+ "ave",
+ "avenida",
+ "avenue",
+ "bagh",
+ "blvd",
+ "boulevard",
+ "calle",
+ "chemin",
+ "chowk",
+ "cir",
+ "circle",
+ "close",
+ "colony",
+ "corso",
+ "court",
+ "cours",
+ "cres",
+ "crescent",
+ "ct",
+ "damm",
+ "dr",
+ "drive",
+ "enclave",
+ "gardens",
+ "gasse",
+ "grove",
+ "highway",
+ "hwy",
+ "impasse",
+ "lane",
+ "ln",
+ "marg",
+ "nagar",
+ "parkway",
+ "paseo",
+ "piazza",
+ "pkwy",
+ "pl",
+ "place",
+ "platz",
+ "puram",
+ "quai",
+ "rd",
+ "ring",
+ "road",
+ "route",
+ "rua",
+ "rue",
+ "salai",
+ "sector",
+ "sq",
+ "square",
+ "st",
+ "str",
+ "strasse",
+ "straße",
+ "street",
+ "ter",
+ "terrace",
+ "ufer",
+ "via",
+ "viale",
+ "vihar",
+ "way",
+ "weg",
+];
+
+/// Words that indicate ordinary prose / sentences rather than a street address.
+const PROSE_STOPWORDS: &[&str] = &[
+ "about",
+ "after",
+ "again",
+ "always",
+ "because",
+ "before",
+ "between",
+ "could",
+ "did",
+ "does",
+ "doing",
+ "down",
+ "during",
+ "error",
+ "every",
+ "failed",
+ "found",
+ "going",
+ "have",
+ "having",
+ "here",
+ "however",
+ "into",
+ "just",
+ "know",
+ "like",
+ "make",
+ "many",
+ "miles",
+ "minutes",
+ "more",
+ "most",
+ "much",
+ "must",
+ "need",
+ "never",
+ "only",
+ "other",
+ "over",
+ "please",
+ "really",
+ "right",
+ "said",
+ "same",
+ "should",
+ "since",
+ "some",
+ "still",
+ "such",
+ "take",
+ "than",
+ "thank",
+ "thanks",
+ "that",
+ "their",
+ "them",
+ "then",
+ "there",
+ "these",
+ "they",
+ "thing",
+ "think",
+ "this",
+ "those",
+ "through",
+ "today",
+ "tomorrow",
+ "under",
+ "until",
+ "very",
+ "wait",
+ "waited",
+ "want",
+ "warning",
+ "were",
+ "what",
+ "when",
+ "where",
+ "which",
+ "while",
+ "who",
+ "will",
+ "winner",
+ "with",
+ "would",
+ "yesterday",
+ "your",
+];
+
+fn detect_street_address(s: &str) -> Option<String> {
+ if s.len() < 8 || s.len() > 200 {
+ return None;
+ }
+ let lines: Vec<&str> = s.lines().map(str::trim).filter(|l| !l.is_empty()).collect();
+ if lines.is_empty() || lines.len() > 4 {
+ return None;
+ }
+ // Reject code, URLs, paths, emails, and shell snippets.
+ if s.contains("://")
+ || s.contains('@')
+ || s.contains('\\')
+ || s.chars()
+ .any(|c| matches!(c, '{' | '}' | '[' | ']' | '<' | '>' | ';' | '=' | '|' | '$' | '`' | '?' | '!'))
+ {
+ return None;
+ }
+
+ let normalized = lines.join(", ");
+ let words: Vec<&str> = normalized
+ .split(|c: char| c.is_whitespace() || matches!(c, ',' | '/'))
+ .filter(|w| !w.is_empty())
+ .collect();
+ if words.len() < 3 || words.len() > 24 {
+ return None;
+ }
+
+ let mut has_house_number = false;
+ let mut has_street_designator = false;
+
+ for w in &words {
+ let clean = w.trim_matches(|c: char| matches!(c, '.' | '#' | '(' | ')' | '-'));
+ if clean.is_empty() {
+ continue;
+ }
+ let lower = clean.to_lowercase();
+ if PROSE_STOPWORDS.binary_search(&lower.as_str()).is_ok() {
+ return None;
+ }
+ if is_house_number_token(clean) {
+ has_house_number = true;
+ }
+ if is_street_designator(&lower) {
+ has_street_designator = true;
+ }
+ }
+
+ if !has_house_number || !has_street_designator {
+ return None;
+ }
+
+ // Require either:
+ // (a) multi-segment address (comma or multiple lines) or postal code, OR
+ // (b) compact single-line street address (`<house_no> <Capitalized Street> <Designator> [Dir]`)
+ // or European `<StreetDesignator> <house_no>`.
+ let has_comma_or_multiline = normalized.contains(',') || lines.len() >= 2;
+ let has_postcode = has_postal_code(&normalized);
+ let first_clean = words[0].trim_matches(|c: char| matches!(c, '.' | '#'));
+ let starts_with_house_no = is_house_number_token(first_clean)
+ && words.get(1).is_some_and(|w| w.chars().next().is_some_and(char::is_uppercase));
+ let starts_with_german_street = is_street_designator(&words[0].trim_matches('.').to_lowercase())
+ && words.get(1).is_some_and(|w| is_house_number_token(w.trim_matches('.')));
+
+ if has_comma_or_multiline
+ || has_postcode
+ || (words.len() <= 7 && (starts_with_house_no || starts_with_german_street))
+ {
+ Some(normalized)
+ } else {
+ None
+ }
+}
+
+fn is_house_number_token(token: &str) -> bool {
+ if token.is_empty() || token.len() > 8 {
+ return false;
+ }
+ let bytes = token.as_bytes();
+ if !bytes[0].is_ascii_digit() || bytes[0] == b'0' {
+ return false;
+ }
+ let digit_prefix_len = bytes.iter().take_while(|b| b.is_ascii_digit()).count();
+ if !(1..=5).contains(&digit_prefix_len) {
+ return false;
+ }
+ let rest = &token[digit_prefix_len..];
+ if rest.is_empty() {
+ return true;
+ }
+ // Reject ordinals like `1st`, `2nd`, `3rd`, `4th` (e.g. `"3rd place"`), unless followed by more words.
+ if matches!(rest.to_ascii_lowercase().as_str(), "st" | "nd" | "rd" | "th") {
+ return false;
+ }
+ // Allow single letter suffix (`221B`, `10A`) or hyphenated range (`12-14`).
+ if rest.len() == 1 && rest.as_bytes()[0].is_ascii_alphabetic() {
+ return true;
+ }
+ if let Some(after_dash) = rest.strip_prefix('-') {
+ return !after_dash.is_empty()
+ && after_dash.len() <= 4
+ && after_dash.bytes().all(|b| b.is_ascii_alphanumeric());
+ }
+ false
+}
+
+fn is_street_designator(lower: &str) -> bool {
+ if STREET_DESIGNATORS.binary_search(&lower).is_ok() {
+ return true;
+ }
+ // German compound street names like `friedrichstraße`, `kurfürstendamm`, `marienplatz`, `königsallee`, `holzweg`.
+ for suffix in ["straße", "strasse", "platz", "allee", "gasse", "damm", "weg"] {
+ if lower.len() >= suffix.len() + 3 && lower.ends_with(suffix) {
+ return true;
+ }
+ }
+ false
+}
+
+fn has_postal_code(s: &str) -> bool {
+ let tokens: Vec<&str> = s
+ .split(|c: char| c.is_whitespace() || c == ',')
+ .map(|t| t.trim_matches('.'))
+ .filter(|t| !t.is_empty())
+ .collect();
+ for (i, &t) in tokens.iter().enumerate() {
+ // US 5-digit or ZIP+4 (`94043`, `94043-1351`), DE/FR 5-digit (`10117`, `75004`), IN 6-digit (`560001`).
+ if (t.len() == 5 || t.len() == 6) && t.bytes().all(|b| b.is_ascii_digit()) {
+ return true;
+ }
+ if t.len() == 10
+ && t.as_bytes()[5] == b'-'
+ && t[..5].bytes().all(|b| b.is_ascii_digit())
+ && t[6..].bytes().all(|b| b.is_ascii_digit())
+ {
+ return true;
+ }
+ // UK outward + inward (`SW1A 2AA`, `NW1 6XE`, `EC1A 1BB`) or Canadian (`M5V 2T6`, `M5H 2N2`).
+ if let Some(&next) = tokens.get(i + 1)
+ && next.len() == 3
+ && next.as_bytes()[0].is_ascii_digit()
+ && next.as_bytes()[1].is_ascii_alphabetic()
+ && next.as_bytes()[2].is_ascii_alphabetic()
+ && (2..=4).contains(&t.len())
+ && t.as_bytes()[0].is_ascii_alphabetic()
+ && t.bytes().any(|b| b.is_ascii_digit())
+ {
+ return true;
+ }
+ if let Some(&next) = tokens.get(i + 1)
+ && t.len() == 3
+ && next.len() == 3
+ && t.as_bytes()[0].is_ascii_alphabetic()
+ && t.as_bytes()[1].is_ascii_digit()
+ && t.as_bytes()[2].is_ascii_alphabetic()
+ && next.as_bytes()[0].is_ascii_digit()
+ && next.as_bytes()[1].is_ascii_alphabetic()
+ && next.as_bytes()[2].is_ascii_digit()
+ {
+ return true;
+ }
+ }
+ false
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn web_links_vs_file_paths_and_text() {
+ let positives = [
+ ("https://nectarlink.app/docs?tab=1#top", "https://nectarlink.app/docs?tab=1#top"),
+ (" http://example.com/path/to/page ", "http://example.com/path/to/page"),
+ ("HTTPS://github.com/thtbee/nectarlink", "https://github.com/thtbee/nectarlink"),
+ (
+ "www.wikipedia.org/wiki/Rust_(programming_language)",
+ "https://www.wikipedia.org/wiki/Rust_(programming_language)",
+ ),
+ ("http://192.168.1.1:8080/admin", "http://192.168.1.1:8080/admin"),
+ ("http://localhost:3000/api/health", "http://localhost:3000/api/health"),
+ ];
+ for (input, expected) in positives {
+ let got = classify_clip(input);
+ assert_eq!(
+ got,
+ Some(ClipSuggestion { kind: ClipKind::WebLink, target: expected.into() }),
+ "expected WebLink for {input:?}"
+ );
+ }
+
+ let negatives = [
+ r"C:\Users\anive\Documents\report.pdf",
+ "C:/Users/anive/Documents/report.pdf",
+ r"\\server\share\folder\file.txt",
+ "/usr/local/bin/nectarlink",
+ "~/Downloads/photo.jpg",
+ "file:///C:/Users/anive/test.html",
+ "ftp://files.example.com/pub/archive.zip",
+ "https://",
+ "http://not_a_host",
+ "Check out https://example.com and let me know",
+ ];
+ for input in negatives {
+ let got = classify_clip(input);
+ assert_ne!(
+ got.as_ref().map(|s| s.kind),
+ Some(ClipKind::WebLink),
+ "should not classify {input:?} as WebLink"
+ );
+ }
+ }
+
+ #[test]
+ fn emails_vs_handles_and_filenames() {
+ let positives = [
+ ("mailto:[email protected]?subject=Invoice", "[email protected]"),
+ ];
+ for (input, expected) in positives {
+ let got = classify_clip(input);
+ assert_eq!(
+ got,
+ Some(ClipSuggestion { kind: ClipKind::Email, target: expected.into() }),
+ "expected Email for {input:?}"
+ );
+ }
+
+ let negatives = [
+ "@username",
+ "[email protected]:thtbee/nectarlink.git",
+ "user@localhost",
+ "user@@example.com",
+ "user@example",
+ ];
+ for input in negatives {
+ let got = classify_clip(input);
+ assert_eq!(got, None, "expected None for {input:?}, got {got:?}");
+ }
+ }
+
+ #[test]
+ fn phone_numbers_vs_amounts_dates_and_otps() {
+ let positives = [
+ ("+1 (415) 555-0199", "+14155550199"),
+ ("+15550100", "+15550100"),
+ ("+44 20 7946 0958", "+442079460958"),
+ ("+91 98765 43210", "+919876543210"),
+ ("+49 30 901820", "+4930901820"),
+ ("(415) 555-0199", "4155550199"),
+ ("415-555-0199", "4155550199"),
+ ("415.555.0199", "4155550199"),
+ ("1-800-555-0199", "18005550199"),
+ ("020 7946 0958", "02079460958"),
+ ("9845012345", "9845012345"),
+ ("tel:+1-800-555-0130", "+18005550130"),
+ ];
+ for (input, expected) in positives {
+ let got = classify_clip(input);
+ assert_eq!(
+ got,
+ Some(ClipSuggestion { kind: ClipKind::PhoneNumber, target: expected.into() }),
+ "expected PhoneNumber for {input:?}"
+ );
+ }
+
+ let negatives = [
+ // One-time codes (must get no chip!)
+ "482910",
+ "739-201",
+ "G-582910",
+ "Your verification code is 839201",
+ // Hyphenated 8-digit non-OTP
+ "1234-5678",
+ // SSN
+ "123-45-6789",
+ // Dates & times
+ "2026-10-08",
+ "08-10-2026",
+ "2026.10.08",
+ "10/08/2026",
+ // Currency amounts & decimals
+ "$1,234,567.89",
+ "12,345,678",
+ "€49.99",
+ "₹1,50,000",
+ "123456.78",
+ // IPv4 & versions
+ "192.168.1.100",
+ "10.0.0.1",
+ // Unix timestamps / bare 10-digit starting with 1 / round or sequential numbers
+ "1700000000",
+ "2000000000",
+ "1234567890",
+ "9876543210",
+ "0000000000",
+ ];
+ for input in negatives {
+ let got = classify_clip(input);
+ assert_eq!(got, None, "expected None for {input:?}, got {got:?}");
+ }
+ }
+
+ #[test]
+ fn tracking_numbers_vs_ordinary_long_numbers() {
+ let positives = [
+ // UPS
+ ("1Z999AA10123456784", "1Z999AA10123456784"),
+ ("1z 999 aa1 01 2345 6784", "1Z999AA10123456784"),
+ // USPS 20-22 digits
+ ("9400 1000 0000 0000 0000 12", "9400100000000000000012"),
+ ("9205590175547700001234", "9205590175547700001234"),
+ // UPU S10 international (US, UK, DE, IN, CA, JP)
+ ("EA123456789US", "EA123456789US"),
+ ("RR 987 654 321 GB", "RR987654321GB"),
+ ("CE123456789DE", "CE123456789DE"),
+ ("EE123456789IN", "EE123456789IN"),
+ ("LX123456789CA", "LX123456789CA"),
+ // Amazon Logistics
+ ("TBA123456789012", "TBA123456789012"),
+ // FedEx Door Tag & Ground 22-digit
+ ("DT123456789012", "DT123456789012"),
+ ("9612019999999999999912", "9612019999999999999912"),
+ // DHL Germany / eCommerce
+ ("JJD0003900012345678", "JJD0003900012345678"),
+ ];
+ for (input, expected) in positives {
+ let got = classify_clip(input);
+ assert_eq!(
+ got,
+ Some(ClipSuggestion { kind: ClipKind::TrackingNumber, target: expected.into() }),
+ "expected TrackingNumber for {input:?}"
+ );
+ }
+
+ let negatives = [
+ // Ordinary long numbers, credit cards, bank accounts, IMEI
+ "123456789012",
+ "123456789012345",
+ "4111 1111 1111 1111",
+ "4532-0151-1283-0366",
+ "12345678901234567890",
+ // Random 13-char string with non-country suffix
+ "AB123456789ZZ",
+ "XY123456789US",
+ ];
+ for input in negatives {
+ let got = classify_clip(input);
+ assert_eq!(got, None, "expected None for {input:?}, got {got:?}");
+ }
+ }
+
+ #[test]
+ fn street_addresses_across_countries_vs_sentences() {
+ let positives = [
+ // US
+ "1600 Amphitheatre Parkway, Mountain View, CA 94043",
+ "350 Fifth Avenue\nNew York, NY 10118",
+ "742 Evergreen Terrace",
+ // UK
+ "221B Baker Street, London NW1 6XE",
+ "10 Downing Street, London, SW1A 2AA",
+ // Canada
+ "100 Queen St W, Toronto, ON M5H 2N2",
+ // Germany
+ "Friedrichstraße 123, 10117 Berlin",
+ "Marienplatz 1, 80331 München",
+ // France
+ "24 Rue de Rivoli, 75004 Paris",
+ // India
+ "42 MG Road, Bengaluru, Karnataka 560001",
+ // Australia
+ "300 George St, Sydney NSW 2000",
+ ];
+ for input in positives {
+ let got = classify_clip(input);
+ assert_eq!(
+ got.as_ref().map(|s| s.kind),
+ Some(ClipKind::StreetAddress),
+ "expected StreetAddress for {input:?}, got {got:?}"
+ );
+ }
+
+ let negatives = [
+ "I drove 2 miles down the road",
+ "3rd place winner in the tournament",
+ "Please wait 5 minutes on the way",
+ "Meeting at 3pm tomorrow",
+ "let x = 100; // main street variable",
+ "Error at line 42: connection reset by peer",
+ ];
+ for input in negatives {
+ let got = classify_clip(input);
+ assert_eq!(got, None, "expected None for {input:?}, got {got:?}");
+ }
+ }
+
+ #[test]
+ fn debug_does_not_leak_target() {
+ let s = ClipSuggestion { kind: ClipKind::PhoneNumber, target: "+14155550199".into() };
+ let dbg = format!("{s:?}");
+ assert!(dbg.contains("PhoneNumber"));
+ assert!(!dbg.contains("4155550199"), "Debug leaked target: {dbg}");
+ }
+}
diff --git a/core/nectarlink-core/src/clipboard.rs b/core/nectarlink-core/src/clipboard.rs
index 65e4cbc..819433c 100644
--- a/core/nectarlink-core/src/clipboard.rs
+++ b/core/nectarlink-core/src/clipboard.rs
@@ -46,6 +46,12 @@ pub(crate) async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: &E
if shared.clipboard_history.record_text(&text, &peer_name, true) {
shared.emit(NodeEvent::ClipboardHistoryChanged);
}
+ let suggestion = crate::clip_kind::classify_clip(&text);
+ if let Some(ref s) = suggestion {
+ tracing::debug!(from = %peer.short(), kind = ?s.kind, "classified received clipboard text");
+ }
+ *shared.last_clip_suggestion.lock().unwrap_or_else(|e| e.into_inner()) =
+ suggestion.map(|s| (peer, s));
shared.emit(NodeEvent::ClipboardReceived { device: peer });
Envelope::empty(types::OK)
}
diff --git a/core/nectarlink-core/src/config.rs b/core/nectarlink-core/src/config.rs
index eabfab1..d678589 100644
--- a/core/nectarlink-core/src/config.rs
+++ b/core/nectarlink-core/src/config.rs
@@ -294,6 +294,18 @@ pub trait Platform: Send + Sync + 'static {
Err("this device has no deck actions".into())
}
+ /// Change this PC's master speaker volume (`0..=100`) and/or mute state
+ /// (`pc.audio.set`, `docs/protocol/deck.md` §2.5). `volume` and `muted`
+ /// have been validated and the per-device permission checked.
+ fn set_pc_audio(
+ &self,
+ _from: &nectarlink_protocol::DeviceId,
+ _volume: Option<u8>,
+ _muted: Option<bool>,
+ ) -> Result<(), String> {
+ Err("this device has no PC audio controls".into())
+ }
+
/// List immediate children of `path` (`""` for the shared storage root) on
/// this phone (`storage.list`, `docs/protocol/storage.md`).
fn storage_list(&self, _path: &str) -> Result<Vec<crate::StorageEntry>, crate::StorageError> {
diff --git a/core/nectarlink-core/src/deck.rs b/core/nectarlink-core/src/deck.rs
index e471e14..65e048f 100644
--- a/core/nectarlink-core/src/deck.rs
+++ b/core/nectarlink-core/src/deck.rs
@@ -14,10 +14,10 @@ use std::{
};
pub use nectarlink_protocol::messages::{
- DeckLayout, DeckPage, DeckPress, DeckState, DeckTile, KeyMod,
+ AudioOutputDevice, DeckLayout, DeckPage, DeckPress, DeckState, DeckTile, KeyMod, PcAudioSet,
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,
+ MAX_PAGES as MAX_DECK_PAGES, MAX_TILES_PER_PAGE as MAX_DECK_TILES_PER_PAGE, PC_AUDIO,
},
deck_colors, deck_icons, deck_kinds, is_valid_deck_id, remote_keys,
};
@@ -519,19 +519,24 @@ impl Shared {
self.local_capabilities().iter().any(|c| c == DECK_ACTIONS)
}
+ fn offers_pc_audio(&self) -> bool {
+ self.local_capabilities().iter().any(|c| c == PC_AUDIO)
+ }
+
/// Sends this PC's Deck layout and live state to `session` if this device
- /// offers `deck.actions`.
+ /// offers `deck.actions` or `pc.audio`.
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;
+ if self.offers_deck() {
+ 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;
+ if self.offers_deck() || self.offers_pc_audio() {
+ let state = self.deck.local_state();
+ if let Ok(env) = Envelope::new(types::DECK_STATE, &state) {
+ let _ = session.send(env).await;
+ }
}
}
@@ -555,7 +560,7 @@ impl Shared {
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()
+ && (self.offers_deck() || self.offers_pc_audio())
&& let Ok(env) = Envelope::new(types::DECK_STATE, &clean)
{
for session in self.live_sessions() {
@@ -581,7 +586,28 @@ pub(crate) async fn press(shared: &Arc<Shared>, session: &Arc<Session>, tile: St
Ok(())
}
-/// Handles `deck.layout`, `deck.state`, and `deck.press`.
+/// Asks a paired PC to change its master speaker volume (`0..=100`) and/or mute
+/// state (`pc.audio.set`).
+pub(crate) async fn set_pc_audio(
+ shared: &Arc<Shared>,
+ session: &Arc<Session>,
+ volume: Option<u8>,
+ muted: Option<bool>,
+) -> Result<()> {
+ let req = PcAudioSet { volume, muted };
+ if !req.is_valid() {
+ return Err(Error::Protocol("invalid PC audio request".into()));
+ }
+ let peer_caps = shared.store.get_peer(&session.peer)?.map(|p| p.caps).unwrap_or_default();
+ if !peer_caps.contains(PC_AUDIO) && !peer_caps.contains(DECK_ACTIONS) {
+ return Err(Error::Unsupported);
+ }
+ let env = Envelope::new(types::PC_AUDIO_SET, &req)?;
+ session.request(env, REQUEST_TIMEOUT).await?.expect(types::OK)?;
+ Ok(())
+}
+
+/// Handles `deck.layout`, `deck.state`, `deck.press`, and `pc.audio.set`.
pub(crate) async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: &Envelope) -> Result<bool> {
let peer = session.peer;
match env.t.as_str() {
@@ -604,11 +630,54 @@ pub(crate) async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: &E
let reply = run_press(shared, &peer, req).await;
session.send(reply.reply_to(env.id)).await?;
}
+ types::PC_AUDIO_SET => {
+ let reply = match env.body::<PcAudioSet>() {
+ Ok(req) => run_pc_audio_set(shared, &peer, req).await,
+ Err(_) => Envelope::error(ErrorCode::BadMessage, "invalid pc.audio.set body"),
+ };
+ session.send(reply.reply_to(env.id)).await?;
+ }
_ => return Ok(false),
}
Ok(true)
}
+async fn run_pc_audio_set(shared: &Arc<Shared>, peer: &DeviceId, req: PcAudioSet) -> Envelope {
+ if !req.is_valid() {
+ return Envelope::error(ErrorCode::BadMessage, "invalid volume or mute");
+ }
+ if !shared.offers_pc_audio() && !shared.offers_deck() {
+ return Envelope::error(ErrorCode::Unsupported, "PC audio control is not supported here");
+ }
+ if !shared.toggle_on(peer, crate::actions::POWER_TOGGLE) && !shared.toggle_on(peer, INPUT_TOGGLE) {
+ return Envelope::error(ErrorCode::Denied, "PC actions are turned off for this device");
+ }
+ let platform = shared.platform.clone();
+ let from = *peer;
+ let vol = req.volume;
+ let muted = req.muted;
+ let ran = tokio::task::spawn_blocking(move || platform.set_pc_audio(&from, vol, muted))
+ .await
+ .unwrap_or_else(|e| Err(e.to_string()));
+ match ran {
+ Ok(()) => {
+ let mut state = shared.deck.local_state();
+ if let Some(v) = vol {
+ state.volume = v.min(100);
+ }
+ if let Some(m) = muted {
+ state.muted = m;
+ }
+ let _ = shared.set_deck_state(state).await;
+ Envelope::empty(types::OK)
+ }
+ Err(reason) => {
+ tracing::warn!(reason, "pc.audio.set failed");
+ Envelope::error(ErrorCode::Internal, "failed")
+ }
+ }
+}
+
async fn run_press(shared: &Arc<Shared>, peer: &DeviceId, req: DeckPress) -> Envelope {
if !req.is_valid() {
return Envelope::error(ErrorCode::BadMessage, "invalid tile ID");
diff --git a/core/nectarlink-core/src/features.rs b/core/nectarlink-core/src/features.rs
index b81deba..f1a03b1 100644
--- a/core/nectarlink-core/src/features.rs
+++ b/core/nectarlink-core/src/features.rs
@@ -844,6 +844,12 @@ pub const FEATURES: &[FeatureDef] = &[
requires: &[desktop("media.control", UPDATE), phone("media.remote", UPDATE), DeviceToggle("media")],
partial: None,
},
+ FeatureDef {
+ id: "media.pc_audio",
+ group: FeatureGroup::Media,
+ requires: &[desktop("pc.audio", UPDATE), DeviceToggle("pc_actions")],
+ partial: None,
+ },
// Camera
FeatureDef {
id: "camera.webcam",
@@ -927,6 +933,7 @@ mod tests {
];
const PC: &[&str] = &[
"pc.power",
+ "pc.audio",
"files.transfer",
"files.browse",
"recorder",
diff --git a/core/nectarlink-core/src/lib.rs b/core/nectarlink-core/src/lib.rs
index f196b70..ab7da1a 100644
--- a/core/nectarlink-core/src/lib.rs
+++ b/core/nectarlink-core/src/lib.rs
@@ -8,6 +8,7 @@
mod actions;
mod calls;
+pub mod clip_kind;
mod clipboard;
pub mod clipboard_history;
mod config;
@@ -35,12 +36,15 @@ pub mod webcam;
pub use actions::{PC_WAKE, PowerAction};
pub use calls::CallCommand;
+pub use clip_kind::{
+ ClipKind, ClipSuggestion, classify_clip, maps_web_url, percent_encode, tracking_search_url,
+};
pub use clipboard_history::{ClipboardHistoryEntry, ClipboardItemKind, MAX_CLIPBOARD_HISTORY};
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,
+ MAX_DECK_ID_BYTES, MAX_DECK_LABEL_BYTES, MAX_DECK_PAGES, MAX_DECK_TILES_PER_PAGE, PC_AUDIO, 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,
};
@@ -58,13 +62,13 @@ pub use nectarlink_protocol::messages::clip::{
pub use nectarlink_protocol::{
DeviceId, PacketKind,
messages::{
- Battery, CLIP_MAX_BYTES, CallControls, CallLogEntry, CallState, Contact, ContactNumber, DeviceInfo,
- DeviceKind, MediaPlayer, MirrorAudioConfig, MirrorConfig, MirrorInput, MirrorResize, MirrorStart,
- Notification, NotificationAction, PcWakeInfo, PhoneApp, PhoneToggleSet, PhoneToggleValue,
- PhoneToggles, PhotoAlbum, PhotoItem, PhotoNew as Photo, PhotoThumb, PowerLevel, SmsMessage, SmsPart,
- SmsThread, StorageChanged, StorageDelete, StorageEntries, StorageEntry, StorageList, StorageMkdir,
- StorageRead, StorageReadMeta, StorageRename, StorageWriteAccept, StorageWriteDone, StorageWriteOffer,
- TouchAction, WebcamConfig, WebcamStart,
+ AudioOutputDevice, Battery, CLIP_MAX_BYTES, CallControls, CallLogEntry, CallState, Contact,
+ ContactNumber, DeviceInfo, DeviceKind, MediaPlayer, MirrorAudioConfig, MirrorConfig, MirrorInput,
+ MirrorResize, MirrorStart, Notification, NotificationAction, PcAudioSet, PcWakeInfo, PhoneApp,
+ PhoneToggleSet, PhoneToggleValue, PhoneToggles, PhotoAlbum, PhotoItem, PhotoNew as Photo, PhotoThumb,
+ PowerLevel, SmsMessage, SmsPart, SmsThread, StorageChanged, StorageDelete, StorageEntries,
+ StorageEntry, StorageList, StorageMkdir, StorageRead, StorageReadMeta, StorageRename,
+ StorageWriteAccept, StorageWriteDone, StorageWriteOffer, TouchAction, WebcamConfig, WebcamStart,
calls::{
CONTROL as CALLS_CONTROL, DIAL as CALLS_DIAL, IN_CALL as CALLS_IN_CALL, LOG as CALLS_LOG,
SHOW as CALLS_SHOW, STATE as CALLS_STATE,
diff --git a/core/nectarlink-core/src/node.rs b/core/nectarlink-core/src/node.rs
index 3990056..bcc56ba 100644
--- a/core/nectarlink-core/src/node.rs
+++ b/core/nectarlink-core/src/node.rs
@@ -136,6 +136,8 @@ pub(crate) struct Shared {
pub(crate) storage: Mutex<crate::storage::StorageState>,
/// Encrypted-at-rest history of the last 50 clips exchanged with peers.
pub(crate) clipboard_history: crate::clipboard_history::ClipboardHistoryStore,
+ /// Smart suggestion for the most recently received text clip, if any.
+ pub(crate) last_clip_suggestion: Mutex<Option<(DeviceId, crate::ClipSuggestion)>>,
pub data_dir: std::path::PathBuf,
/// Where received files go.
pub downloads_dir: std::path::PathBuf,
@@ -669,6 +671,7 @@ impl Node {
remote: Mutex::new(Default::default()),
storage: Mutex::new(Default::default()),
clipboard_history,
+ last_clip_suggestion: Mutex::new(None),
data_dir: config.data_dir.clone(),
downloads_dir: config.downloads_dir.clone().unwrap_or_else(|| config.data_dir.join("received")),
transfers: Mutex::new(HashMap::new()),
@@ -1078,6 +1081,12 @@ impl Node {
}
}
+ /// Returns the smart suggestion classified for the most recently received
+ /// text clip (`None` when the latest clip had no suggestion or was an OTP).
+ pub fn last_clip_suggestion(&self) -> Option<(DeviceId, crate::ClipSuggestion)> {
+ self.shared.last_clip_suggestion.lock().unwrap_or_else(|e| e.into_inner()).clone()
+ }
+
// ---- Actions (docs/protocol/actions.md) ----
/// Locks or sleeps a paired PC.
@@ -1536,6 +1545,13 @@ impl Node {
crate::deck::press(&self.shared, &session, tile).await
}
+ /// Asks a paired PC to change its master speaker volume (`0..=100`) and/or
+ /// mute state (`pc.audio.set`).
+ pub async fn set_pc_audio(&self, peer: DeviceId, volume: Option<u8>, muted: Option<bool>) -> Result<()> {
+ let session = self.connected(&peer)?;
+ crate::deck::set_pc_audio(&self.shared, &session, volume, muted).await
+ }
+
// ---- Phone storage (PC File Explorer) ----
/// Lists a directory on a connected phone (`storage.list`).
diff --git a/core/nectarlink-core/src/session.rs b/core/nectarlink-core/src/session.rs
index 4320f89..cc00dab 100644
--- a/core/nectarlink-core/src/session.rs
+++ b/core/nectarlink-core/src/session.rs
@@ -412,7 +412,8 @@ async fn handle(shared: &Arc<Shared>, session: &Arc<Session>, env: Envelope) ->
t if t.starts_with("webcam.") && crate::webcam::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? => {}
+ t if (t.starts_with("deck.") || t == types::PC_AUDIO_SET)
+ && crate::deck::handle(shared, session, &env).await? => {}
t if t.starts_with("storage.") && crate::storage::handle(shared, session, &env).await? => {}
other => {
if env.id.is_some() {
diff --git a/core/nectarlink-core/tests/two_devices.rs b/core/nectarlink-core/tests/two_devices.rs
index be5db69..1dcf03a 100644
--- a/core/nectarlink-core/tests/two_devices.rs
+++ b/core/nectarlink-core/tests/two_devices.rs
@@ -45,6 +45,7 @@ struct RecordingPlatform {
remote_inputs: Mutex<Vec<nectarlink_core::RemoteInput>>,
phone_toggles: Mutex<Vec<(String, nectarlink_core::PhoneToggleValue)>>,
deck_presses: Mutex<Vec<String>>,
+ pc_audio_changes: Mutex<Vec<(Option<u8>, Option<bool>)>>,
storage: Mutex<Option<nectarlink_core::FolderStorage>>,
}
@@ -424,6 +425,15 @@ impl Platform for RecordingPlatform {
self.deck_presses.lock().unwrap().push(tile.to_owned());
Ok(())
}
+ fn set_pc_audio(
+ &self,
+ _from: &nectarlink_core::DeviceId,
+ volume: Option<u8>,
+ muted: Option<bool>,
+ ) -> Result<(), String> {
+ self.pc_audio_changes.lock().unwrap().push((volume, muted));
+ Ok(())
+ }
fn storage_list(
&self,
path: &str,
@@ -2734,7 +2744,13 @@ async fn deck_layout_and_state_arrive_press_runs_action_and_respects_toggles_and
});
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) };
+ let initial_state = DeckState {
+ playing: true,
+ volume: 60,
+ muted: false,
+ mic_muted: Some(false),
+ output_devices: Vec::new(),
+ };
pc.node.set_deck_state(initial_state.clone()).await.unwrap();
pair_qr(&mut pc, &mut phone).await;
@@ -2782,7 +2798,7 @@ async fn deck_layout_and_state_arrive_press_runs_action_and_respects_toggles_and
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.
+ // Enable `commands`: the `run_build` 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();
@@ -2792,7 +2808,13 @@ async fn deck_layout_and_state_arrive_press_runs_action_and_respects_toggles_and
);
// Live state updates push to the phone.
- let updated_state = DeckState { playing: false, volume: 45, muted: true, mic_muted: Some(true) };
+ let updated_state = DeckState {
+ playing: false,
+ volume: 45,
+ muted: true,
+ mic_muted: Some(true),
+ output_devices: Vec::new(),
+ };
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 => {
@@ -3074,3 +3096,118 @@ async fn the_phone_camera_streams_to_the_pc_as_a_webcam() {
let refused = pc.node.webcam_start(phone_id, options).await;
assert!(matches!(refused, Err(Error::Denied)), "{refused:?}");
}
+
+#[tokio::test(flavor = "multi_thread")]
+async fn pc_audio_volume_mute_output_devices_and_smart_clipboard_context_chips_flow_end_to_end() {
+ use nectarlink_core::{AudioOutputDevice, ClipKind, DECK_ACTIONS, DeckState, PC_AUDIO};
+
+ let mut pc =
+ device_with("Desktop", DeviceKind::Desktop, &[DECK_ACTIONS, PC_AUDIO, "clipboard.sync"]).await;
+ let mut phone = device_with("Pixel", DeviceKind::Phone, &["clipboard.sync"]).await;
+
+ let initial_state = DeckState {
+ playing: false,
+ volume: 75,
+ muted: false,
+ mic_muted: Some(false),
+ output_devices: vec![
+ AudioOutputDevice {
+ id: "{0.0.0.00000000}.{speakers-id}".into(),
+ name: "Speakers (Realtek Audio)".into(),
+ is_default: true,
+ },
+ AudioOutputDevice {
+ id: "{0.0.0.00000000}.{headphones-id}".into(),
+ name: "Headphones (USB DAC)".into(),
+ is_default: 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 DeckState with active output devices arrives on connect.
+ let got_state = wait_for(&mut phone, "initial deck state with output devices", |e| match e {
+ NodeEvent::DeckState { device, state } if *device == pc_id && *state == initial_state => {
+ Some(state.clone())
+ }
+ _ => None,
+ })
+ .await;
+ assert_eq!(got_state.default_output_name(), Some("Speakers (Realtek Audio)"));
+ assert_eq!(got_state.output_devices.len(), 2);
+
+ // Phone sets PC volume and mute (`pc_actions` is ON by default).
+ with_timeout("set pc volume 40", phone.node.set_pc_audio(pc_id, Some(40), None)).await.unwrap();
+ let after_vol = wait_for(&mut phone, "deck state volume 40", |e| match e {
+ NodeEvent::DeckState { device, state } if *device == pc_id && state.volume == 40 => {
+ Some(state.clone())
+ }
+ _ => None,
+ })
+ .await;
+ assert_eq!(after_vol.volume, 40);
+ assert!(!after_vol.muted);
+
+ with_timeout("set pc mute true", phone.node.set_pc_audio(pc_id, None, Some(true))).await.unwrap();
+ let after_mute = wait_for(&mut phone, "deck state muted true", |e| match e {
+ NodeEvent::DeckState { device, state } if *device == pc_id && state.muted => Some(state.clone()),
+ _ => None,
+ })
+ .await;
+ assert!(after_mute.muted);
+ assert_eq!(*pc.platform.pc_audio_changes.lock().unwrap(), vec![(Some(40), None), (None, Some(true))]);
+
+ // Out-of-range volume or empty request is rejected as a protocol error.
+ assert!(matches!(phone.node.set_pc_audio(pc_id, Some(101), None).await, Err(Error::Protocol(_))));
+ assert!(matches!(phone.node.set_pc_audio(pc_id, None, None).await, Err(Error::Protocol(_))));
+
+ // When both `pc_actions` and `remote_input` are off, `set_pc_audio` is denied.
+ pc.node.set_device_toggle(phone_id, "pc_actions", false).unwrap();
+ assert!(matches!(phone.node.set_pc_audio(pc_id, Some(50), None).await, Err(Error::Denied)));
+
+ // Turning `pc_actions` back on re-enables `set_pc_audio`.
+ pc.node.set_device_toggle(phone_id, "pc_actions", true).unwrap();
+ with_timeout("set pc audio unmute + 65", phone.node.set_pc_audio(pc_id, Some(65), Some(false)))
+ .await
+ .unwrap();
+
+ // Smart clipboard context chips: phone sends different text clips to PC,
+ // and PC classifies each into at most 1 context chip (and None for OTP).
+ let cases = [
+ ("https://nectarlink.app/docs?ref=clip", Some((ClipKind::WebLink, "Open"))),
+ (
+ "1600 Amphitheatre Parkway, Mountain View, CA 94043",
+ Some((ClipKind::StreetAddress, "Open in Maps")),
+ ),
+ ("+1 (415) 555-0199", Some((ClipKind::PhoneNumber, "Call"))),
+ ("1Z999AA10123456784", Some((ClipKind::TrackingNumber, "Track"))),
+ ("[email protected]", Some((ClipKind::Email, "Email"))),
+ ("Your verification code is 482910", None),
+ ("Just a regular sentence with no special action.", None),
+ ];
+
+ for (text, expected) in cases {
+ with_timeout("send clipboard", phone.node.send_clipboard(pc_id, text.into())).await.unwrap();
+ wait_for(&mut pc, "clipboard received", |e| match e {
+ NodeEvent::ClipboardReceived { device } if *device == phone_id => Some(()),
+ _ => None,
+ })
+ .await;
+ let suggestion = pc.node.last_clip_suggestion();
+ match expected {
+ Some((kind, label)) => {
+ let (from, s) = suggestion.unwrap_or_else(|| panic!("expected chip for {text:?}"));
+ assert_eq!(from, phone_id);
+ assert_eq!(s.kind, kind, "wrong kind for {text:?}");
+ assert_eq!(s.action_label(), label, "wrong label for {text:?}");
+ assert!(!format!("{s:?}").contains(&s.target), "Debug must not leak target");
+ }
+ None => {
+ assert!(suggestion.is_none(), "expected no chip for {text:?}, got {suggestion:?}");
+ }
+ }
+ }
+}
diff --git a/core/nectarlink-ffi/src/lib.rs b/core/nectarlink-ffi/src/lib.rs
index 5603142..69ea21e 100644
--- a/core/nectarlink-ffi/src/lib.rs
+++ b/core/nectarlink-ffi/src/lib.rs
@@ -578,6 +578,26 @@ impl From<core::DeckLayout> for DeckLayout {
}
}
+/// An active audio output device on a paired PC (`docs/protocol/deck.md`).
+#[derive(Clone, PartialEq, Eq, uniffi::Record)]
+pub struct AudioOutputDevice {
+ pub id: String,
+ pub name: String,
+ pub is_default: bool,
+}
+
+impl std::fmt::Debug for AudioOutputDevice {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("AudioOutputDevice").field("is_default", &self.is_default).finish_non_exhaustive()
+ }
+}
+
+impl From<core::AudioOutputDevice> for AudioOutputDevice {
+ fn from(d: core::AudioOutputDevice) -> Self {
+ AudioOutputDevice { id: d.id, name: d.name, is_default: d.is_default }
+ }
+}
+
/// Live PC state reflected on Deck tiles (`docs/protocol/deck.md`).
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
pub struct DeckState {
@@ -585,11 +605,61 @@ pub struct DeckState {
pub volume: u8,
pub muted: bool,
pub mic_muted: Option<bool>,
+ pub output_devices: Vec<AudioOutputDevice>,
}
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 }
+ DeckState {
+ playing: s.playing,
+ volume: s.volume,
+ muted: s.muted,
+ mic_muted: s.mic_muted,
+ output_devices: s.output_devices.into_iter().map(Into::into).collect(),
+ }
+ }
+}
+
+/// The recognized kind of a text clip (`docs/protocol/clipboard.md`).
+#[derive(Debug, Clone, Copy, PartialEq, Eq, uniffi::Enum)]
+pub enum ClipKind {
+ WebLink,
+ StreetAddress,
+ PhoneNumber,
+ TrackingNumber,
+ Email,
+}
+
+impl From<core::ClipKind> for ClipKind {
+ fn from(k: core::ClipKind) -> Self {
+ match k {
+ core::ClipKind::WebLink => ClipKind::WebLink,
+ core::ClipKind::StreetAddress => ClipKind::StreetAddress,
+ core::ClipKind::PhoneNumber => ClipKind::PhoneNumber,
+ core::ClipKind::TrackingNumber => ClipKind::TrackingNumber,
+ core::ClipKind::Email => ClipKind::Email,
+ }
+ }
+}
+
+/// A context chip suggestion for a received text clip.
+#[derive(Clone, PartialEq, Eq, uniffi::Record)]
+pub struct ClipSuggestion {
+ pub kind: ClipKind,
+ pub action_label: String,
+ pub target: String,
+}
+
+/// Never prints the target text (protocol v0 §11).
+impl std::fmt::Debug for ClipSuggestion {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("ClipSuggestion").field("kind", &self.kind).finish_non_exhaustive()
+ }
+}
+
+impl From<core::ClipSuggestion> for ClipSuggestion {
+ fn from(s: core::ClipSuggestion) -> Self {
+ ClipSuggestion { kind: s.kind.into(), action_label: s.action_label().into(), target: s.target }
}
}
@@ -2556,6 +2626,18 @@ impl NectarlinkNode {
self.run(async move { Ok(node.deck_press(id, tile).await?) }).await
}
+ /// Asks a paired PC to set its master volume (`0..=100`) and/or mute state (`pc.audio.set`).
+ pub async fn set_pc_audio(&self, id: String, volume: Option<u8>, muted: Option<bool>) -> Result<()> {
+ let id = parse_id(&id)?;
+ let node = self.node.clone();
+ self.run(async move { Ok(node.set_pc_audio(id, volume, muted).await?) }).await
+ }
+
+ /// The context chip suggestion for the most recently received text clip, if any.
+ pub fn last_clip_suggestion(&self) -> Option<ClipSuggestion> {
+ self.node.last_clip_suggestion().map(|(_, s)| s.into())
+ }
+
/// 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>> {
@@ -2692,6 +2774,25 @@ impl NectarlinkNode {
}
}
+/// Classifies a text clip into a single context chip suggestion (`None` for
+/// OTPs or plain text).
+#[uniffi::export]
+pub fn classify_clip(text: String) -> Option<ClipSuggestion> {
+ core::classify_clip(&text).map(Into::into)
+}
+
+/// Builds a web search URL for a parcel tracking number.
+#[uniffi::export]
+pub fn tracking_search_url(tracking_number: String) -> String {
+ core::tracking_search_url(&tracking_number)
+}
+
+/// Builds a web maps URL for a street address.
+#[uniffi::export]
+pub fn maps_web_url(address: String) -> String {
+ core::maps_web_url(&address)
+}
+
/// Sends core logs to the platform log (logcat on Android). Call once,
/// before starting the node. `filter` uses tracing's syntax, e.g. "info".
#[uniffi::export]
diff --git a/core/nectarlink-protocol/src/messages.rs b/core/nectarlink-protocol/src/messages.rs
index e3d9c16..20000fc 100644
--- a/core/nectarlink-protocol/src/messages.rs
+++ b/core/nectarlink-protocol/src/messages.rs
@@ -76,6 +76,7 @@ pub mod types {
pub const DECK_LAYOUT: &str = "deck.layout";
pub const DECK_STATE: &str = "deck.state";
pub const DECK_PRESS: &str = "deck.press";
+ pub const PC_AUDIO_SET: &str = "pc.audio.set";
pub const STORAGE_LIST: &str = "storage.list";
pub const STORAGE_ENTRIES: &str = "storage.entries";
pub const STORAGE_READ: &str = "storage.read";
@@ -2341,6 +2342,8 @@ impl PhoneToggleSet {
pub mod deck {
/// Offered by PCs that share their Deck layout and live state and run Deck actions.
pub const ACTIONS: &str = "deck.actions";
+ /// Offered by PCs that share their active audio output devices and accept `pc.audio.set`.
+ pub const PC_AUDIO: &str = "pc.audio";
/// Maximum pages in a `DeckLayout`.
pub const MAX_PAGES: usize = 8;
/// Maximum tiles on a single `DeckPage`.
@@ -2349,6 +2352,12 @@ pub mod deck {
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;
+ /// Maximum active audio output devices in a `DeckState`.
+ pub const MAX_OUTPUT_DEVICES: usize = 32;
+ /// Maximum bytes in an audio endpoint ID.
+ pub const MAX_DEVICE_ID_BYTES: usize = 256;
+ /// Maximum UTF-8 bytes in an audio endpoint friendly name.
+ pub const MAX_DEVICE_NAME_BYTES: usize = 128;
}
/// Action kinds for [`DeckTile::kind`] (`docs/protocol/deck.md` §2.4).
@@ -2728,6 +2737,57 @@ impl Default for DeckLayout {
}
}
+/// One active audio output endpoint on the PC (`docs/protocol/deck.md` §2.2).
+#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct AudioOutputDevice {
+ pub id: String,
+ pub name: String,
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ pub is_default: bool,
+}
+
+/// Never prints the user's audio device name or system ID in logs (protocol v0 §11).
+impl std::fmt::Debug for AudioOutputDevice {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("AudioOutputDevice").field("is_default", &self.is_default).finish_non_exhaustive()
+ }
+}
+
+impl AudioOutputDevice {
+ pub fn is_valid(&self) -> bool {
+ let id = self.id.trim();
+ let name = self.name.trim();
+ !id.is_empty()
+ && self.id.len() <= deck::MAX_DEVICE_ID_BYTES
+ && !self.id.chars().any(char::is_control)
+ && !name.is_empty()
+ && self.name.len() <= deck::MAX_DEVICE_NAME_BYTES
+ && !self.name.chars().any(char::is_control)
+ }
+
+ pub fn sanitized(self) -> Option<Self> {
+ let id: String = self.id.chars().filter(|c| !c.is_control()).collect();
+ let id = id.trim();
+ if id.is_empty() || id.len() > deck::MAX_DEVICE_ID_BYTES {
+ return None;
+ }
+ let name: String = self.name.chars().filter(|c| !c.is_control()).collect();
+ let name = name.trim();
+ if name.is_empty() {
+ return None;
+ }
+ let mut end = name.len().min(deck::MAX_DEVICE_NAME_BYTES);
+ while end > 0 && !name.is_char_boundary(end) {
+ end -= 1;
+ }
+ let name = name[..end].trim().to_owned();
+ if name.is_empty() {
+ return None;
+ }
+ Some(AudioOutputDevice { id: id.to_owned(), name, is_default: self.is_default })
+ }
+}
+
/// 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 {
@@ -2739,18 +2799,37 @@ pub struct DeckState {
pub muted: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mic_muted: Option<bool>,
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub output_devices: Vec<AudioOutputDevice>,
}
impl DeckState {
pub fn is_valid(&self) -> bool {
self.volume <= 100
+ && self.output_devices.len() <= deck::MAX_OUTPUT_DEVICES
+ && self.output_devices.iter().all(AudioOutputDevice::is_valid)
}
pub fn sanitized(mut self) -> Option<Self> {
self.volume = self.volume.min(100);
+ self.output_devices = self
+ .output_devices
+ .into_iter()
+ .filter_map(AudioOutputDevice::sanitized)
+ .take(deck::MAX_OUTPUT_DEVICES)
+ .collect();
Some(self)
}
+ /// Friendly name of the default audio output device, if reported.
+ pub fn default_output_name(&self) -> Option<&str> {
+ self.output_devices
+ .iter()
+ .find(|d| d.is_default)
+ .or_else(|| self.output_devices.first())
+ .map(|d| d.name.as_str())
+ }
+
/// 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 {
@@ -2787,6 +2866,22 @@ impl DeckPress {
}
}
+/// Body of `pc.audio.set`: asks the PC to change its master speaker volume
+/// (`0..=100`) and/or mute state (`docs/protocol/deck.md` §2.5).
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct PcAudioSet {
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub volume: Option<u8>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub muted: Option<bool>,
+}
+
+impl PcAudioSet {
+ pub fn is_valid(&self) -> bool {
+ (self.volume.is_some() || self.muted.is_some()) && self.volume.is_none_or(|v| v <= 100)
+ }
+}
+
// ---- Storage (docs/protocol/storage.md) ----
pub mod storage {
@@ -3681,8 +3776,27 @@ mod tests {
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) };
+ let state = DeckState {
+ playing: true,
+ volume: 72,
+ muted: false,
+ mic_muted: Some(true),
+ output_devices: vec![
+ AudioOutputDevice {
+ id: "out:speakers".into(),
+ name: "Speakers (Realtek Audio)".into(),
+ is_default: true,
+ },
+ AudioOutputDevice {
+ id: "out:headphones".into(),
+ name: "Headphones".into(),
+ is_default: false,
+ },
+ ],
+ };
assert!(state.is_valid());
+ assert_eq!(state.default_output_name(), Some("Speakers (Realtek Audio)"));
+ assert!(!format!("{:?}", state.output_devices[0]).contains("Realtek"));
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"));
@@ -3691,6 +3805,14 @@ mod tests {
let back: DeckState = Envelope::from_cbor(&env.to_cbor()).unwrap().body().unwrap();
assert_eq!(back, state);
+ // PC audio set validation and round-trip.
+ let audio_set = PcAudioSet { volume: Some(65), muted: Some(false) };
+ assert!(audio_set.is_valid());
+ let env = Envelope::new(types::PC_AUDIO_SET, &audio_set).unwrap();
+ assert_eq!(Envelope::from_cbor(&env.to_cbor()).unwrap().body::<PcAudioSet>().unwrap(), audio_set);
+ assert!(!PcAudioSet { volume: None, muted: None }.is_valid());
+ assert!(!PcAudioSet { volume: Some(101), muted: None }.is_valid());
+
// Press validation.
let press = DeckPress { tile: "play_pause".into() };
assert!(press.is_valid());
diff --git a/desktop/app/Cargo.toml b/desktop/app/Cargo.toml
index 82772e7..f5484f7 100644
--- a/desktop/app/Cargo.toml
+++ b/desktop/app/Cargo.toml
@@ -34,6 +34,8 @@ tracing.workspace = true
tracing-subscriber.workspace = true
[target.'cfg(windows)'.dependencies]
+# For the COM callbacks that `windows::core::implement` generates.
+windows-core.workspace = true
windows = { workspace = true, features = [
"Data_Xml_Dom",
"Foundation",
@@ -69,6 +71,7 @@ windows = { workspace = true, features = [
"Win32_System_WinRT",
"Win32_UI_Input_KeyboardAndMouse",
"Win32_UI_Shell",
+ "Win32_UI_Shell_PropertiesSystem",
"Win32_UI_WindowsAndMessaging",
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_WindowsFirewall",
diff --git a/desktop/app/qml/MainWindow.qml b/desktop/app/qml/MainWindow.qml
index 349b0e4..0a000b3 100644
--- a/desktop/app/qml/MainWindow.qml
+++ b/desktop/app/qml/MainWindow.qml
@@ -368,9 +368,21 @@ NativeWindow {
}
}
- Toast { id: toast }
+ Toast {
+ id: toast
+ onActionTriggered: AppController.runClipSuggestion()
+ }
Connections {
target: AppController
function onToast(message) { toast.show(message) }
+ function onToastWithAction(message, actionLabel) { toast.showWithAction(message, actionLabel) }
+ function onCurrentPageChanged() {
+ if (AppController.currentPage.length > 0 && window.page !== AppController.currentPage)
+ window.page = AppController.currentPage
+ }
+ function onPendingDialChanged() {
+ if (AppController.pendingDial.length > 0 && window.page !== "calls")
+ window.page = "calls"
+ }
}
}
diff --git a/desktop/app/qml/components/Toast.qml b/desktop/app/qml/components/Toast.qml
index 0311a26..8ca0d4a 100644
--- a/desktop/app/qml/components/Toast.qml
+++ b/desktop/app/qml/components/Toast.qml
@@ -2,14 +2,28 @@
import QtQuick
import app.nectarlink
-// A short message at the bottom of the window that hides itself.
+// A short message at the bottom of the window that hides itself, with an
+// optional context action chip (e.g. "Open", "Call", "Track").
Rectangle {
id: toast
property int timeout: 4000
+ property int actionTimeout: 6500
+ property string actionText: ""
+ signal actionTriggered()
function show(message) {
label.text = message
+ actionText = ""
shown = true
+ timer.interval = toast.timeout
+ timer.restart()
+ }
+
+ function showWithAction(message, actionLabel) {
+ label.text = message
+ actionText = actionLabel || ""
+ shown = true
+ timer.interval = actionText.length > 0 ? toast.actionTimeout : toast.timeout
timer.restart()
}
@@ -22,21 +36,78 @@ Rectangle {
Behavior on opacity { NumberAnimation { duration: Theme.fadeFast } }
z: 200
- width: Math.min(label.implicitWidth + 40, parent.width - 48)
+ readonly property bool hasAction: actionText.length > 0
+ width: Math.min(contentRow.implicitWidth + (hasAction ? 28 : 40), parent.width - 48)
height: 44
radius: Theme.pill(height)
color: Theme.surfaceContent
Accessible.role: Accessible.AlertMessage
- Accessible.name: label.text
+ Accessible.name: hasAction ? (label.text + " " + actionText) : label.text
- Txt {
- id: label
+ Row {
+ id: contentRow
anchors.centerIn: parent
- width: parent.width - 40
- horizontalAlignment: Text.AlignHCenter
- role: "body"
- color: Theme.surface
+ spacing: 12
+
+ Txt {
+ id: label
+ anchors.verticalCenter: parent.verticalCenter
+ width: Math.min(implicitWidth, toast.parent.width - (toast.hasAction ? actionChip.width + 100 : 88))
+ horizontalAlignment: Text.AlignHCenter
+ elide: Text.ElideRight
+ role: "body"
+ color: Theme.surface
+ }
+
+ Rectangle {
+ id: actionChip
+ visible: toast.hasAction
+ anchors.verticalCenter: parent.verticalCenter
+ width: chipLabel.implicitWidth + 24
+ height: 30
+ radius: Theme.pill(height)
+ color: chipHover.hovered
+ ? Qt.rgba(Theme.primaryContainer.r, Theme.primaryContainer.g, Theme.primaryContainer.b, 0.92)
+ : Theme.primaryContainer
+ border.width: Theme.focusVisible(actionChip) ? 2 : 0
+ border.color: Theme.surface
+ activeFocusOnTab: toast.shown && toast.hasAction
+
+ Accessible.role: Accessible.Button
+ Accessible.name: toast.actionText
+ Accessible.onPressAction: trigger()
+
+ function trigger() {
+ toast.shown = false
+ timer.stop()
+ toast.actionTriggered()
+ }
+
+ Keys.onPressed: (event) => {
+ if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_Space) {
+ trigger()
+ event.accepted = true
+ }
+ }
+
+ Txt {
+ id: chipLabel
+ anchors.centerIn: parent
+ text: toast.actionText
+ role: "label"
+ color: Theme.primaryContainerContent
+ }
+
+ HoverHandler { id: chipHover; cursorShape: Qt.PointingHandCursor }
+ TapHandler { onTapped: actionChip.trigger() }
+ }
+ }
+
+ // Stays while the pointer is on it, so its action can be reached.
+ HoverHandler {
+ onHoveredChanged: if (hovered) timer.stop(); else if (toast.shown) timer.restart()
}
Timer { id: timer; interval: toast.timeout; onTriggered: toast.shown = false }
}
+
diff --git a/desktop/app/qml/pages/CallsPage.qml b/desktop/app/qml/pages/CallsPage.qml
index 9336284..3063f36 100644
--- a/desktop/app/qml/pages/CallsPage.qml
+++ b/desktop/app/qml/pages/CallsPage.qml
@@ -111,9 +111,22 @@ Item {
page.textRequested(n, name || "")
}
+ function consumePendingDial() {
+ if (AppController.pendingDial.length > 0) {
+ dialInput.text = AppController.pendingDial
+ AppController.pendingDial = ""
+ }
+ }
+
function load() {
if (active && deviceId.length > 0)
PhoneCall.open(deviceId)
+ consumePendingDial()
+ }
+
+ Connections {
+ target: AppController
+ function onPendingDialChanged() { page.consumePendingDial() }
}
onActiveChanged: if (active) load()
diff --git a/desktop/app/qml/pages/SettingsPage.qml b/desktop/app/qml/pages/SettingsPage.qml
index 634497d..981f80e 100644
--- a/desktop/app/qml/pages/SettingsPage.qml
+++ b/desktop/app/qml/pages/SettingsPage.qml
@@ -273,6 +273,18 @@ Item {
}
}
Divider { width: parent.width }
+ ListRow {
+ width: parent.width
+ iconPath: Icons.sparkle
+ title: qsTr("Suggest actions for copied text")
+ description: qsTr("Offer to open links, look up addresses in Maps, call numbers, track parcels, or compose emails when text arrives from your phone.")
+ Toggle {
+ label: qsTr("Suggest actions for copied text")
+ checked: Preferences.suggestClipboardActions
+ onToggled: (on) => Preferences.suggestClipboardActions = on
+ }
+ }
+ Divider { width: parent.width }
ListRow {
width: parent.width
iconPath: Icons.history
diff --git a/desktop/app/src/bridge/app.rs b/desktop/app/src/bridge/app.rs
index 0cd0b0d..0ab77e5 100644
--- a/desktop/app/src/bridge/app.rs
+++ b/desktop/app/src/bridge/app.rs
@@ -92,6 +92,9 @@ pub mod qobject {
/// unloads so the window can be destroyed in the background.
#[qproperty(QString, current_page)]
#[qproperty(i32, current_device)]
+ /// Phone number to pre-fill in the Calls page dialer when opened from a
+ /// clipboard context chip ("" when none).
+ #[qproperty(QString, pending_dial)]
/// Encrypted local clipboard history as JSON:
/// `[{ id, kind, text, imageDataUrl, deviceName, incoming, timestamp, pinned }]`.
#[qproperty(QString, clipboard_history)]
@@ -151,6 +154,9 @@ pub mod qobject {
/// Clears all items from local clipboard history.
#[qinvokable]
fn clear_clipboard_history(self: &AppController);
+ /// Runs the suggested action for the most recently received clipboard item.
+ #[qinvokable]
+ fn run_clip_suggestion(self: &AppController);
/// Re-reads whether Windows shows this app's notifications (the user
/// may have changed it in Settings).
@@ -190,6 +196,9 @@ pub mod qobject {
/// A short message for the user (e.g. a command failed).
#[qsignal]
fn toast(self: Pin<&mut AppController>, message: QString);
+ /// A short message with a context action chip (e.g. a received clip).
+ #[qsignal]
+ fn toast_with_action(self: Pin<&mut AppController>, message: QString, action_label: QString);
/// Show the main window (tray click, second launch).
#[qsignal]
fn activate_requested(self: Pin<&mut AppController>);
@@ -236,6 +245,7 @@ pub struct AppControllerRust {
wake_wired: bool,
current_page: QString,
current_device: i32,
+ pending_dial: QString,
clipboard_history: QString,
tray: Option<tray::Tray>,
}
@@ -326,6 +336,42 @@ pub(crate) fn show_message(message: impl Into<String>) {
}
}
+/// Shows a short message with a context action chip in the app (from any thread).
+pub(crate) fn show_message_with_action(message: impl Into<String>, action_label: impl Into<String>) {
+ let message = message.into();
+ let action_label = action_label.into();
+ if let Some(qt) = controller() {
+ let _ = qt.queue(move |object| {
+ object.toast_with_action(QString::from(&message), QString::from(&action_label));
+ });
+ }
+}
+
+/// Opens the Calls page dialer with `number` filled in (without placing the call).
+pub(crate) fn open_dialer(device: DeviceId, number: &str) {
+ let number = number.trim().to_owned();
+ if number.is_empty() {
+ return;
+ }
+ let idx = core_host::host().hub.read(|s| {
+ s.devices
+ .iter()
+ .position(|d| d.id == device && matches!(d.link, LinkState::Online { .. }))
+ .or_else(|| s.devices.iter().position(|d| matches!(d.link, LinkState::Online { .. })))
+ .or_else(|| s.devices.iter().position(|d| d.id == device))
+ });
+ if let Some(qt) = controller() {
+ let _ = qt.queue(move |mut object| {
+ if let Some(idx) = idx {
+ object.as_mut().set_current_device(idx as i32);
+ }
+ object.as_mut().set_pending_dial(QString::from(&number));
+ object.as_mut().set_current_page(QString::from("calls"));
+ object.activate_requested();
+ });
+ }
+}
+
/// Explains a failed command in a sentence the user understands.
pub(crate) fn describe(error: &Error) -> String {
match error {
@@ -571,6 +617,10 @@ impl qobject::AppController {
crate::clipboard::clear_history();
}
+ pub fn run_clip_suggestion(&self) {
+ crate::clipboard::run_last_suggestion();
+ }
+
pub fn refresh_toasts_enabled(self: Pin<&mut Self>) {
self.set_toasts_enabled(win::toast::enabled());
core_host::spawn(core_host::refresh_wake());
diff --git a/desktop/app/src/bridge/prefs.rs b/desktop/app/src/bridge/prefs.rs
index 370340b..63aca04 100644
--- a/desktop/app/src/bridge/prefs.rs
+++ b/desktop/app/src/bridge/prefs.rs
@@ -48,6 +48,8 @@ pub mod qobject {
#[qproperty(bool, auto_clipboard)]
/// Keep the last 50 synced clips in encrypted local history.
#[qproperty(bool, clipboard_history)]
+ /// Suggest context chips (Open, Open in Maps, Call, Track, Email) for copied text.
+ #[qproperty(bool, suggest_clipboard_actions)]
/// Copy one-time codes from phone notifications and SMS automatically.
#[qproperty(bool, auto_copy_otp)]
/// Pause PC media playback while a phone call is ringing or active.
@@ -143,6 +145,7 @@ pub struct PreferencesRust {
close_to_tray: bool,
auto_clipboard: bool,
clipboard_history: bool,
+ suggest_clipboard_actions: bool,
auto_copy_otp: bool,
pause_media_on_call: bool,
sync_dnd: bool,
@@ -178,6 +181,8 @@ impl cxx_qt::Initialize for qobject::Preferences {
crate::clipboard::set_auto_send(settings.auto_clipboard);
self.as_mut().set_clipboard_history(settings.clipboard_history);
crate::clipboard::set_history_enabled(settings.clipboard_history);
+ self.as_mut().set_suggest_clipboard_actions(settings.suggest_clipboard_actions);
+ crate::clipboard::set_suggest_actions(settings.suggest_clipboard_actions);
self.as_mut().set_auto_copy_otp(settings.auto_copy_otp);
crate::notifications::set_auto_copy_otp(settings.auto_copy_otp);
self.as_mut().set_pause_media_on_call(settings.pause_media_on_call);
@@ -215,6 +220,12 @@ impl cxx_qt::Initialize for qobject::Preferences {
p.save();
})
.release();
+ self.as_mut()
+ .on_suggest_clipboard_actions_changed(|p| {
+ crate::clipboard::set_suggest_actions(p.suggest_clipboard_actions);
+ p.save();
+ })
+ .release();
self.as_mut()
.on_auto_copy_otp_changed(|p| {
crate::notifications::set_auto_copy_otp(p.auto_copy_otp);
@@ -311,6 +322,7 @@ impl qobject::Preferences {
close_to_tray: p.close_to_tray,
auto_clipboard: p.auto_clipboard,
clipboard_history: p.clipboard_history,
+ suggest_clipboard_actions: p.suggest_clipboard_actions,
auto_copy_otp: p.auto_copy_otp,
pause_media_on_call: p.pause_media_on_call,
sync_dnd: p.sync_dnd,
diff --git a/desktop/app/src/clipboard.rs b/desktop/app/src/clipboard.rs
index 1e1522d..cc32a2f 100644
--- a/desktop/app/src/clipboard.rs
+++ b/desktop/app/src/clipboard.rs
@@ -15,23 +15,35 @@ use std::{
use data_encoding::BASE64;
use nectarlink_core::{
- CLIP_MAX_IMAGE_BYTES, ClipboardItemKind, DeviceId, Error, FeatureState, LinkState, Node, NodeEvent,
+ CLIP_MAX_IMAGE_BYTES, ClipKind, ClipSuggestion, ClipboardItemKind, DeviceId, Error, FeatureState,
+ LinkState, Node, NodeEvent,
};
use serde_json::json;
use crate::{
- bridge::app::{describe, show_message},
+ bridge::app::{describe, open_dialer, show_message, show_message_with_action},
core_host,
state::Changes,
win::clipboard::{self, Clip},
};
+/// Toast group and action ID for smart clipboard context chips.
+pub const TOAST_GROUP: &str = "clipboard";
+pub const ACTION_CLIP_SUGGESTION: &str = "clip_action";
+
/// The "Send what you copy to your phone" preference.
static AUTO_SEND: AtomicBool = AtomicBool::new(true);
/// The "Keep clipboard history" preference.
static HISTORY_ENABLED: AtomicBool = AtomicBool::new(true);
+/// The "Suggest actions for copied text" preference.
+static SUGGEST_ACTIONS: AtomicBool = AtomicBool::new(true);
+
+/// Most recent incoming clipboard context suggestion, kept only in memory so
+/// Windows toast XML arguments never carry the copied text.
+static LAST_SUGGESTION: Mutex<Option<(DeviceId, ClipSuggestion)>> = Mutex::new(None);
+
/// Small PNG previews of history images as data URLs, by entry ID. Made
/// off the UI thread and kept only in memory, so nothing decrypted is
/// written to disk.
@@ -49,6 +61,14 @@ pub fn set_auto_send(on: bool) {
AUTO_SEND.store(on, Ordering::Relaxed);
}
+pub fn set_suggest_actions(on: bool) {
+ SUGGEST_ACTIONS.store(on, Ordering::Relaxed);
+ if !on {
+ *LAST_SUGGESTION.lock().unwrap_or_else(|e| e.into_inner()) = None;
+ crate::win::toast::remove_device(TOAST_GROUP);
+ }
+}
+
pub fn set_history_enabled(on: bool) {
HISTORY_ENABLED.store(on, Ordering::Relaxed);
if let Some(node) = core_host::node() {
@@ -265,6 +285,59 @@ pub fn send_now(device: DeviceId) {
pub fn on_event(event: &NodeEvent) {
if let NodeEvent::ClipboardReceived { device } = event {
let name = core_host::host().hub.read(|s| s.name_of(device)).unwrap_or_else(|| "your phone".into());
- show_message(format!("Copied from {name}."));
+ let suggestion = if SUGGEST_ACTIONS.load(Ordering::Relaxed) {
+ core_host::node()
+ .and_then(|node| node.last_clip_suggestion())
+ .filter(|(sug_dev, _)| sug_dev == device)
+ .map(|(_, sug)| sug)
+ } else {
+ None
+ };
+ if let Some(suggestion) = suggestion {
+ let label = suggestion.action_label();
+ *LAST_SUGGESTION.lock().unwrap_or_else(|e| e.into_inner()) = Some((*device, suggestion));
+ show_message_with_action(format!("Copied from {name}."), label);
+ crate::win::toast::show(crate::win::toast::Toast {
+ device: TOAST_GROUP.into(),
+ key: "clip_suggestion".into(),
+ title: format!("Copied from {name}"),
+ body: String::new(),
+ attribution: String::new(),
+ icon: None,
+ image: None,
+ actions: vec![(ACTION_CLIP_SUGGESTION.into(), label.into())],
+ reply: None,
+ silent: true,
+ progress: None,
+ call: false,
+ });
+ } else {
+ *LAST_SUGGESTION.lock().unwrap_or_else(|e| e.into_inner()) = None;
+ show_message(format!("Copied from {name}."));
+ }
+ }
+}
+
+/// Runs the action for the most recently offered clipboard suggestion (from
+/// the in-app toast chip or the Windows toast action button).
+pub fn run_last_suggestion() {
+ let Some((device, suggestion)) = LAST_SUGGESTION.lock().unwrap_or_else(|e| e.into_inner()).clone() else {
+ return;
+ };
+ crate::win::toast::remove(TOAST_GROUP, "clip_suggestion");
+ let result = match suggestion.kind {
+ ClipKind::WebLink => crate::win::shell::open_url(&suggestion.target),
+ ClipKind::StreetAddress => crate::win::shell::open_maps(&suggestion.target),
+ ClipKind::PhoneNumber => {
+ open_dialer(device, &suggestion.target);
+ Ok(())
+ }
+ ClipKind::TrackingNumber => {
+ crate::win::shell::open_url(&nectarlink_core::tracking_search_url(&suggestion.target))
+ }
+ ClipKind::Email => crate::win::shell::open_mailto(&suggestion.target),
+ };
+ if let Err(e) = result {
+ tracing::debug!(kind = ?suggestion.kind, error = %e, "clipboard suggestion action failed");
}
}
diff --git a/desktop/app/src/core_host.rs b/desktop/app/src/core_host.rs
index 7619350..8c5c8ca 100644
--- a/desktop/app/src/core_host.rs
+++ b/desktop/app/src/core_host.rs
@@ -108,6 +108,7 @@ async fn run(data_dir: PathBuf, platform: Arc<dyn Platform>) {
nectarlink_core::MIRROR_LISTEN.into(),
nectarlink_core::INPUT_INJECT.into(),
nectarlink_core::DECK_ACTIONS.into(),
+ nectarlink_core::PC_AUDIO.into(),
nectarlink_core::RECORDER.into(),
nectarlink_core::TOGGLES_SHOW.into(),
nectarlink_core::STORAGE_MOUNT.into(),
diff --git a/desktop/app/src/deck.rs b/desktop/app/src/deck.rs
index 9153124..976c1ab 100644
--- a/desktop/app/src/deck.rs
+++ b/desktop/app/src/deck.rs
@@ -44,7 +44,8 @@ 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 }
+ let output_devices = win::audio::output_devices();
+ DeckState { volume, muted, mic_muted, playing, output_devices }
}
/// Marks whether the desktop Deck page is currently visible so idle background
@@ -60,7 +61,8 @@ pub fn set_page_active(active: bool) {
}
/// Loads `deck.json` from `data_dir` and starts the background poller that
-/// keeps speaker volume, microphone mute, and external `deck.json` edits in sync.
+/// keeps speaker volume, microphone mute, output devices, and external
+/// `deck.json` edits in sync.
pub fn init(data_dir: &Path) {
let path = data_dir.join(FILE_NAME);
if !path.exists() {
@@ -69,7 +71,13 @@ pub fn init(data_dir: &Path) {
}
let config = DeckConfig::load(&path);
let mtime = file_mtime(&path);
- let initial_state = DeckState { volume: 50, muted: false, mic_muted: Some(false), playing: false };
+ let initial_state = DeckState {
+ volume: 50,
+ muted: false,
+ mic_muted: Some(false),
+ playing: false,
+ output_devices: Vec::new(),
+ };
let wire_layout = config.to_wire_layout();
{
let mut guard = lock(&DECK);
@@ -83,6 +91,7 @@ pub fn init(data_dir: &Path) {
muted: false,
mic_muted: Some(false),
playing: false,
+ output_devices: Vec::new(),
});
{
let mut guard = lock(&DECK);
@@ -95,6 +104,9 @@ pub fn init(data_dir: &Path) {
let _ = node.set_deck_layout(wire_layout).await;
let _ = node.set_deck_state(sampled).await;
}
+ // Windows reports audio changes as they happen; the poll only
+ // picks up edits to deck.json while the Deck page is open.
+ win::audio::watch(|| core_host::spawn(refresh_live_state()));
let mut interval = tokio::time::interval(Duration::from_millis(1500));
loop {
interval.tick().await;
@@ -211,6 +223,21 @@ pub fn handle_press(_peer: &DeviceId, tile_id: &str) -> Result<(), String> {
execute_tile(tile_id)
}
+/// Called when a paired phone changes the PC's speaker volume and/or mute state
+/// (`Platform::set_pc_audio`).
+pub fn handle_set_audio(_peer: &DeviceId, volume: Option<u8>, muted: Option<bool>) -> Result<(), String> {
+ if let Some(level) = volume {
+ win::audio::set_speaker_volume(level)?;
+ }
+ if let Some(m) = muted {
+ win::audio::set_speaker_mute(m)?;
+ }
+ core_host::spawn(async {
+ refresh_live_state().await;
+ });
+ Ok(())
+}
+
/// 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> {
diff --git a/desktop/app/src/main.rs b/desktop/app/src/main.rs
index 974ecf8..3c5cce2 100644
--- a/desktop/app/src/main.rs
+++ b/desktop/app/src/main.rs
@@ -116,6 +116,14 @@ impl Platform for DesktopPlatform {
fn deck_press(&self, peer: &nectarlink_core::DeviceId, tile: &str) -> Result<(), String> {
deck::handle_press(peer, tile)
}
+ fn set_pc_audio(
+ &self,
+ peer: &nectarlink_core::DeviceId,
+ volume: Option<u8>,
+ muted: Option<bool>,
+ ) -> Result<(), String> {
+ deck::handle_set_audio(peer, volume, muted)
+ }
}
/// Command-line options (also used by shortcuts and autostart).
@@ -296,6 +304,7 @@ fn main() -> ExitCode {
let settings = settings::Settings::load(&data_dir);
clipboard::set_auto_send(settings.auto_clipboard);
clipboard::set_history_enabled(settings.clipboard_history);
+ clipboard::set_suggest_actions(settings.suggest_clipboard_actions);
notifications::set_auto_copy_otp(settings.auto_copy_otp);
notifications::set_sync_dnd(settings.sync_dnd);
calls::set_pause_media_on_call(settings.pause_media_on_call);
diff --git a/desktop/app/src/notifications.rs b/desktop/app/src/notifications.rs
index 78292be..c7bf812 100644
--- a/desktop/app/src/notifications.rs
+++ b/desktop/app/src/notifications.rs
@@ -370,6 +370,13 @@ pub fn on_toast(event: ToastEvent) {
{
return;
}
+ ToastEvent::Action { device, action, .. } if device == crate::clipboard::TOAST_GROUP => {
+ if action == crate::clipboard::ACTION_CLIP_SUGGESTION {
+ crate::clipboard::run_last_suggestion();
+ }
+ return;
+ }
+ ToastEvent::Dismissed { device, .. } if device == crate::clipboard::TOAST_GROUP => return,
_ => {}
}
match event {
diff --git a/desktop/app/src/settings.rs b/desktop/app/src/settings.rs
index 2c0cebc..b55ab47 100644
--- a/desktop/app/src/settings.rs
+++ b/desktop/app/src/settings.rs
@@ -75,6 +75,8 @@ pub struct Settings {
pub auto_clipboard: bool,
/// Keep the last 50 synced clips in encrypted local clipboard history.
pub clipboard_history: bool,
+ /// Suggest context chips (Open, Open in Maps, Call, Track, Email) for copied text.
+ pub suggest_clipboard_actions: bool,
/// Copy one-time codes from phone notifications and SMS automatically.
pub auto_copy_otp: bool,
/// Pause PC media playback while a phone call is ringing or active.
@@ -116,6 +118,7 @@ impl Default for Settings {
close_to_tray: true,
auto_clipboard: true,
clipboard_history: true,
+ suggest_clipboard_actions: true,
auto_copy_otp: false,
pause_media_on_call: true,
sync_dnd: false,
@@ -189,6 +192,7 @@ mod tests {
close_to_tray: false,
auto_clipboard: false,
clipboard_history: false,
+ suggest_clipboard_actions: false,
auto_copy_otp: true,
pause_media_on_call: false,
sync_dnd: true,
diff --git a/desktop/app/src/win/audio.rs b/desktop/app/src/win/audio.rs
index 883e491..cbc488c 100644
--- a/desktop/app/src/win/audio.rs
+++ b/desktop/app/src/win/audio.rs
@@ -1,15 +1,31 @@
// SPDX-License-Identifier: GPL-3.0-or-later
-//! Speaker volume and microphone mute control and state via Windows Core Audio
-//! (`IMMDeviceEnumerator` + `IAudioEndpointVolume`).
+//! Speaker volume, mute, output device enumeration, and microphone mute state
+//! via Windows Core Audio (`IMMDeviceEnumerator` + `IAudioEndpointVolume`),
+//! and notifications when any of them change.
-use windows::Win32::{
- Media::Audio::{
- EDataFlow, Endpoints::IAudioEndpointVolume, IMMDeviceEnumerator, MMDeviceEnumerator, eCapture,
- eConsole, eRender,
+use windows::{
+ Win32::{
+ Foundation::PROPERTYKEY,
+ Media::Audio::{
+ AUDIO_VOLUME_NOTIFICATION_DATA, DEVICE_STATE, DEVICE_STATE_ACTIVE, EDataFlow, ERole,
+ Endpoints::{
+ IAudioEndpointVolume, IAudioEndpointVolumeCallback, IAudioEndpointVolumeCallback_Impl,
+ },
+ IMMDevice, IMMDeviceEnumerator, IMMNotificationClient, IMMNotificationClient_Impl,
+ MMDeviceEnumerator, eCapture, eConsole, eRender,
+ },
+ System::Com::{
+ CLSCTX_ALL, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx, CoTaskMemFree,
+ CoUninitialize, STGM_READ,
+ },
},
- System::Com::{CLSCTX_ALL, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx, CoUninitialize},
+ core::{GUID, PCWSTR, PWSTR},
};
+/// `PKEY_Device_FriendlyName` (`{a45c254e-df1c-4efd-8020-67d146a850e0}, 14`).
+const PKEY_DEVICE_FRIENDLY_NAME: PROPERTYKEY =
+ PROPERTYKEY { fmtid: GUID::from_u128(0xa45c254e_df1c_4efd_8020_67d146a850e0), pid: 14 };
+
struct ComGuard(bool);
impl ComGuard {
@@ -51,6 +67,23 @@ pub fn speaker_state() -> Option<(u8, bool)> {
}
}
+/// Sets the default speaker endpoint's master volume (`0..=100`).
+pub fn set_speaker_volume(level: u8) -> Result<(), String> {
+ let _com = ComGuard::new();
+ let ep = endpoint_volume(eRender).map_err(|e| format!("no speaker device: {e}"))?;
+ let scalar = (f32::from(level.min(100)) / 100.0).clamp(0.0, 1.0);
+ // SAFETY: `ep` is a valid activated `IAudioEndpointVolume`.
+ unsafe { ep.SetMasterVolumeLevelScalar(scalar, std::ptr::null()).map_err(|e| e.to_string()) }
+}
+
+/// Sets the default speaker endpoint's mute state.
+pub fn set_speaker_mute(muted: bool) -> Result<(), 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.SetMute(muted, std::ptr::null()).map_err(|e| e.to_string()) }
+}
+
/// 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();
@@ -116,15 +149,175 @@ pub fn toggle_mic_mute() -> Result<bool, String> {
}
}
+fn device_id_string(device: &IMMDevice) -> Option<String> {
+ // SAFETY: `GetId` returns a task-allocated wide string freed with `CoTaskMemFree`.
+ unsafe {
+ let raw: PWSTR = device.GetId().ok()?;
+ if raw.is_null() {
+ return None;
+ }
+ let s = raw.to_string().ok();
+ CoTaskMemFree(Some(raw.0 as *const _));
+ s.filter(|id| !id.is_empty())
+ }
+}
+
+fn device_friendly_name(device: &IMMDevice) -> Option<String> {
+ // SAFETY: Reads `PKEY_Device_FriendlyName` from the read-only property store.
+ unsafe {
+ let store = device.OpenPropertyStore(STGM_READ).ok()?;
+ let prop = store.GetValue(&PKEY_DEVICE_FRIENDLY_NAME).ok()?;
+ let s = prop.to_string();
+ let trimmed = s.trim();
+ (!trimmed.is_empty()).then(|| trimmed.to_owned())
+ }
+}
+
+/// Lists active audio render (output) endpoints on this PC, marking the current
+/// default console output (`is_default: true`) and sorting the default first.
+pub fn output_devices() -> Vec<nectarlink_core::AudioOutputDevice> {
+ let _com = ComGuard::new();
+ // SAFETY: Enumerates active render endpoints via `IMMDeviceEnumerator`.
+ unsafe {
+ let Ok(enumerator) =
+ CoCreateInstance::<_, IMMDeviceEnumerator>(&MMDeviceEnumerator, None, CLSCTX_ALL)
+ else {
+ return Vec::new();
+ };
+ let default_id =
+ enumerator.GetDefaultAudioEndpoint(eRender, eConsole).ok().and_then(|d| device_id_string(&d));
+ let Ok(collection) = enumerator.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE) else {
+ return Vec::new();
+ };
+ let count = collection.GetCount().unwrap_or(0);
+ let mut out = Vec::with_capacity(count as usize);
+ for i in 0..count {
+ let Ok(dev) = collection.Item(i) else { continue };
+ let Some(id) = device_id_string(&dev) else { continue };
+ let name = device_friendly_name(&dev).unwrap_or_else(|| "Speakers".into());
+ let is_default = default_id.as_deref() == Some(id.as_str());
+ out.push(nectarlink_core::AudioOutputDevice { id, name, is_default });
+ }
+ out.sort_by(|a, b| b.is_default.cmp(&a.is_default).then_with(|| a.name.cmp(&b.name)));
+ out
+ }
+}
+
+/// Calls `changed` (on a worker thread, a moment after a burst of changes)
+/// whenever Windows reports a change to the default speaker's or
+/// microphone's volume or mute, or to the output devices (one plugged in or
+/// out, a new default). This replaces polling: nothing runs while nothing
+/// changes.
+pub fn watch(changed: fn()) {
+ std::thread::Builder::new().name("audio-watch".into()).spawn(move || watch_thread(changed)).ok();
+}
+
+#[windows::core::implement(IMMNotificationClient)]
+struct DeviceEvents(std::sync::mpsc::Sender<Notice>);
+
+#[windows::core::implement(IAudioEndpointVolumeCallback)]
+struct VolumeEvents(std::sync::mpsc::Sender<Notice>);
+
+enum Notice {
+ /// A volume or mute changed.
+ Volume,
+ /// Devices changed; the default ones may be different now.
+ Devices,
+}
+
+impl IMMNotificationClient_Impl for DeviceEvents_Impl {
+ fn OnDeviceStateChanged(&self, _: &PCWSTR, _: DEVICE_STATE) -> windows::core::Result<()> {
+ let _ = self.0.send(Notice::Devices);
+ Ok(())
+ }
+ fn OnDeviceAdded(&self, _: &PCWSTR) -> windows::core::Result<()> {
+ let _ = self.0.send(Notice::Devices);
+ Ok(())
+ }
+ fn OnDeviceRemoved(&self, _: &PCWSTR) -> windows::core::Result<()> {
+ let _ = self.0.send(Notice::Devices);
+ Ok(())
+ }
+ fn OnDefaultDeviceChanged(&self, _: EDataFlow, role: ERole, _: &PCWSTR) -> windows::core::Result<()> {
+ if role == eConsole {
+ let _ = self.0.send(Notice::Devices);
+ }
+ Ok(())
+ }
+ fn OnPropertyValueChanged(&self, _: &PCWSTR, _: &PROPERTYKEY) -> windows::core::Result<()> {
+ // Very chatty and rarely relevant (a renamed device shows on the
+ // next other change).
+ Ok(())
+ }
+}
+
+impl IAudioEndpointVolumeCallback_Impl for VolumeEvents_Impl {
+ fn OnNotify(&self, _: *mut AUDIO_VOLUME_NOTIFICATION_DATA) -> windows::core::Result<()> {
+ let _ = self.0.send(Notice::Volume);
+ Ok(())
+ }
+}
+
+fn watch_thread(changed: fn()) {
+ let _com = ComGuard::new();
+ let (tx, rx) = std::sync::mpsc::channel();
+ // SAFETY: Core Audio COM calls on this MTA thread; the callbacks only
+ // send on a channel, and are unregistered before they're dropped.
+ unsafe {
+ let Ok(enumerator) =
+ CoCreateInstance::<_, IMMDeviceEnumerator>(&MMDeviceEnumerator, None, CLSCTX_ALL)
+ else {
+ return;
+ };
+ let devices: IMMNotificationClient = DeviceEvents(tx.clone()).into();
+ if enumerator.RegisterEndpointNotificationCallback(&devices).is_err() {
+ return;
+ }
+ let volume: IAudioEndpointVolumeCallback = VolumeEvents(tx).into();
+ // The default speaker and microphone being watched.
+ let mut watched: Vec<IAudioEndpointVolume> = Vec::new();
+ let rewatch = |watched: &mut Vec<IAudioEndpointVolume>| {
+ for ep in watched.drain(..) {
+ let _ = ep.UnregisterControlChangeNotify(&volume);
+ }
+ for flow in [eRender, eCapture] {
+ if let Ok(ep) = endpoint_volume(flow)
+ && ep.RegisterControlChangeNotify(&volume).is_ok()
+ {
+ watched.push(ep);
+ }
+ }
+ };
+ rewatch(&mut watched);
+ while let Ok(first) = rx.recv() {
+ // Settle: a slider drag or a device switch sends many at once.
+ let mut devices_changed = matches!(first, Notice::Devices);
+ while let Ok(next) = rx.recv_timeout(std::time::Duration::from_millis(150)) {
+ devices_changed |= matches!(next, Notice::Devices);
+ }
+ if devices_changed {
+ rewatch(&mut watched);
+ }
+ changed();
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
#[test]
- fn reads_speaker_and_mic_state_without_mutating() {
+ fn reads_speaker_mic_and_output_devices_without_mutating() {
if let Some((vol, _muted)) = speaker_state() {
assert!(vol <= 100);
}
let _ = mic_muted();
+ let devices = output_devices();
+ assert!(devices.iter().filter(|d| d.is_default).count() <= 1);
+ for d in &devices {
+ assert!(!d.id.is_empty());
+ assert!(!d.name.is_empty());
+ }
}
}
diff --git a/desktop/app/src/win/shell.rs b/desktop/app/src/win/shell.rs
index 0b8baf3..06d7444 100644
--- a/desktop/app/src/win/shell.rs
+++ b/desktop/app/src/win/shell.rs
@@ -3,7 +3,14 @@
use windows::{
Win32::{
- System::{Power::SetSuspendState, Shutdown::LockWorkStation},
+ System::{
+ Power::SetSuspendState,
+ Registry::{
+ HKEY, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, KEY_READ, RegCloseKey, RegOpenKeyExW,
+ RegQueryValueExW,
+ },
+ Shutdown::LockWorkStation,
+ },
UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_SHOWNORMAL},
},
core::{HSTRING, w},
@@ -18,6 +25,117 @@ pub fn open_url(url: &str) -> Result<(), String> {
if result.0 as isize > 32 { Ok(()) } else { Err(format!("ShellExecute returned {}", result.0 as isize)) }
}
+/// Opens a `mailto:` link in the default mail client.
+pub fn open_mailto(email: &str) -> Result<(), String> {
+ let trimmed = email.trim();
+ if trimmed.is_empty() {
+ return Err("empty email address".into());
+ }
+ open_url(&format!("mailto:{trimmed}"))
+}
+
+/// Opens a street address in the registered Windows maps handler if one is
+/// installed, or in the default browser via a maps web URL otherwise
+/// (Windows 11 deprecated the built-in Maps app, so `bingmaps:` / `ms-maps:`
+/// are only used when an active handler is registered).
+pub fn open_maps(address: &str) -> Result<(), String> {
+ let trimmed = address.trim();
+ if trimmed.is_empty() {
+ return Err("empty address".into());
+ }
+ for scheme in ["bingmaps", "ms-maps"] {
+ if is_url_scheme_registered(scheme) {
+ let uri = format!("{scheme}:?where={}", nectarlink_core::clip_kind::percent_encode(trimmed));
+ if open_url(&uri).is_ok() {
+ return Ok(());
+ }
+ }
+ }
+ open_url(&nectarlink_core::maps_web_url(trimmed))
+}
+
+/// Returns `true` if `scheme` has an installed classic command handler or an
+/// active `UserChoice` `ProgId` under `HKEY_CLASSES_ROOT`.
+pub fn is_url_scheme_registered(scheme: &str) -> bool {
+ let scheme = scheme.trim();
+ if scheme.is_empty() || scheme.contains('\\') {
+ return false;
+ }
+ // 1. Classic handler: HKCR\<scheme> has "URL Protocol" and shell\open\command exists.
+ if key_has_value(HKEY_CLASSES_ROOT, scheme, "URL Protocol")
+ && key_exists(HKEY_CLASSES_ROOT, &format!(r"{scheme}\shell\open\command"))
+ {
+ return true;
+ }
+ // 2. Modern AppX/MSIX handler: UserChoice ProgId exists and is registered in HKCR.
+ let assoc_path =
+ format!(r"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\{scheme}\UserChoice");
+ if let Some(prog_id) = read_reg_sz(HKEY_CURRENT_USER, &assoc_path, "ProgId")
+ && !prog_id.is_empty()
+ && key_exists(HKEY_CLASSES_ROOT, &prog_id)
+ {
+ return true;
+ }
+ false
+}
+
+fn key_exists(root: HKEY, subkey: &str) -> bool {
+ let mut key = HKEY::default();
+ // SAFETY: read-only RegOpenKeyExW; closed immediately on success.
+ let status = unsafe { RegOpenKeyExW(root, &HSTRING::from(subkey), None, KEY_READ, &mut key) };
+ if status.is_ok() {
+ unsafe {
+ let _ = RegCloseKey(key);
+ }
+ true
+ } else {
+ false
+ }
+}
+
+fn key_has_value(root: HKEY, subkey: &str, value_name: &str) -> bool {
+ let mut key = HKEY::default();
+ // SAFETY: read-only RegOpenKeyExW + RegQueryValueExW; key closed below.
+ if unsafe { RegOpenKeyExW(root, &HSTRING::from(subkey), None, KEY_READ, &mut key) }.is_err() {
+ return false;
+ }
+ let exists = unsafe { RegQueryValueExW(key, &HSTRING::from(value_name), None, None, None, None) }.is_ok();
+ unsafe {
+ let _ = RegCloseKey(key);
+ }
+ exists
+}
+
+fn read_reg_sz(root: HKEY, subkey: &str, value_name: &str) -> Option<String> {
+ let mut key = HKEY::default();
+ // SAFETY: read-only RegOpenKeyExW + RegQueryValueExW; key closed below.
+ if unsafe { RegOpenKeyExW(root, &HSTRING::from(subkey), None, KEY_READ, &mut key) }.is_err() {
+ return None;
+ }
+ let val_h = HSTRING::from(value_name);
+ let mut size: u32 = 0;
+ let status = unsafe { RegQueryValueExW(key, &val_h, None, None, None, Some(&mut size)) };
+ if status.is_err() || size < 2 {
+ unsafe {
+ let _ = RegCloseKey(key);
+ }
+ return None;
+ }
+ let mut buf = vec![0u16; (size as usize).div_ceil(2)];
+ let mut byte_len = (buf.len() * 2) as u32;
+ let status = unsafe {
+ RegQueryValueExW(key, &val_h, None, None, Some(buf.as_mut_ptr().cast::<u8>()), Some(&mut byte_len))
+ };
+ unsafe {
+ let _ = RegCloseKey(key);
+ }
+ if status.is_err() {
+ return None;
+ }
+ let len = buf.iter().position(|&c| c == 0).unwrap_or(buf.len());
+ Some(String::from_utf16_lossy(&buf[..len]))
+}
+
/// Starts a program with arguments (Windows asks for permission when it
/// needs administrator rights).
pub fn run(program: &std::path::Path, arguments: &str) -> Result<(), String> {
@@ -92,3 +210,15 @@ pub fn run_command(command: &str) -> Result<(), String> {
.map(|_| ())
.map_err(|e| format!("failed to run command: {e}"))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn url_scheme_registration_distinguishes_registered_and_unregistered_schemes() {
+ assert!(is_url_scheme_registered("http"));
+ assert!(!is_url_scheme_registered("nectarlink-nonexistent-scheme"));
+ assert!(!is_url_scheme_registered(""));
+ }
+}
diff --git a/docs/protocol/capabilities.md b/docs/protocol/capabilities.md
index 0eef242..3547c1f 100644
--- a/docs/protocol/capabilities.md
+++ b/docs/protocol/capabilities.md
@@ -81,5 +81,7 @@ capability is missing.
| `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` | Shares its Deck layout and live tile state and runs Deck actions ([deck](deck.md)) | app update |
+| `pc.audio` | Reports active audio output devices in `deck.state` and accepts `pc.audio.set` volume/mute changes ([deck](deck.md)) | app update |
| `camera.virtual` | Receives and decodes a phone's camera stream ([webcam](webcam.md)) | app update |
| `addon.vcam` | The virtual camera add-on is installed ([webcam](webcam.md)) | installing the add-on |
+
diff --git a/docs/protocol/clipboard.md b/docs/protocol/clipboard.md
index d7b0972..813ff83 100644
--- a/docs/protocol/clipboard.md
+++ b/docs/protocol/clipboard.md
@@ -73,4 +73,13 @@ PNG arrived; Android as a content URI from the app's own provider.
Android: clips marked `ClipDescription.EXTRA_IS_SENSITIVE`.
- **No echoes.** A device does not send text it just received with
`clip.set`.
-- Implementations **MUST NOT** log clipboard content (v0 §11).
+- **Smart clipboard context chips (local only).** When a text clip arrives via
+ `clip.set` and is not a one-time code (`otp::is_otp_clip`), `nectarlink-core`
+ classifies it locally (`clip_kind::classify_clip`) into at most one suggestion
+ (`WebLink` → `"Open"`, `StreetAddress` → `"Open in Maps"`, `PhoneNumber` →
+ `"Call"`, `TrackingNumber` → `"Track"`, `Email` → `"Email"`). Both apps offer
+ that single chip on the received-clip confirmation when `"Suggest actions for
+ copied text"` is enabled (on by default).
+- Implementations **MUST NOT** log clipboard content (v0 §11); only the
+ classified `ClipKind` may be logged.
+
diff --git a/docs/protocol/deck.md b/docs/protocol/deck.md
index 03fb192..4d262fd 100644
--- a/docs/protocol/deck.md
+++ b/docs/protocol/deck.md
@@ -17,9 +17,10 @@ never sends commands, file paths, or URLs.
| 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`) |
+| `pc.audio` | desktop | Reports active audio output devices in `deck.state` and accepts `pc.audio.set` requests (`media.pc_audio`) |
- **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.
+ - `remote_input` (**off by default**): required for all `deck.press` and `pc.audio.set` requests. When a paired phone presses a tile, adjusts PC audio, 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
@@ -27,10 +28,11 @@ never sends commands, file paths, or URLs.
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
+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 = "pc.audio.set" id = n b = { volume?: uint, muted?: bool } // phone → PC
+t = "ok" re = n
```
### 2.1 `deck.layout`
@@ -52,24 +54,31 @@ DeckPage = {
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
+ icon: text, // from the fixed icon set (§2.5)
+ color: text, // from the fixed color set (§2.5)
+ kind: text, // action kind (§2.5); 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.
+Sent by a PC that offers `deck.actions` or `pc.audio` when a session starts and
+whenever the PC's media playback state, speaker volume/mute, microphone mute
+state, or active audio output devices change.
```
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
+ playing: bool, // PC media is currently playing (`media_play_pause` tiles)
+ volume: uint, // PC master speaker volume, 0..=100 (`volume_*` tiles and phone audio slider)
+ muted: bool, // PC speaker is muted (`volume_*` tiles and phone audio bar)
+ mic_muted?: bool, // default PC microphone is muted (`mic_mute` tiles); omitted when no capture device exists
+ output_devices?: [AudioOutputDevice], // active PC playback endpoints (0..=32)
+}
+
+AudioOutputDevice = {
+ id: text, // 1..=256 UTF-8 bytes, no control chars
+ name: text, // 1..=128 UTF-8 bytes, friendly endpoint name
+ is_default: bool, // true for the current default multimedia render endpoint
}
```
@@ -90,7 +99,27 @@ Errors:
- `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
+### 2.4 `pc.audio.set`
+
+Sets the PC's master speaker volume (`0..=100`) and/or mute state via Windows
+Core Audio (`IAudioEndpointVolume`), then pushes the updated `deck.state`.
+
+```
+PcAudioSet = {
+ volume?: uint, // 0..=100
+ muted?: bool,
+}
+```
+
+At least one of `volume` or `muted` must be present.
+
+Errors:
+- `BAD_MESSAGE` when both `volume` and `muted` are omitted or `volume > 100`.
+- `UNSUPPORTED` when the PC does not offer `pc.audio` or `deck.actions`.
+- `DENIED` when `remote_input` is off for the phone.
+- `INTERNAL` when the audio endpoint update fails on the PC.
+
+### 2.5 Action kinds, icons, and colors
- **Action kinds (`kind`):**
- Media: `"media_play_pause"`, `"media_next"`, `"media_previous"`