Merge pull request #1331 from OffbandMesh/feat/1288-land-on-dev

feat(#1311): land Epic D on dev (#1330 merged into its stacked base)
pull/1338/head
Strycher 21 hours ago committed by GitHub
commit 67d7541c88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import '../l10n/l10n.dart';
import '../services/link_router.dart';
import 'share_link_forms.dart';
import '../utils/platform_info.dart';
import '../helpers/snack_bar_builder.dart';

@ -0,0 +1,62 @@
/// The two forms of a channel or contact share link (#1280).
///
/// - `meshcore://channel/add?<fields>` and `meshcore://contact/add?<fields>`:
/// what the stock app reads, so QR codes keep using it.
/// - `https://offband.app/add/channel#<fields>` and `/add/contact#<fields>`:
/// what Share and Copy Link emit. The OS opens it in Offband, which the
/// stock app's claim on `meshcore://` gets in the way of.
///
/// The fields are the same in both. In the https form they sit after `#`,
/// which browsers never send to the server, so a channel secret stays out
/// of the server's logs.
library;
/// The hosts whose `/add/...` links are Offband share links. The app is
/// verified for both (#1309), so these open it instead of the browser.
const shareLinkHosts = {'offband.app', 'dev.offband.app'};
/// The host Share and Copy Link emit (#1311).
const shareLinkHost = 'offband.app';
final _meshcoreForm = RegExp(r'^meshcore://(channel|contact)/add\?(.+)$');
/// The `meshcore://` twin of an `https://offband.app/add/channel#...` or
/// `/add/contact#...` link, or null if [raw] is not one (#1309).
String? meshcoreFormOf(String raw) {
final uri = Uri.tryParse(raw.trim());
if (uri == null || !isShareAddress(uri)) return null;
final path = _pathOf(uri);
if (path.length != 2) return null;
if (path[1] != 'channel' && path[1] != 'contact') return null;
if (uri.query.isNotEmpty || uri.fragment.isEmpty) return null;
return 'meshcore://${path[1]}/add?${uri.fragment}';
}
/// The path's segments, lowercased: a link typed by hand as `/Add/Channel`
/// is the same link.
List<String> _pathOf(Uri uri) => [
for (final s in uri.pathSegments)
if (s.isNotEmpty) s.toLowerCase(),
];
/// The https twin of a `meshcore://channel/add?...` or `contact/add?...`
/// link, on [shareLinkHost] (#1311). The fields are carried as they are,
/// already encoded.
String httpsFormOf(String meshcoreLink) {
final match = _meshcoreForm.firstMatch(meshcoreLink);
if (match == null) {
throw ArgumentError.value(meshcoreLink, 'meshcoreLink', 'not a share link');
}
return 'https://$shareLinkHost/add/${match[1]}#${match[2]}';
}
/// [raw] in the `meshcore://` form, whichever form it arrived in, so one
/// parser reads both.
String toMeshcoreForm(String raw) => meshcoreFormOf(raw) ?? raw.trim();
/// True for any `https://offband.app/add/...` address, well formed or not.
bool isShareAddress(Uri uri) =>
uri.scheme.toLowerCase() == 'https' &&
!uri.hasPort &&
shareLinkHosts.contains(uri.host.toLowerCase()) &&
_pathOf(uri).firstOrNull == 'add';

@ -3186,6 +3186,8 @@
"contacts_myContactQr": "My contact QR",
"contacts_myContactQrInstructions": "Have them scan this, or send them the link below. It works even if they have never heard your advert.",
"contacts_contactLinkCopied": "Contact link copied",
"common_copyLink": "Copy link",
"channels_channelLinkCopied": "Channel link copied",
"contacts_qrNeedsConnection": "Connect to a radio first, so the app knows your public key.",
"contacts_scanContactQr": "Scan contact QR",
"contacts_scanContactQrInstructions": "Point the camera at a MeshCore contact QR",

@ -8836,6 +8836,18 @@ abstract class AppLocalizations {
/// **'Contact link copied'**
String get contacts_contactLinkCopied;
/// No description provided for @common_copyLink.
///
/// In en, this message translates to:
/// **'Copy link'**
String get common_copyLink;
/// No description provided for @channels_channelLinkCopied.
///
/// In en, this message translates to:
/// **'Channel link copied'**
String get channels_channelLinkCopied;
/// No description provided for @contacts_qrNeedsConnection.
///
/// In en, this message translates to:

@ -5264,6 +5264,12 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5276,6 +5276,12 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5198,6 +5198,12 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5265,6 +5265,12 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5287,6 +5287,12 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5282,6 +5282,12 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5270,6 +5270,12 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5067,6 +5067,12 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5069,6 +5069,12 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5250,6 +5250,12 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5280,6 +5280,12 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5262,6 +5262,12 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5272,6 +5272,12 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5246,6 +5246,12 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5240,6 +5240,12 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5219,6 +5219,12 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -5271,6 +5271,12 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -4970,6 +4970,12 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get contacts_contactLinkCopied => 'Contact link copied';
@override
String get common_copyLink => 'Copy link';
@override
String get channels_channelLinkCopied => 'Channel link copied';
@override
String get contacts_qrNeedsConnection =>
'Connect to a radio first, so the app knows your public key.';

@ -4,6 +4,7 @@ import 'dart:typed_data';
import 'package:crypto/crypto.dart' as crypto;
import '../connector/meshcore_protocol.dart';
import '../helpers/share_link_forms.dart';
import 'community.dart';
enum ChannelType { public, private, hashtag, communityPublic, communityHashtag }
@ -112,14 +113,22 @@ class Channel {
String toShareUri() =>
'meshcore://channel/add?name=${Uri.encodeComponent(name)}&secret=$pskHex';
/// The `https://offband.app/add/channel#...` twin of [toShareUri], for
/// Copy Link: it opens Offband, where the `meshcore://` form can land in
/// the stock app. QR codes keep [toShareUri], so the stock app can still
/// scan them. (#1311)
String toShareLink() => httpsFormOf(toShareUri());
/// Parses a channel from a reference-app share URI, or null if malformed.
/// [index] is the local slot the caller assigns on add. (#161)
///
/// A hashtag channel's key is derived from its name, so a link naming one
/// needs no `secret=`; "#public" means the real Public, as everywhere else
/// (#1896). (#1289)
///
/// The `https://offband.app/add/channel#...` form reads the same (#1311).
static Channel? fromShareUri(String uri, {int index = 0}) {
final parsed = Uri.tryParse(uri.trim());
final parsed = Uri.tryParse(toMeshcoreForm(uri));
if (parsed == null || parsed.scheme != 'meshcore') return null;
if (parsed.host != 'channel') return null;
if (parsed.path.replaceAll('/', '') != 'add') return null;

@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'package:meshcore_open/utils/app_logger.dart';
import '../connector/meshcore_protocol.dart';
import '../helpers/share_link_forms.dart';
class Contact {
final Uint8List publicKey;
@ -354,6 +355,18 @@ class Contact {
'&public_key=$publicKeyHex'
'&type=$type';
/// The `https://offband.app/add/contact#...` twin of [buildShareUri], for
/// Share and Copy Link: it opens Offband, where the `meshcore://` form can
/// land in the stock app. QR codes keep [buildShareUri], so the stock app
/// can still scan them. (#1311)
static String buildShareLink({
required String publicKeyHex,
required String name,
int type = advTypeChat,
}) => httpsFormOf(
buildShareUri(publicKeyHex: publicKeyHex, name: name, type: type),
);
/// The body of one compact channel share, `<key:type:name>`, captured
/// without its delimiters. `[^>]*` cannot cross a closing bracket, so each
/// card matches individually even when several sit in one message.
@ -468,8 +481,10 @@ class Contact {
/// Returns null for the fork's older `meshcore://<raw advert hex>` form,
/// whose host is the leading hex rather than `contact`. Callers keep handling
/// that separately: it carries a full signed advert and is strictly richer.
///
/// The `https://offband.app/add/contact#...` form reads the same (#1311).
static Contact? fromShareUri(String uri) {
final parsed = Uri.tryParse(uri.trim());
final parsed = Uri.tryParse(toMeshcoreForm(uri));
if (parsed == null || parsed.scheme != 'meshcore') return null;
if (parsed.host != 'contact') return null;
if (parsed.path.replaceAll('/', '') != 'add') return null;

@ -2201,6 +2201,8 @@ class _ChannelsScreenState extends State<ChannelsScreen>
QrCodeShareDialog.show(
context: context,
data: channel.toShareUri(),
link: channel.toShareLink(),
linkCopiedMessage: context.l10n.channels_channelLinkCopied,
title: context.l10n.channels_shareQrTitle,
instructions: context.l10n.channels_shareQrInstructions(channel.name),
embeddedImage: Image.asset(

@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import '../connector/meshcore_protocol.dart';
import '../helpers/share_link_forms.dart';
import '../models/channel.dart';
import '../models/contact.dart';
import '../utils/address_bar.dart';
@ -50,36 +51,9 @@ class AdvertShareLink extends ShareLink {
// in one radio packet, so anything past 255 bytes is not one.
final _advertLink = RegExp(r'^meshcore://((?:[0-9a-fA-F]{2}){98,255})$');
/// The hosts whose `/add/...` links are Offband share links. The app is
/// verified for both (#1309), so these open it instead of the browser.
const shareLinkHosts = {'offband.app', 'dev.offband.app'};
/// The `meshcore://` twin of an `https://offband.app/add/channel#...` or
/// `/add/contact#...` link, or null if [raw] is not one (#1309).
///
/// The fields sit after `#`, which browsers never send to the server, so a
/// channel secret stays out of the server's logs. They are the same fields
/// as the `meshcore://` link's query, so one parser reads both.
String? meshcoreFormOf(String raw) {
final uri = Uri.tryParse(raw.trim());
if (uri == null || !_isShareAddress(uri)) return null;
final path = uri.pathSegments.where((s) => s.isNotEmpty).toList();
if (path.length != 2) return null;
if (path[1] != 'channel' && path[1] != 'contact') return null;
if (uri.query.isNotEmpty || uri.fragment.isEmpty) return null;
return 'meshcore://${path[1]}/add?${uri.fragment}';
}
/// True for any `https://offband.app/add/...` address, well formed or not.
bool _isShareAddress(Uri uri) =>
uri.scheme.toLowerCase() == 'https' &&
!uri.hasPort &&
shareLinkHosts.contains(uri.host.toLowerCase()) &&
uri.pathSegments.where((s) => s.isNotEmpty).firstOrNull == 'add';
/// Parses [raw] into a link Offband can add, or null if it is not one.
ShareLink? parseShareLink(String raw) {
final trimmed = meshcoreFormOf(raw) ?? raw.trim();
final trimmed = raw.trim();
final channel = Channel.fromShareUri(trimmed);
if (channel != null) return ChannelShareLink(channel);
final contact = Contact.fromShareUri(trimmed);
@ -136,7 +110,7 @@ class LinkRouter extends ChangeNotifier {
void handleFromOs(Uri uri) {
if (uri.scheme.toLowerCase() == 'meshcore') {
handle(uri.toString());
} else if (_isShareAddress(uri)) {
} else if (isShareAddress(uri)) {
handle(uri.toString());
_clearAddressLink();
}

@ -33,10 +33,19 @@ Future<void> showMyContactQrDialog(BuildContext context) {
return Future<void>.value();
}
final name = connector.selfName ?? '';
// This device is a companion.
final uri = Contact.buildShareUri(
publicKeyHex: keyHex,
name: connector.selfName ?? '',
// This device is a companion.
name: name,
type: advTypeChat,
);
// What they are told to send: it opens Offband, where the meshcore:// form
// can land in the stock app. The QR keeps the meshcore:// form, which the
// stock app scans. (#1311)
final link = Contact.buildShareLink(
publicKeyHex: keyHex,
name: name,
type: advTypeChat,
);
@ -55,7 +64,7 @@ Future<void> showMyContactQrDialog(BuildContext context) {
),
const SizedBox(height: 8),
SelectableText(
uri,
link,
style: Theme.of(dialogContext).textTheme.bodySmall?.copyWith(
fontFamily: 'monospace',
color: Theme.of(dialogContext).colorScheme.onSurfaceVariant,
@ -67,7 +76,7 @@ Future<void> showMyContactQrDialog(BuildContext context) {
actions: [
TextButton.icon(
onPressed: () async {
await Clipboard.setData(ClipboardData(text: uri));
await Clipboard.setData(ClipboardData(text: link));
if (!dialogContext.mounted) return;
showDismissibleSnackBar(
dialogContext,

@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:qr_flutter/qr_flutter.dart';
import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
/// A reusable QR code display widget for sharing data.
@ -179,12 +181,20 @@ class QrCodeShareDialog extends StatelessWidget {
final String? instructions;
final Widget? embeddedImage;
/// A link to offer under the code, with a Copy link button, and the
/// message shown once it is copied. The QR keeps [data]: a link sent in
/// text can be a different form from the one a scanner reads. (#1311)
final String? link;
final String? linkCopiedMessage;
const QrCodeShareDialog({
super.key,
required this.data,
this.title,
this.instructions,
this.embeddedImage,
this.link,
this.linkCopiedMessage,
});
@override
@ -203,6 +213,24 @@ class QrCodeShareDialog extends StatelessWidget {
embeddedImage: embeddedImage,
padding: EdgeInsets.zero,
),
if (link case final link?) ...[
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () async {
await Clipboard.setData(ClipboardData(text: link));
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(linkCopiedMessage ?? link),
);
},
icon: const Icon(Icons.link),
label: Text(context.l10n.common_copyLink),
),
),
],
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
@ -224,6 +252,8 @@ class QrCodeShareDialog extends StatelessWidget {
String? title,
String? instructions,
Widget? embeddedImage,
String? link,
String? linkCopiedMessage,
}) {
return showDialog(
context: context,
@ -232,6 +262,8 @@ class QrCodeShareDialog extends StatelessWidget {
title: title,
instructions: instructions,
embeddedImage: embeddedImage,
link: link,
linkCopiedMessage: linkCopiedMessage,
),
);
}

@ -0,0 +1,146 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/helpers/share_link_forms.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/models/channel.dart';
import 'package:meshcore_open/models/contact.dart';
import 'package:meshcore_open/widgets/qr_code_display.dart';
// #1311: Share and Copy Link emit https://offband.app/add/..., which opens
// Offband; QR codes stay meshcore://, which the stock app scans. Every parser
// reads both.
const _key = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
const _secret = '5d25cf40b1f5b4a7eb0cf9703634a948';
void main() {
group('the two forms', () {
test('a channel link round-trips through both forms', () {
for (final name in ['Ops', '#echo', 'a&b', '50% off', 'one+two', 'a b']) {
final channel = Channel(
index: 0,
name: name,
psk: Channel.parsePskHex(_secret),
);
final link = channel.toShareLink();
expect(link, startsWith('https://offband.app/add/channel#'));
expect(meshcoreFormOf(link), channel.toShareUri());
final back = Channel.fromShareUri(link)!;
expect(back.name, name, reason: link);
expect(back.pskHex, _secret, reason: link);
}
});
test('a contact link round-trips through both forms', () {
for (final name in ['Bob', 'Strycher-RK4', 'a&b', 'a b']) {
final link = Contact.buildShareLink(
publicKeyHex: _key,
name: name,
type: advTypeRepeater,
);
expect(link, startsWith('https://offband.app/add/contact#'));
expect(
meshcoreFormOf(link),
Contact.buildShareUri(
publicKeyHex: _key,
name: name,
type: advTypeRepeater,
),
);
final back = Contact.fromShareUri(link)!;
expect(back.publicKeyHex, _key);
expect(back.name, name);
expect(back.type, advTypeRepeater);
}
});
test('the parsers still read the meshcore:// form', () {
final channel = Channel(
index: 0,
name: 'Ops',
psk: Channel.parsePskHex(_secret),
);
expect(Channel.fromShareUri(channel.toShareUri())?.name, 'Ops');
expect(Channel.isValidShareUri(channel.toShareUri()), isTrue);
expect(Channel.isValidShareUri(channel.toShareLink()), isTrue);
final uri = Contact.buildShareUri(publicKeyHex: _key, name: 'Bob');
expect(Contact.isValidShareUri(uri), isTrue);
expect(
Contact.isValidShareUri(
Contact.buildShareLink(publicKeyHex: _key, name: 'Bob'),
),
isTrue,
);
});
test('httpsFormOf refuses what is not a share link', () {
for (final bad in [
'meshcore://${'ab' * 98}',
'meshcore://channel/add',
'https://offband.app/add/channel#name=x',
]) {
expect(() => httpsFormOf(bad), throwsArgumentError, reason: bad);
}
});
});
testWidgets('the channel QR stays meshcore://, Copy link copies https', (
tester,
) async {
final channel = Channel(
index: 0,
name: '#echo',
psk: Channel.parsePskHex(_secret),
);
final copied = <String>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method == 'Clipboard.setData') {
copied.add((call.arguments as Map)['text'] as String);
}
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: QrCodeShareDialog(
data: channel.toShareUri(),
link: channel.toShareLink(),
linkCopiedMessage: 'Channel link copied',
),
),
),
);
expect(
tester.widget<QrCodeDisplay>(find.byType(QrCodeDisplay)).data,
channel.toShareUri(),
);
await tester.tap(find.text('Copy link'));
await tester.pump();
expect(copied, [channel.toShareLink()]);
expect(find.text('Channel link copied'), findsOneWidget);
});
testWidgets('a QR with no link offers no Copy link', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const Scaffold(body: QrCodeShareDialog(data: '{"x":1}')),
),
);
expect(find.text('Copy link'), findsNothing);
});
}

@ -1,5 +1,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/helpers/share_link_forms.dart';
import 'package:meshcore_open/models/channel.dart';
import 'package:meshcore_open/models/contact.dart';
import 'package:meshcore_open/services/link_router.dart';
// #1289: every share link goes through LinkRouter, which holds it until its
@ -77,17 +79,22 @@ void main() {
as ChannelShareLink;
expect(hashtag.channel.name, '#example');
final contact =
parseShareLink(
https(host, 'contact', 'name=Bob&public_key=$_key&type=1'),
)
as ContactShareLink;
final link = https(host, 'contact', 'name=Bob&public_key=$_key&type=1');
final contact = parseShareLink(link) as ContactShareLink;
expect(contact.contact.name, 'Bob');
// The add-contact dialog reads the link again, in the form it knows.
expect(contact.uri, _contactLink);
// Held as received; the add-contact dialog reads either form (#1311).
expect(contact.uri, link);
expect(Contact.fromShareUri(contact.uri)?.publicKeyHex, _key);
}
});
test('read a hand-typed path in any case', () {
expect(
parseShareLink('https://offband.app/Add/Channel#name=%23example'),
isA<ChannelShareLink>(),
);
});
test('keep a name with reserved characters intact', () {
const secret = '5d25cf40b1f5b4a7eb0cf9703634a948';
for (final name in ['a&b', 'x=y', '50% off', 'one+two', 'a b', '#c#d']) {

@ -6,6 +6,7 @@
// that link parsing back into the right key, name and type.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:qr_flutter/qr_flutter.dart';
@ -15,6 +16,7 @@ import 'package:meshcore_open/connector/meshcore_protocol.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/models/contact.dart';
import 'package:meshcore_open/widgets/my_contact_qr_dialog.dart';
import 'package:meshcore_open/widgets/qr_code_display.dart';
const _key = 'aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899';
@ -57,26 +59,69 @@ void main() {
testWidgets('renders a QR plus the link it encodes', (tester) async {
await _open(tester, _FakeConn(keyHex: _key, nodeName: 'Strycher-RK4'));
final expected = Contact.buildShareUri(
publicKeyHex: _key,
name: 'Strycher-RK4',
type: advTypeChat,
);
expect(find.byType(QrImageView), findsOneWidget);
// The QR stays meshcore://, which the stock app scans (#1311).
expect(
tester.widget<QrCodeDisplay>(find.byType(QrCodeDisplay)).data,
Contact.buildShareUri(
publicKeyHex: _key,
name: 'Strycher-RK4',
type: advTypeChat,
),
);
// The link is shown so it can be copied or pasted into a chat, which is
// the path that works when the other person is not in the room.
expect(find.text(expected), findsOneWidget);
// the path that works when the other person is not in the room. It is
// the offband.app form, which opens Offband (#1311).
expect(
find.text(
Contact.buildShareLink(
publicKeyHex: _key,
name: 'Strycher-RK4',
type: advTypeChat,
),
),
findsOneWidget,
);
});
testWidgets('Copy copies the offband.app link (#1311)', (tester) async {
final copied = <String>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method == 'Clipboard.setData') {
copied.add((call.arguments as Map)['text'] as String);
}
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
await _open(tester, _FakeConn(keyHex: _key, nodeName: 'Strycher-RK4'));
await tester.tap(find.byIcon(Icons.copy));
await tester.pump();
expect(copied, [
Contact.buildShareLink(
publicKeyHex: _key,
name: 'Strycher-RK4',
type: advTypeChat,
),
]);
});
testWidgets('the rendered link parses back to this device', (tester) async {
await _open(tester, _FakeConn(keyHex: _key, nodeName: 'Strycher-RK4'));
final expected = Contact.buildShareUri(
final expected = Contact.buildShareLink(
publicKeyHex: _key,
name: 'Strycher-RK4',
type: advTypeChat,
);
expect(find.text(expected), findsOneWidget);
final parsed = Contact.fromShareUri(expected);
expect(parsed, isNotNull);
@ -91,7 +136,7 @@ void main() {
) async {
await _open(tester, _FakeConn(keyHex: _key));
final expected = Contact.buildShareUri(
final expected = Contact.buildShareLink(
publicKeyHex: _key,
name: '',
type: advTypeChat,

@ -325,6 +325,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -799,6 +801,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -1273,6 +1277,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -1747,6 +1753,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -2221,6 +2229,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -2695,6 +2705,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -3169,6 +3181,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -3643,6 +3657,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -4117,6 +4133,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -4591,6 +4609,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -5065,6 +5085,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -5539,6 +5561,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -6013,6 +6037,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -6487,6 +6513,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -6961,6 +6989,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -7435,6 +7465,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",
@ -7909,6 +7941,8 @@
"contacts_myContactQr",
"contacts_myContactQrInstructions",
"contacts_contactLinkCopied",
"common_copyLink",
"channels_channelLinkCopied",
"contacts_qrNeedsConnection",
"contacts_scanContactQr",
"contacts_scanContactQrInstructions",

Loading…
Cancel
Save

Powered by TurnKey Linux.