merge(app): land native deep links
This commit is contained in:
@@ -26,6 +26,16 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<!-- The server publishes `pipelines://run/<id>` as a notification's
|
||||
click URL; it opens that run (lib/application/app_router.dart
|
||||
routeLocation). It only opens a run; it starts nothing. -->
|
||||
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
|
||||
<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="pipelines" android:host="run" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
|
||||
@@ -2,6 +2,19 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>FlutterDeepLinkingEnabled</key>
|
||||
<true/>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>pipelines-run</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>pipelines</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
|
||||
@@ -26,8 +26,16 @@ class AppRouteParser extends RouteInformationParser<AppRoute> {
|
||||
/// [AppRoute.parse] understands this form, so a browser location such as
|
||||
/// `/runs/7/stage/plan?visit=1` keeps the query instead of losing it to
|
||||
/// `Uri.path`. A fragment is not part of an app route.
|
||||
String routeLocation(Uri uri) =>
|
||||
uri.hasQuery ? '${uri.path}?${uri.query}' : uri.path;
|
||||
///
|
||||
/// The native notification link `pipelines://run/<id>` (the URL the server
|
||||
/// publishes as the notification's click target, as the Android client
|
||||
/// registers it) is the run route `/runs/<id>`.
|
||||
String routeLocation(Uri uri) {
|
||||
final path = uri.scheme == 'pipelines' && uri.host == 'run'
|
||||
? '/runs${uri.path}'
|
||||
: uri.path;
|
||||
return uri.hasQuery ? '$path?${uri.query}' : path;
|
||||
}
|
||||
|
||||
/// Owns the app's current route and builds the shell for it.
|
||||
///
|
||||
@@ -238,13 +246,23 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// The location a web launch starts at, or the Pipelines list elsewhere.
|
||||
/// The location a launch starts at: the browser location on the web, the
|
||||
/// deep link a native app was opened with, or the Pipelines list.
|
||||
///
|
||||
/// The origin stays out of route configuration so a serialised route is always
|
||||
/// app-relative, but the path and its query are both part of the route: a
|
||||
/// launch at `/runs/7/stage/plan?visit=1` must open exactly that visit.
|
||||
RouteInformation initialRouteInformation() {
|
||||
if (!kIsWeb) return RouteInformation(uri: Uri(path: '/pipelines'));
|
||||
if (!kIsWeb) {
|
||||
// A cold start from a deep link carries the full link as the platform's
|
||||
// initial route; an ordinary launch opens the Pipelines list.
|
||||
final launched = WidgetsBinding.instance.platformDispatcher.defaultRouteName;
|
||||
return RouteInformation(
|
||||
uri: launched.isEmpty || launched == '/'
|
||||
? Uri(path: '/pipelines')
|
||||
: Uri.parse(launched),
|
||||
);
|
||||
}
|
||||
return routeInformationForLocation(Uri.base);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,4 +100,18 @@ void main() {
|
||||
'/',
|
||||
);
|
||||
});
|
||||
|
||||
test('the native notification link opens its run', () async {
|
||||
const parser = AppRouteParser();
|
||||
final run = await parser.parseRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('pipelines://run/42')),
|
||||
);
|
||||
expect(run, AppRoute.run(42));
|
||||
final decide = await parser.parseRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('pipelines://run/42?action=decide')),
|
||||
);
|
||||
expect(decide.path, '/runs/42?action=decide');
|
||||
// Another scheme or host is not a run link.
|
||||
expect(routeLocation(Uri.parse('pipelines://other/42')), '/42');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user