Widget: show a closed app and a disconnected companion

The third line reads "cmp off" (amber) when the companion is
disconnected and "app off" (red) when the app is closed: at once from
MainActivity.onDestroy, or when the bridge's 5-minute heartbeat has been
missing for 15 minutes (process killed). The widget now refreshes every
30 minutes so it notices the latter. Counts dim while the app is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-23 10:19:41 +02:00
1 parent 71884e269f
commit b16314cf39
5 files changed
+48 -20

No files matched your search

+10 -4
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/services.dart';
import '../connector/meshcore_connector.dart';
@@ -6,23 +8,27 @@ import '../utils/platform_info.dart';
/// tth fork: feeds the 1x1 Android home-screen widget (UnreadWidget.kt) with
/// unread direct messages, unread channel messages and the companion's
/// battery. Pushes only when one of those changes - the connector notifies
/// on every frame.
/// battery. Pushes when one of those changes - the connector notifies on
/// every frame - plus a heartbeat, so the widget can tell an app that was
/// killed without a goodbye (no heartbeat for 15 min) from a quiet one.
class HomeWidgetBridge {
static const _channel = MethodChannel('meshcore_open/home_widget');
final MeshCoreConnector _connector;
({int dm, int channels, int? battery, bool connected})? _last;
static const _heartbeat = Duration(minutes: 5);
HomeWidgetBridge(this._connector);
void start() {
if (!PlatformInfo.isAndroid) return;
_connector.addListener(_onChanged);
Timer.periodic(_heartbeat, (_) => _onChanged(force: true));
_onChanged();
}
void _onChanged() {
void _onChanged({bool force = false}) {
final connected = _connector.isConnected;
final state = (
dm: _connector.getTotalContactsUnreadCount(),
@@ -31,7 +37,7 @@ class HomeWidgetBridge {
battery: _connector.batteryPercent ?? _last?.battery,
connected: connected,
);
if (state == _last) return;
if (!force && state == _last) return;
_last = state;
_channel
.invokeMethod<void>('update', {