Configure the connect screen's node banner from a DNS TXT record

The "get a node" banner's link, and optionally its title, body and button
text, now come from the _banner.meshcoreopen.org TXT record, looked up
over Cloudflare DNS-over-HTTPS and cached for the record's TTL (1 min to
6 h). The record is `v=1;on=1;url=<https link>` with URL-encoded values;
`on=0`, a missing record or any lookup failure hides the banner.
This commit is contained in:
zjs81 committed 2026-10-24 21:29:08 -07:00
1 parent ae2db54a24
commit ee382f9177
4 files changed
+321 -16

No files matched your search

+43 -2
View File
@@ -1,13 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/services/node_banner_service.dart';
import 'package:meshcore_open/widgets/get_node_banner.dart';
final _config = NodeBannerConfig(url: Uri.parse('https://example.com/node'));
void main() {
Future<void> pumpBanner(
WidgetTester tester, {
required Size size,
required double textScale,
NodeBannerConfig? config,
bool hidden = false,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
@@ -21,7 +26,11 @@ void main() {
size: size,
textScaler: TextScaler.linear(textScale),
),
child: const Scaffold(bottomNavigationBar: GetNodeBanner()),
child: Scaffold(
bottomNavigationBar: GetNodeBanner(
loadConfig: () async => hidden ? null : config ?? _config,
),
),
),
),
);
@@ -29,11 +38,11 @@ void main() {
testWidgets('shows the pitch and affiliate link', (tester) async {
await pumpBanner(tester, size: const Size(390, 844), textScale: 1);
await tester.pump();
expect(find.text('Need a new node?'), findsOneWidget);
expect(find.text('Get one here'), findsOneWidget);
expect(find.textContaining('Affiliate link'), findsOneWidget);
expect(getNodeUrl, contains('sensecap_affiliate=JFWID0g'));
// Leaves most of the screen for the device list.
expect(
tester.getSize(find.byType(GetNodeBanner)).height,
@@ -43,6 +52,38 @@ void main() {
testWidgets('lays out on a narrow phone with large text', (tester) async {
await pumpBanner(tester, size: const Size(320, 800), textScale: 1.5);
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('uses text overrides from the record', (tester) async {
await pumpBanner(
tester,
size: const Size(390, 844),
textScale: 1,
config: NodeBannerConfig(
url: Uri.parse('https://example.com'),
title: 'Spring sale',
action: 'Shop now',
),
);
await tester.pump();
expect(find.text('Spring sale'), findsOneWidget);
expect(find.text('Shop now'), findsOneWidget);
expect(find.textContaining('Affiliate link'), findsOneWidget);
});
testWidgets('shows nothing when there is no config', (tester) async {
await pumpBanner(
tester,
size: const Size(390, 844),
textScale: 1,
hidden: true,
);
await tester.pump();
expect(find.byType(InkWell), findsNothing);
expect(tester.getSize(find.byType(GetNodeBanner)).height, 0);
});
}