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
parent
d4420aa752
commit
16a1e62f57
@ -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,
|
||||
);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue