feat(#1291): open meshcore:// links in Offband on Android, iOS and macOS

No platform declared the meshcore scheme, so a share link tapped in a
browser or another app went nowhere.

- Android: a meshcore VIEW/BROWSABLE intent filter on MainActivity, and
  flutter_deeplinking_enabled=false, which app_links needs; otherwise
  Flutter treats "channel/add" as a screen to navigate to.
- iOS: CFBundleURLTypes for meshcore, and FlutterDeepLinkingEnabled=false.
- macOS: CFBundleURLTypes for meshcore.
- app_links 7.2.2 (Apache-2.0) feeds the link the app was opened with,
  and later ones, to LinkRouter (#1289). Only meshcore:// links are acted
  on: on web the page's own address arrives as the initial link, and an
  ordinary launch must not show a link message.

Windows and Linux wait on how the app is installed (#1284).

Regression tests:
- share_link_registration_test: the three platform declarations. All
  three fail against dev's manifest and plists.
- link_router_test: only share links are taken from the OS.
- link_router_host_test: a link from the OS opens the confirmation, and
  an ordinary address does nothing.

Epic: #1286
Feature: #1280

Agent: StormyElk (session 088ce922)
pull/1308/head
diffwireauto 2 days ago
parent d4420aa752
commit 16a1e62f57

@ -51,6 +51,16 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- meshcore:// share links (#1291). app_links hands them to
LinkRouter, so Flutter's own deep-link routing is off: it
would treat channel/add as a screen to navigate to. -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="false" />
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="meshcore"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->

@ -22,8 +22,21 @@
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>app.offband.meshcore.share</string>
<key>CFBundleURLSchemes</key>
<array>
<string>meshcore</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>FlutterDeepLinkingEnabled</key>
<false/>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter/foundation.dart';
@ -442,8 +443,9 @@ class MeshCoreApp extends StatelessWidget {
},
home: (PlatformInfo.isWeb && !PlatformInfo.isChrome)
? const ChromeRequiredScreen()
: const LinkRouterHost(
child: IosOnMacNoticeGate(
: LinkRouterHost(
osLinks: AppLinks().uriLinkStream,
child: const IosOnMacNoticeGate(
child: SponsorPromptGate(child: ScannerScreen()),
),
),

@ -91,6 +91,15 @@ class LinkRouter extends ChangeNotifier {
return link != null;
}
/// Takes a link the OS opened the app with (#1291). Only share links are
/// acted on: the OS also reports ordinary launches, and on web the page's
/// own address arrives as the "initial link", neither of which is the
/// user asking to add anything, so they are ignored rather than reported.
void handleFromOs(Uri uri) {
if (uri.scheme.toLowerCase() != 'meshcore') return;
handle(uri.toString());
}
/// The pending link if its confirmation can be shown now, removing it.
///
/// Adding anything needs a connected radio. A channel also waits for the

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@ -8,6 +10,7 @@ import '../helpers/channel_share_add.dart';
import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../services/link_router.dart';
import '../utils/app_logger.dart';
import 'add_contact_by_key_dialog.dart';
import 'contact_add_feedback.dart';
@ -17,10 +20,14 @@ import 'contact_add_feedback.dart';
/// It wraps the home route, so it sits below the Navigator and its dialogs
/// and messages open over whatever screen is on top.
class LinkRouterHost extends StatefulWidget {
const LinkRouterHost({super.key, required this.child});
const LinkRouterHost({super.key, required this.child, this.osLinks});
final Widget child;
/// Links the OS opened the app with: the one that launched it, then any
/// that arrive while it runs (#1291). Null in tests that do not need it.
final Stream<Uri>? osLinks;
@override
State<LinkRouterHost> createState() => _LinkRouterHostState();
}
@ -28,6 +35,7 @@ class LinkRouterHost extends StatefulWidget {
class _LinkRouterHostState extends State<LinkRouterHost> {
late final LinkRouter _router;
late final MeshCoreConnector _connector;
StreamSubscription<Uri>? _osLinks;
bool _scheduled = false;
bool _showing = false;
@ -38,11 +46,17 @@ class _LinkRouterHostState extends State<LinkRouterHost> {
_connector = context.read<MeshCoreConnector>();
_router.addListener(_schedule);
_connector.addListener(_schedule);
_osLinks = widget.osLinks?.listen(
_router.handleFromOs,
onError: (Object e) =>
appLogger.warn('OS link stream error: $e', tag: 'LinkRouter'),
);
_schedule();
}
@override
void dispose() {
_osLinks?.cancel();
_router.removeListener(_schedule);
_connector.removeListener(_schedule);
super.dispose();

@ -6,12 +6,16 @@
#include "generated_plugin_registrant.h"
#include <app_links_linux/app_links_plugin_linux.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <screen_retriever_linux/screen_retriever_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) app_links_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AppLinksPluginLinux");
app_links_plugin_linux_register_with_registrar(app_links_linux_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);

@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
app_links_linux
file_selector_linux
screen_retriever_linux
url_launcher_linux

@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation
import app_links
import file_selector_macos
import flutter_blue_plus_darwin
import flutter_local_notifications
@ -20,6 +21,7 @@ import wakelock_plus
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterBluePlusPlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlusPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))

@ -18,6 +18,17 @@
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>app.offband.meshcore.share</string>
<key>CFBundleURLSchemes</key>
<array>
<string>meshcore</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSMinimumSystemVersion</key>

@ -25,6 +25,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "12.1.0"
app_links:
dependency: "direct main"
description:
name: app_links
sha256: "08ba88bf19d9edea33130cb71c8ced2cb982b4e00b82efef4a434d1357bc69c3"
url: "https://pub.dev"
source: hosted
version: "7.2.2"
app_links_linux:
dependency: transitive
description:
name: app_links_linux
sha256: "734aa57a2f65d1b35c3643384ccfbe668730157a08479bfa488e10a9da847853"
url: "https://pub.dev"
source: hosted
version: "1.0.5"
app_links_platform_interface:
dependency: transitive
description:
name: app_links_platform_interface
sha256: "7546f09a6e93f4a2df2fe2bd40a5c6c64310ac461b036d82b43033be7a59f809"
url: "https://pub.dev"
source: hosted
version: "2.0.4"
app_links_web:
dependency: transitive
description:
name: app_links_web
sha256: "382d32c6f486f15b1d7f5d6a37a70a481a4fc08382eef419d373169921a3e765"
url: "https://pub.dev"
source: hosted
version: "1.0.5"
archive:
dependency: "direct main"
description:

@ -62,6 +62,7 @@ dependencies:
qr_flutter: ^4.1.0 # QR code generation
url_launcher: ^6.3.0 # Launch URLs in system browser
flutter_linkify: ^6.0.0 # Auto-detect and linkify URLs in text
app_links: ^7.2.2 # meshcore:// and offband.app share links from the OS (#1280)
gpx: ^2.3.0
yaml: ^3.1.2 # Parse importable device config profiles (#403)
path_provider: ^2.1.6

@ -0,0 +1,59 @@
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
// #1291: the OS only hands a meshcore:// link to Offband if the app declares
// the scheme. Before this, none of the platforms did, so a tapped link went
// nowhere. Flutter's own deep-link routing must also be off where app_links
// needs it, or Flutter treats "channel/add" as a screen to navigate to.
String _read(String path) => File(path).readAsStringSync();
/// The `<intent-filter>` blocks in the Android manifest.
Iterable<String> _intentFilters(String manifest) => RegExp(
r'<intent-filter>([\s\S]*?)</intent-filter>',
).allMatches(manifest).map((m) => m[1]!);
/// True if a `CFBundleURLSchemes` array in [plist] lists [scheme].
bool _plistDeclaresScheme(String plist, String scheme) => RegExp(
r'<key>CFBundleURLSchemes</key>\s*<array>[\s\S]*?<string>' +
RegExp.escape(scheme) +
r'</string>[\s\S]*?</array>',
).hasMatch(plist);
void main() {
test('Android opens meshcore:// links in Offband', () {
final manifest = _read('android/app/src/main/AndroidManifest.xml');
final filter = _intentFilters(
manifest,
).where((f) => f.contains('android:scheme="meshcore"'));
expect(filter, hasLength(1), reason: 'one meshcore intent filter');
expect(filter.single, contains('android.intent.action.VIEW'));
expect(filter.single, contains('android.intent.category.BROWSABLE'));
expect(filter.single, contains('android.intent.category.DEFAULT'));
expect(
manifest,
matches(
RegExp(
r'android:name="flutter_deeplinking_enabled"\s+android:value="false"',
),
),
);
});
test('iOS opens meshcore:// links in Offband', () {
final plist = _read('ios/Runner/Info.plist');
expect(_plistDeclaresScheme(plist, 'meshcore'), isTrue);
expect(
plist,
matches(RegExp(r'<key>FlutterDeepLinkingEnabled</key>\s*<false/>')),
);
});
test('macOS opens meshcore:// links in Offband', () {
expect(
_plistDeclaresScheme(_read('macos/Runner/Info.plist'), 'meshcore'),
isTrue,
);
});
}

@ -101,6 +101,21 @@ void main() {
expect(router.pendingAnnounced, isFalse);
});
test('from the OS, only share links are acted on (#1291)', () {
final router = LinkRouter();
// An ordinary launch, and on web the page's own address.
router.handleFromOs(Uri.parse('https://offband.app/'));
router.handleFromOs(Uri.parse('offband://open'));
expect(router.pending, isNull);
expect(router.takeRejected(), isNull, reason: 'not reported either');
router.handleFromOs(Uri.parse(_hashtagLink));
expect(router.pending, isA<ChannelShareLink>());
router.handleFromOs(Uri.parse('MESHCORE://channel/add?name=nope'));
expect(router.takeRejected(), isNotNull, reason: 'a broken share link');
});
test('a malformed link does not replace a held one', () {
final router = LinkRouter()..handle(_channelLink);
router.handle('meshcore://nope');

@ -1,6 +1,7 @@
// #1289: a share link opens the existing confirmation, waits for a radio
// when none is connected, and never adds anything the user did not confirm.
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
@ -149,6 +150,35 @@ void main() {
expect(find.textContaining("isn't a channel or contact"), findsOne);
});
testWidgets('a link from the OS opens the confirmation (#1291)', (
tester,
) async {
final radio = _Radio()..connected = true;
final os = StreamController<Uri>();
addTearDown(os.close);
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider<MeshCoreConnector>.value(value: radio),
ChangeNotifierProvider(create: (_) => LinkRouter()),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: LinkRouterHost(osLinks: os.stream, child: const Scaffold()),
),
),
);
os.add(Uri.parse('https://offband.app/'));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);
expect(find.textContaining("isn't a channel"), findsNothing);
os.add(Uri.parse(_link));
await tester.pumpAndSettle();
expect(find.text('Add channel "#example"?'), findsOne);
});
testWidgets('tapping a meshcore:// link in a message routes it here', (
tester,
) async {

@ -6,6 +6,7 @@
#include "generated_plugin_registrant.h"
#include <app_links/app_links_plugin_c_api.h>
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_blue_plus_winrt/flutter_blue_plus_plugin.h>
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
@ -14,6 +15,8 @@
#include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
AppLinksPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterBluePlusPluginRegisterWithRegistrar(

@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
app_links
file_selector_windows
flutter_blue_plus_winrt
screen_retriever_windows

Loading…
Cancel
Save

Powered by TurnKey Linux.