diff --git a/AGENTS.md b/AGENTS.md index df569d30..f3c31bcc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,7 +28,7 @@ ## Coding Style & Naming Conventions - Follow `flutter_lints`, use `lowerCamelCase`/`UpperCamelCase`/`snake_case`, prefer `StatelessWidget` + `Consumer`, and use `const` constructors. - Material widgets only (no Cupertino); center app bar titles (`centerTitle: true`); prefix private members with `_`. -- Keep screens simple, handle disconnects by returning to the scanner, and avoid premature abstractions (don't add a helper until it is needed in 3+ places). +- Keep screens simple, keep the main screens open and read-only when the radio disconnects (see `documentation/offline-mode.md`), and avoid premature abstractions (don't add a helper until it is needed in 3+ places). - Avoid unnecessary comments, feature flags, and backwards-compatibility shims. ## Testing Guidelines diff --git a/CLAUDE.md b/CLAUDE.md index 9a348612..ef21d2be 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -39,7 +39,7 @@ For Linux, use `nix develop`; see [Linux with Nix](README.md#linux-with-nix) for | Serial marker/length framing | `lib/services/usb_serial_frame_codec.dart` | | ACK tracking and retry scheduling | `lib/services/message_retry_service.dart` | | Route scoring/history | `lib/services/path_history_service.dart` | -| Preferences and JSON stores | `lib/storage/` | +| Preferences, native history database, and JSON stores | `lib/storage/` | | Region list and channel/default assignments | `lib/storage/region_store.dart`, `lib/storage/channel_region_store.dart` | | Message filter (rules, duplicate/spam checks, on-device classifier) | `lib/services/message_filter/`, `lib/models/message_filter.dart`, `lib/storage/message_filter_store.dart`, `lib/screens/message_filter_settings_screen.dart`, `lib/screens/filtered_messages_screen.dart` | | Translation models/inference | `lib/services/translation_service.dart` | @@ -47,10 +47,12 @@ For Linux, use `nix develop`; see [Linux with Nix](README.md#linux-with-nix) for | Image reassembly and file persistence | `lib/services/received_image_store.dart`, `lib/services/received_image_blob_store_io.dart` | | Material themes | `lib/theme/mesh_theme.dart` | | Screens and reusable UI | `lib/screens/`, `lib/widgets/` | -| Localization | `lib/l10n/` (18 locales) | +| Localization | `lib/l10n/` (19 locales) | `Provider`/`ChangeNotifier` drives UI state. `main.dart` wires `MeshTheme.light()` and `MeshTheme.dark()` and uses the saved theme preference. Its `MultiProvider` exposes `MeshCoreConnector`, `MessageRetryService`, `PathHistoryService`, `AppSettingsService`, `BleDebugLogService`, `AppDebugLogService`, `ChatTextScaleService`, `TranslationService`, `UiViewStateService`, `StorageService` (plain `Provider`), `MapTileCacheService`, `TimeoutPredictionService`, `ImageCodecService`, `ReceivedImageStore`, and `MessageFilterService`; screens read them with `Consumer`, `context.watch()`, or `context.read()`. +Message/channel histories use indexed SQLite rows on native platforms, and route histories use the same database. Web builds use preferences. Startup imports old history preferences once; backup and review-mode cleanup include database histories. See [local history storage](documentation/performance-profiling.md#local-history-storage). + Most JSON stores scope keys by the first 10 hex chars of the connected device's public key, so per-radio data stays isolated; some preferences, including the saved region-name list, are global. Model bundles, received images, and caches use files. ## Localization @@ -70,3 +72,5 @@ Android builds currently include ARM64 only and use Java 17. iOS targets 16.4. R ## Documentation Use the [feature index](documentation/README.md), [regions](documentation/regions.md), [image messages](documentation/image-messages.md), [message filter](documentation/message-filter.md), and [routing reference](documentation/routing-paths.md). Keep protocol details in the canonical reference rather than maintaining competing command tables. + +Follow the [UI design reference](documentation/design.md) for any UI work, and update it in the same change when you add or change a UI pattern. diff --git a/README.md b/README.md index 31fb94dc..caa1dcff 100644 --- a/README.md +++ b/README.md @@ -428,7 +428,7 @@ Messages are transmitted as binary frames using a custom protocol optimized for ### App Settings - **Theme**: System default, light, or dark mode -- **Language**: Use one of 18 languages (English, Chinese, French, Spanish, Portuguese, German, Dutch, Polish, Swedish, Italian, Slovak, Slovenian, Bulgarian, Russian, Ukrainian, Hungarian, Japanese, Korean) +- **Language**: Use one of 19 languages (English, Chinese, French, Spanish, Portuguese, German, Dutch, Polish, Swedish, Italian, Slovak, Czech, Slovenian, Bulgarian, Russian, Ukrainian, Hungarian, Japanese, Korean) - **Notifications**: Configurable for messages, channels, and node advertisements; per-channel muting; reply, mark-as-read, and mute actions on Android notifications and watches (reply and mark-as-read in Android Auto when built with `--android-project-arg=androidAuto=true`) - **Battery Chemistry**: Support for NMC, LiFePO4, LiPo, and LiPo HV battery types - **Message Retry**: Automatic retry with configurable path clearing diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 96e61afb..987aae02 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -130,4 +130,6 @@ flutter { dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4") + // enableEdgeToEdge() for Android 15+ edge-to-edge enforcement. + implementation("androidx.activity:activity-ktx:1.13.0") } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index f25683d7..20656e86 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -29,7 +29,11 @@ android:name="com.pravera.flutter_foreground_task.service.ForegroundService" android:exported="false" android:foregroundServiceType="connectedDevice" - android:stopWithTask="false" /> + android:stopWithTask="true" /> + + ) { + val view = host + if (view == null) { + onReady.accept(Rect()) + return + } + invoke("search", null) { result -> + val map = result as? Map<*, *> + val surface = findFlutterSurface(view) + if (map == null || surface == null) { + onReady.accept(Rect()) + return@invoke + } + flutterBounds = Rect( + map.int("left"), + map.int("top"), + map.int("right"), + map.int("bottom"), + ) + // Convert to the host view's coordinates. + val hostLoc = IntArray(2).also { view.getLocationInWindow(it) } + val surfLoc = IntArray(2).also { surface.getLocationInWindow(it) } + val bounds = Rect(flutterBounds) + bounds.offset(surfLoc[0] - hostLoc[0], surfLoc[1] - hostLoc[1]) + onReady.accept(bounds) + } + } + + override fun onScrollCaptureStart( + session: ScrollCaptureSession, + signal: CancellationSignal, + onReady: Runnable, + ) { + invoke("start", null) { onReady.run() } + } + + override fun onScrollCaptureImageRequest( + session: ScrollCaptureSession, + signal: CancellationSignal, + captureArea: Rect, + onComplete: Consumer, + ) { + val args = mapOf("top" to captureArea.top, "bottom" to captureArea.bottom) + invoke("scroll", args) { result -> + val scrolled = ((result as? Number)?.toDouble() ?: 0.0).roundToInt() + // The part of the requested strip now on screen, in scroll-bounds + // coordinates relative to the current scroll position. + val visibleTop = max(captureArea.top - scrolled, 0) + val visibleBottom = min(captureArea.bottom - scrolled, flutterBounds.height()) + val left = max(captureArea.left, 0) + val right = min(captureArea.right, flutterBounds.width()) + if (visibleBottom <= visibleTop || right <= left || signal.isCanceled) { + onComplete.accept(Rect()) + return@invoke + } + val source = Rect( + flutterBounds.left + left, + flutterBounds.top + visibleTop, + flutterBounds.left + right, + flutterBounds.top + visibleBottom, + ) + val captured = Rect(left, visibleTop + scrolled, right, visibleBottom + scrolled) + // Give the raster thread a moment to present the scrolled frame. + handler.postDelayed({ + copyPixels(source) { bitmap -> + if (bitmap == null || signal.isCanceled) { + onComplete.accept(Rect()) + return@copyPixels + } + try { + val canvas = session.surface.lockHardwareCanvas() + try { + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR) + canvas.drawBitmap(bitmap, 0f, 0f, null) + } finally { + session.surface.unlockCanvasAndPost(canvas) + } + onComplete.accept(captured) + } catch (e: Exception) { + onComplete.accept(Rect()) + } finally { + bitmap.recycle() + } + } + }, FRAME_SETTLE_MS) + } + } + + override fun onScrollCaptureEnd(onReady: Runnable) { + invoke("end", null) { onReady.run() } + } + + private fun copyPixels(source: Rect, done: (Bitmap?) -> Unit) { + val view = host + val surface = view?.let { findFlutterSurface(it) } + val bitmap = Bitmap.createBitmap(source.width(), source.height(), Bitmap.Config.ARGB_8888) + when (surface) { + is SurfaceView -> PixelCopy.request(surface, source, bitmap, { code -> + if (code == PixelCopy.SUCCESS) { + done(bitmap) + } else { + bitmap.recycle() + done(null) + } + }, handler) + is TextureView -> { + val full = surface.bitmap + if (full == null) { + bitmap.recycle() + done(null) + } else { + android.graphics.Canvas(bitmap).drawBitmap( + full, + source, + Rect(0, 0, source.width(), source.height()), + null, + ) + full.recycle() + done(bitmap) + } + } + else -> { + bitmap.recycle() + done(null) + } + } + } + + /** The view Flutter renders into (SurfaceView by default). */ + private fun findFlutterSurface(view: View): View? { + if (view is SurfaceView || view is TextureView) return view + if (view is ViewGroup) { + for (i in 0 until view.childCount) { + findFlutterSurface(view.getChildAt(i))?.let { return it } + } + } + return null + } + + private fun invoke(method: String, args: Any?, onResult: (Any?) -> Unit) { + if (activity.isFinishing) { + onResult(null) + return + } + channel.invokeMethod(method, args, object : MethodChannel.Result { + override fun success(result: Any?) = onResult(result) + override fun error(code: String, message: String?, details: Any?) = onResult(null) + override fun notImplemented() = onResult(null) + }) + } + + private fun Map<*, *>.int(key: String): Int = (this[key] as? Number)?.toInt() ?: 0 + + private companion object { + const val FRAME_SETTLE_MS = 48L + } +} diff --git a/android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt b/android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt index ac104e12..19084b78 100644 --- a/android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt +++ b/android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt @@ -1,20 +1,42 @@ package com.meshcore.meshcore_open -import io.flutter.embedding.android.FlutterActivity +import android.os.Build +import android.os.Bundle +import android.view.View +import androidx.activity.enableEdgeToEdge +import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.engine.FlutterEngine -class MainActivity : FlutterActivity() { +// FlutterFragmentActivity (a ComponentActivity) so enableEdgeToEdge() works: +// Android 15+ enforces edge-to-edge for apps targeting SDK 35, and the app +// already draws behind the system bars and handles insets in Flutter. +class MainActivity : FlutterFragmentActivity() { private val usbFunctions by lazy { MeshcoreUsbFunctions(this) } + private var scrollCapture: FlutterScrollCapture? = null + + override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge() + super.onCreate(savedInstanceState) + } override fun configureFlutterEngine(flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) usbFunctions.configureFlutterEngine(flutterEngine) UnreadWidget.configureFlutterEngine(applicationContext, flutterEngine) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + scrollCapture?.detach() + scrollCapture = FlutterScrollCapture( + this, + flutterEngine.dartExecutor.binaryMessenger, + ).also { it.attach(findViewById(android.R.id.content)) } + } } override fun onDestroy() { // A rotation recreates the activity; only a real exit closes the app. if (!isChangingConfigurations) UnreadWidget.markAppClosed(applicationContext) + scrollCapture?.detach() + scrollCapture = null usbFunctions.dispose() super.onDestroy() } diff --git a/android/app/src/main/kotlin/com/meshcore/meshcore_open/MeshcoreUsbFunctions.kt b/android/app/src/main/kotlin/com/meshcore/meshcore_open/MeshcoreUsbFunctions.kt index 279ba8a7..c5306907 100644 --- a/android/app/src/main/kotlin/com/meshcore/meshcore_open/MeshcoreUsbFunctions.kt +++ b/android/app/src/main/kotlin/com/meshcore/meshcore_open/MeshcoreUsbFunctions.kt @@ -14,7 +14,7 @@ import android.hardware.usb.UsbManager import android.os.Build import android.os.Handler import android.os.Looper -import io.flutter.embedding.android.FlutterActivity +import android.app.Activity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.EventChannel import io.flutter.plugin.common.MethodCall @@ -24,7 +24,7 @@ import java.util.concurrent.ExecutorService import java.util.concurrent.Executors class MeshcoreUsbFunctions( - private val activity: FlutterActivity, + private val activity: Activity, ) { private companion object { const val usbRecipientInterface = 0x01 diff --git a/android/app/src/main/res/drawable/ic_stat_notification.xml b/android/app/src/main/res/drawable/ic_stat_notification.xml new file mode 100644 index 00000000..87bdcae5 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_stat_notification.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/assets/themes/christmas/map_self.jxl b/assets/themes/christmas/map_self.jxl index 5c5ac7de..ee6dfe7f 100644 Binary files a/assets/themes/christmas/map_self.jxl and b/assets/themes/christmas/map_self.jxl differ diff --git a/documentation/README.md b/documentation/README.md index 683894b9..64533529 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -17,7 +17,7 @@ MeshCore Open is an open-source Flutter client for MeshCore LoRa mesh networking 4. [Chat & Messaging](chat-and-messaging.md) - Direct messages, location sharing, message status, reactions, and retries 5. [Channels](channels.md) - Broadcast channels, communities, channel chat, and auto-resend 6. [Map & Location](map-and-location.md) - Node map, shared pins, path tracing, line-of-sight, and offline caching -7. [Settings](settings.md) - Device settings, app settings, radio configuration, and exports +7. [Settings](settings.md) - Device settings, app settings, radio configuration, backup/restore, and exports 8. [Notifications](notifications.md) - System notifications, replies from watches and Android Auto, unread badges, and notification preferences 9. [Repeater Management](repeater-management.md) - Repeater hub, status, CLI, telemetry, and neighbors 10. [Additional Features](additional-features.md) - GIF picker, localization, debug logs, SMAZ compression, and more @@ -31,6 +31,9 @@ MeshCore Open is an open-source Flutter client for MeshCore LoRa mesh networking 18. [Network Map](network-map.md) - Online repeater map, adding and managing repeaters from it, opt-in uploads, and hiding a repeater 19. [Themes](themes.md) - Color themes, custom icons and map markers, chat backgrounds, automatic holiday themes, and holiday message animations 20. [Message Filter](message-filter.md) - Hide spam and repeated channel messages with your own rules, automatic checks, and learning from Spam taps, all on the device +21. [UI Design Reference](design.md) - Contributor reference: theme, typography, spacing, shared widgets, sheets vs dialogs vs pages, states, and localization rules for UI changes +22. [Offline Mode](offline-mode.md) - Read-only view of the last radio's contacts, channels and messages while no radio is connected, and the Connect sheet +23. [Performance Profiling](performance-profiling.md) - Contributor reference: frame and memory baselines, HTTP capture retention, and resetting diagnostic recordings ## App Overview diff --git a/documentation/additional-features.md b/documentation/additional-features.md index 46b81f96..b160577d 100644 --- a/documentation/additional-features.md +++ b/documentation/additional-features.md @@ -26,7 +26,7 @@ A bottom sheet with a search field and a grid of GIF thumbnails. App Settings → Appearance → Language ### Supported Languages (18) -English, French, Spanish, German, Polish, Slovenian, Portuguese, Italian, Chinese, Swedish, Dutch, Slovak, Bulgarian, Russian, Ukrainian, Hungarian, Japanese, Korean +English, French, Spanish, German, Polish, Slovenian, Portuguese, Italian, Chinese, Swedish, Dutch, Slovak, Czech, Bulgarian, Russian, Ukrainian, Hungarian, Japanese, Korean ### How It Works - All UI strings go through Flutter's ARB localization system @@ -149,16 +149,15 @@ A full-screen informational page explaining that the web client requires Chrome. ### What It Does (Background Service) Maintains an in-memory LRU cache of up to 50 contacts, each with up to 100 route history entries, tracking: - Hop count and trip time -- Success/failure counts and route weights +- Success/failure counts (lifetime and faded) - Flood vs. direct discovery ### Path Scoring -Paths are scored using a weighted formula: reliability (45%), route weight (20%), latency (25%), and freshness (10%). These weights are internal and not user-configurable. Paths whose weight drops to zero or below are automatically deleted. Flood deliveries that receive an ACK give a weight boost (+0.5) to the specific return path. +Each route keeps delivery and failure counts that fade over time (half their weight per day, at most 16 recent results). For each send attempt a route is chosen by Thompson sampling over those counts, adjusted slightly for speed and for what the radio currently hears. There are no user-tunable weights. A route is deleted only when it keeps failing and hasn't delivered for a week. Flood deliveries that receive an ACK credit the specific return path. Details: [Auto route selection](routing-paths.md#auto-route-selection). Used internally for: -- **Auto route rotation**: Cycles through known paths using configurable weights on retries, with a diversity window to avoid re-using recently tried paths -- **Path selection**: Picks the best-scored path for each retry attempt -- **Flood statistics**: Tracks flood vs. direct discovery ratios +- **Auto route rotation**: Picks a route for each attempt; retries usually move to a different route, and the last attempt floods +- **Flood statistics**: Tracks flood deliveries and failures --- diff --git a/documentation/channels.md b/documentation/channels.md index f3dc9d6e..d9dd58f7 100644 --- a/documentation/channels.md +++ b/documentation/channels.md @@ -77,7 +77,8 @@ Tap a channel card to open the channel chat screen. - Channel name - Subtitle: channel type and effective region when set, with `(default)` when inherited - Tap the title or landscape icon to select a region; see [Regions](regions.md) -- Bell icon: mute or unmute notifications for this channel (crossed-out bell when muted) +- Overflow menu (⋮) → **Notifications**: choose all messages, mentions only or muted for this channel. The row shows the current mode +- Overflow menu (⋮) → **Edit channel** and **Delete channel**: the same sheet and confirmation as a long-press in the channel list - Overflow menu (⋮) → **Chat background**: a color or picture, with a fade slider, behind this channel only. See [Chat backgrounds](themes.md#chat-backgrounds). Holiday greetings in new messages play a short animation, as in [direct chat](chat-and-messaging.md#message-list) ### Message Display diff --git a/documentation/chat-and-messaging.md b/documentation/chat-and-messaging.md index 8c47e507..cd2af697 100644 --- a/documentation/chat-and-messaging.md +++ b/documentation/chat-and-messaging.md @@ -18,8 +18,9 @@ From the Contacts screen, tap any Chat-type contact to open the ChatScreen. - **Title**: Contact name - **Subtitle**: Current routing path label (e.g., "2 hops", "flood (auto)", "direct (forced)") and unread count. Tapping the subtitle shows the full path details. -- **Action button**: - - **Overflow menu** (⋮ icon): Contains Routing, Info, Telemetry, Settings, Chat background, and Clear Chat. Routing opens the routing sheet where you can switch between Auto, Direct, and Flood routing and manage recent paths (hop count, round-trip time, age, success count, color-coded by repeater). Info shows a dialog with contact type, path, GPS coordinates, and public key. Chat background sets a color or picture (with a fade slider) behind this chat only; see [Chat backgrounds](themes.md#chat-backgrounds). +- **Action buttons**: + - **Search** (magnifier icon): Replaces the title with a search field and lists every message in this conversation's full history whose text (or translation) contains the typed word, newest first, with matches highlighted. Channel search also matches sender names and skips messages caught by the [message filter](message-filter.md). Back, Esc or the arrow closes search. Channel chats have the same button. + - **Overflow menu** (⋮ icon): Contains Routing, Info, Telemetry, Settings, Chat background, Clear Chat, and Remove from contacts (rooms also have Room Server Management). Routing opens the routing sheet where you can switch between Auto, Direct, and Flood routing and manage recent paths (hop count, round-trip time, age, success count, color-coded by repeater). Info shows a dialog with contact type, path, GPS coordinates, and public key. Chat background sets a color or picture (with a fade slider) behind this chat only; see [Chat backgrounds](themes.md#chat-backgrounds). ### Message List @@ -56,6 +57,14 @@ From the Contacts screen, tap any Chat-type contact to open the ChatScreen. | Location pin | `m:,\|