Skip to content

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

Fix the Android pairing screen in dark mode; quicker offline and toggles

Bee63366f61be4f
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 61e7aed..2e28d8b 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
@@ -15,11 +15,13 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
+import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
+import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -69,7 +71,11 @@ class MainActivity : ComponentActivity() {
if (state.devices.isNotEmpty()) ConnectionService.start(this@MainActivity)
}
NectarlinkTheme(appearance) {
- App(core, state, preferences)
+ // Every screen sits on the theme's background, not the
+ // window's (which can't follow the app's own light/dark choice).
+ Surface(color = MaterialTheme.colorScheme.background) {
+ App(core, state, preferences)
+ }
}
}
}
@@ -145,7 +151,7 @@ private fun App(core: Core, state: CoreState, preferences: Preferences) {
) { padding ->
val modifier = Modifier.fillMaxSize().padding(padding)
when (tab) {
- Tab.Home -> HomeScreen(state, core::ring, core::stopRinging, modifier)
+ Tab.Home -> HomeScreen(state, core::ring, core::stopRinging, onPairNew = { pairing = true }, modifier = modifier)
Tab.Settings -> SettingsScreen(
state = state,
appearance = preferences.appearance.collectAsStateWithLifecycle().value,
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 3e8a276..b618cf1 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
@@ -18,6 +18,8 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.AssistChip
import androidx.compose.material3.Button
import androidx.compose.material3.FilledTonalButton
+import androidx.compose.material3.FilledTonalIconButton
+import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
@@ -28,6 +30,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.nectarlink.android.R
@@ -44,6 +47,7 @@ fun HomeScreen(
state: CoreState,
onRing: (id: String, on: Boolean) -> Unit,
onStopRinging: () -> Unit,
+ onPairNew: () -> Unit,
modifier: Modifier = Modifier,
) {
LazyColumn(
@@ -52,11 +56,16 @@ fun HomeScreen(
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
item {
- Text(
- stringResource(R.string.home_title),
- style = MaterialTheme.typography.headlineMedium,
- modifier = Modifier.padding(top = 8.dp, bottom = 4.dp),
- )
+ Row(Modifier.padding(top = 8.dp, bottom = 4.dp), verticalAlignment = Alignment.CenterVertically) {
+ Text(
+ stringResource(R.string.home_title),
+ style = MaterialTheme.typography.headlineMedium,
+ modifier = Modifier.weight(1f),
+ )
+ FilledTonalIconButton(onClick = onPairNew) {
+ Icon(painterResource(R.drawable.ic_qr), contentDescription = stringResource(R.string.action_pair_new))
+ }
+ }
}
state.ringingFrom?.let { from ->
item { RingingBanner(from, onStopRinging) }
diff --git a/android/app/src/main/res/drawable/ic_qr.xml b/android/app/src/main/res/drawable/ic_qr.xml
new file mode 100644
index 0000000..7f215c5
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_qr.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
+<!-- Scan a QR code: viewfinder corners around a code. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
+ <path android:pathData="M4,8V6a2,2 0,0 1,2,-2h2M16,4h2a2,2 0,0 1,2,2v2M20,16v2a2,2 0,0 1,-2,2h-2M8,20H6a2,2 0,0 1,-2,-2v-2"
+ android:strokeColor="#FF000000" android:strokeWidth="1.8" android:strokeLineCap="round"
+ android:strokeLineJoin="round" android:fillColor="#00000000" />
+ <path android:pathData="M8.5,8.5h2.5v2.5h-2.5zM13,8.5h2.5v2.5h-2.5zM8.5,13h2.5v2.5h-2.5zM13.5,13.5h1.5v1.5h-1.5z"
+ android:fillColor="#FF000000" />
+</vector>
\ No newline at end of file
diff --git a/android/app/src/main/res/values-night/colors.xml b/android/app/src/main/res/values-night/colors.xml
new file mode 100644
index 0000000..3563a56
--- /dev/null
+++ b/android/app/src/main/res/values-night/colors.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
+<resources>
+ <!-- Bloom honey, dark (docs/design/tokens.json). -->
+ <color name="surface">#17130E</color>
+ <color name="primary">#FFB95F</color>
+</resources>
\ No newline at end of file
diff --git a/android/app/src/main/res/values-night/themes.xml b/android/app/src/main/res/values-night/themes.xml
new file mode 100644
index 0000000..9a0fd7c
--- /dev/null
+++ b/android/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
+<resources>
+ <!-- Dark mode: the window behind Compose is dark too, so launching
+ doesn't flash a light screen. -->
+ <style name="Theme.Nectarlink" parent="android:Theme.Material.NoActionBar">
+ <item name="android:windowBackground">@color/surface</item>
+ <item name="android:statusBarColor">@android:color/transparent</item>
+ <item name="android:navigationBarColor">@android:color/transparent</item>
+ </style>
+</resources>
\ No newline at end of file
diff --git a/core/nectarlink-core/src/node.rs b/core/nectarlink-core/src/node.rs
index 8aba598..6abec51 100644
--- a/core/nectarlink-core/src/node.rs
+++ b/core/nectarlink-core/src/node.rs
@@ -12,7 +12,7 @@ use std::{
use iroh::{
Endpoint, EndpointAddr, RelayMode,
address_lookup::{DnsAddressLookup, MemoryLookup, PkarrPublisher, PkarrResolver},
- endpoint::{Connection, VarInt, presets},
+ endpoint::{Connection, QuicTransportConfig, VarInt, presets},
endpoint_info::{EndpointInfo, UserData},
protocol::{AcceptError, ProtocolHandler, Router},
};
@@ -41,6 +41,11 @@ const BACKOFF_MAX: Duration = Duration::from_secs(30);
/// How long the device with the higher ID waits before dialing (see `maintain`).
const DEFER_DIAL: Duration = Duration::from_millis(750);
const EVENT_CAPACITY: usize = 512;
+/// A connection with no traffic for this long is dead. iroh sends a
+/// keep-alive every 5 s, so a healthy link is never idle that long, and a
+/// device that drops off the network shows as offline within seconds
+/// instead of after QUIC's default of 30 s.
+const IDLE_TIMEOUT: Duration = Duration::from_secs(8);
/// Capabilities every build offers.
const BASE_CAPABILITIES: &[&str] = &["core.ping", "device.battery", "device.ring"];
@@ -804,9 +809,13 @@ async fn bind_endpoint(
secret: iroh::SecretKey,
ports: Option<Ports>,
) -> Result<Endpoint> {
+ let transport = QuicTransportConfig::builder()
+ .max_idle_timeout(Some(IDLE_TIMEOUT.try_into().expect("the idle timeout fits a QUIC varint")))
+ .build();
let mut builder = Endpoint::builder(presets::Minimal)
.secret_key(secret)
- .alpns(vec![ALPN_SESSION.to_vec(), ALPN_PAIR.to_vec()]);
+ .alpns(vec![ALPN_SESSION.to_vec(), ALPN_PAIR.to_vec()])
+ .transport_config(transport);
builder = if config.away_mode {
builder
.relay_mode(RelayMode::Default)
diff --git a/desktop/app/qml/components/Toggle.qml b/desktop/app/qml/components/Toggle.qml
index f22ca7f..d748108 100644
--- a/desktop/app/qml/components/Toggle.qml
+++ b/desktop/app/qml/components/Toggle.qml
@@ -44,8 +44,9 @@ FocusScope {
anchors.verticalCenter: parent.verticalCenter
x: toggle.checked ? parent.width - width - 4.5 : 6.5
color: toggle.checked ? Theme.primaryContent : Theme.outline
- Behavior on x { SpringAnimation { spring: Theme.springSnappy; damping: Theme.dampingSnappy } }
- Behavior on size { SpringAnimation { spring: Theme.springSnappy; damping: Theme.dampingSnappy } }
+ // Quick and settled, never springy: a switch must feel immediate.
+ Behavior on x { NumberAnimation { duration: Theme.reduceMotion ? 0 : 140; easing.type: Easing.OutCubic } }
+ Behavior on size { NumberAnimation { duration: Theme.reduceMotion ? 0 : 140; easing.type: Easing.OutCubic } }
Behavior on color { ColorAnimation { duration: Theme.fadeFast } }
}
}
diff --git a/desktop/app/src/bridge/prefs.rs b/desktop/app/src/bridge/prefs.rs
index c227b04..b769703 100644
--- a/desktop/app/src/bridge/prefs.rs
+++ b/desktop/app/src/bridge/prefs.rs
@@ -1,7 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//! `Preferences`: the app's look and behavior, saved whenever it changes.
-use std::pin::Pin;
+use std::{
+ pin::Pin,
+ sync::{
+ Mutex,
+ atomic::{AtomicU64, Ordering},
+ },
+};
use cxx_qt::CxxQtType;
use cxx_qt_lib::QString;
@@ -88,8 +94,27 @@ impl qobject::Preferences {
backdrop: p.backdrop,
close_to_tray: p.close_to_tray,
};
+ save_in_background(settings);
+ }
+}
+
+/// Saves off the UI thread (the write is flushed to disk, which can take a
+/// moment), newest settings last even when changes come in quick succession.
+fn save_in_background(settings: Settings) {
+ static NEXT: AtomicU64 = AtomicU64::new(0);
+ static WRITTEN: Mutex<u64> = Mutex::new(0);
+ let seq = NEXT.fetch_add(1, Ordering::SeqCst) + 1;
+ let save = move || {
+ let mut written = WRITTEN.lock().unwrap_or_else(|e| e.into_inner());
+ if *written > seq {
+ return; // A newer save already ran.
+ }
if let Err(e) = settings.save(&core_host::host().data_dir) {
tracing::warn!(error = %e, "can't save preferences");
}
+ *written = seq;
+ };
+ if let Err(e) = std::thread::Builder::new().name("save-preferences".into()).spawn(save) {
+ tracing::warn!(error = %e, "can't save preferences");
}
}