Skip to content

Commit

Permalink
Migrate from uni_links to app_links for deep links (thunder-app#1626)
Browse files Browse the repository at this point in the history
* refactor: migrate from uni_links to app_links

* fix: fix deep link config for iOS, potential fix for 1575
  • Loading branch information
hjiangsu authored Dec 6, 2024
1 parent b5f5189 commit 8ae7eab
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 74 deletions.
19 changes: 19 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,22 @@
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

##---------------End: proguard configuration for Gson ----------

##---------------Begin: proguard configuration for App Links ----------
# SPDX-FileCopyrightText: 2016, microG Project Team
# SPDX-License-Identifier: CC0-1.0

# Keep AutoSafeParcelables
-keep public class * extends org.microg.safeparcel.AutoSafeParcelable {
@org.microg.safeparcel.SafeParcelable.Field *;
@org.microg.safeparcel.SafeParceled *;
}

# Keep asInterface method cause it's accessed from SafeParcel
-keepattributes InnerClasses
-keepclassmembers interface * extends android.os.IInterface {
public static class *;
}
-keep public class * extends android.os.Binder { public static *; }

##---------------End: proguard configuration for App Links ----------
8 changes: 4 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:resizeableActivity="true">
android:resizeableActivity="true"
android:windowSoftInputMode="adjustResize">
<!--Allowing support for multi windows (split-screen mode) & picture-in-picture mode -->
<meta-data
android:name="android.allow_multiple_resumed_activities"
android:value="true" />
<meta-data android:name="android.allow_multiple_resumed_activities" android:value="true" />
<!--Disable Flutter's built-in deep linking -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="false" />
<!-- support sharing images -->
<intent-filter
android:label="@string/create_post">
Expand Down
12 changes: 6 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- app_links (0.0.2):
- Flutter
- background_fetch (1.3.7):
- Flutter
- connectivity_plus (0.0.1):
Expand Down Expand Up @@ -69,8 +71,6 @@ PODS:
- sqlite3/fts5
- sqlite3/perf-threadsafe
- sqlite3/rtree
- uni_links (0.0.1):
- Flutter
- url_launcher_ios (0.0.1):
- Flutter
- video_player_avfoundation (0.0.1):
Expand All @@ -81,6 +81,7 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- app_links (from `.symlinks/plugins/app_links/ios`)
- background_fetch (from `.symlinks/plugins/background_fetch/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
Expand All @@ -103,7 +104,6 @@ DEPENDENCIES:
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`)
- uni_links (from `.symlinks/plugins/uni_links/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/darwin`)
Expand All @@ -114,6 +114,8 @@ SPEC REPOS:
- sqlite3

EXTERNAL SOURCES:
app_links:
:path: ".symlinks/plugins/app_links/ios"
background_fetch:
:path: ".symlinks/plugins/background_fetch/ios"
connectivity_plus:
Expand Down Expand Up @@ -158,8 +160,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite_darwin/darwin"
sqlite3_flutter_libs:
:path: ".symlinks/plugins/sqlite3_flutter_libs/ios"
uni_links:
:path: ".symlinks/plugins/uni_links/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
video_player_avfoundation:
Expand All @@ -168,6 +168,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/webview_flutter_wkwebview/darwin"

SPEC CHECKSUMS:
app_links: e7a6750a915a9e161c58d91bc610e8cd1d4d0ad0
background_fetch: 39f11371c0dce04b001c4bfd5e782bcccb0a85e2
connectivity_plus: 4c41c08fc6d7c91f63bc7aec70ffe3730b04f563
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
Expand All @@ -192,7 +193,6 @@ SPEC CHECKSUMS:
sqflite_darwin: a553b1fd6fe66f53bbb0fe5b4f5bab93f08d7a13
sqlite3: 0aa20658a9b238a3b1ff7175eb7bdd863b0ab4fd
sqlite3_flutter_libs: b55ef23cfafea5318ae5081e0bf3fbbce8417c94
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
video_player_avfoundation: 7c6c11d8470e1675df7397027218274b6d2360b3
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@
</array>
</dict>
</array>
<key>FlutterDeepLinkingEnabled</key>
<false/>
</dict>
</plist>
49 changes: 12 additions & 37 deletions lib/thunder/cubits/deep_links_cubit/deep_links_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import 'dart:async';
import 'dart:math';

import 'package:app_links/app_links.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:thunder/thunder/enums/deep_link_enums.dart';
import 'package:thunder/utils/global_context.dart';
import 'package:uni_links/uni_links.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

part 'deep_links_state.dart';

/// A Cubit for handling deep links and determining their types.
class DeepLinksCubit extends Cubit<DeepLinksState> {
DeepLinksCubit() : super(const DeepLinksState());
StreamSubscription? _uniLinksStreamSubscription;
StreamSubscription? _appLinksStreamSubscription;

AppLinks appLinks = AppLinks();

/// Analyzes a given link to determine its type and updates the state accordingly.
///
Expand Down Expand Up @@ -85,17 +88,12 @@ class DeepLinksCubit extends Cubit<DeepLinksState> {
}
}

/// Handle incoming links - the ones that the app will recieve from the OS
/// while already started.
/// Handles deep link navigation.
Future<void> initialize() async {
emit(state.copyWith(deepLinkStatus: DeepLinkStatus.loading));

Future<void> handleIncomingLinks() async {
emit(state.copyWith(
deepLinkStatus: DeepLinkStatus.loading,
));
_uniLinksStreamSubscription = uriLinkStream.listen((Uri? uri) {
emit(state.copyWith(
deepLinkStatus: DeepLinkStatus.loading,
));
_appLinksStreamSubscription = appLinks.uriLinkStream.listen((Uri? uri) {
emit(state.copyWith(deepLinkStatus: DeepLinkStatus.loading));
getLinkType(uri.toString());
}, onError: (Object err) {
if (err is FormatException) {
Expand All @@ -114,30 +112,7 @@ class DeepLinksCubit extends Cubit<DeepLinksState> {
});
}

/// Handle the initial Uri - the one the app was started with
Future<void> handleInitialURI() async {
try {
emit(state.copyWith(
deepLinkStatus: DeepLinkStatus.loading,
));
final uri = await getInitialUri();
if (uri == null) {
state.copyWith(
deepLinkStatus: DeepLinkStatus.empty,
error: AppLocalizations.of(GlobalContext.context)!.emptyUri,
);
} else {
getLinkType(uri.toString());
}
} catch (e) {
state.copyWith(
deepLinkStatus: DeepLinkStatus.error,
error: e.toString(),
);
}
}

void dispose() {
_uniLinksStreamSubscription?.cancel();
_appLinksStreamSubscription?.cancel();
}
}
8 changes: 6 additions & 2 deletions lib/thunder/pages/thunder_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ class _ThunderState extends State<Thunder> {
handleSharedFilesAndText();

if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
BlocProvider.of<DeepLinksCubit>(context).handleIncomingLinks();
BlocProvider.of<DeepLinksCubit>(context).handleInitialURI();
BlocProvider.of<DeepLinksCubit>(context).initialize();
BlocProvider.of<NotificationsCubit>(context).handleNotifications();
}
});
Expand Down Expand Up @@ -259,6 +258,7 @@ class _ThunderState extends State<Thunder> {
} catch (e) {
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
Navigator.of(context).pop();
}
}
}
Expand Down Expand Up @@ -287,6 +287,7 @@ class _ThunderState extends State<Thunder> {
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
Navigator.of(context).pop();
}
}

Expand All @@ -305,6 +306,7 @@ class _ThunderState extends State<Thunder> {
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
Navigator.of(context).pop();
}
}

Expand Down Expand Up @@ -359,6 +361,7 @@ class _ThunderState extends State<Thunder> {
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
Navigator.of(context).pop();
}
}

Expand All @@ -375,6 +378,7 @@ class _ThunderState extends State<Thunder> {

if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
Navigator.of(context).pop();
}
}

Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <dynamic_color/dynamic_color_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <gtk/gtk_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

Expand All @@ -18,6 +19,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
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);
g_autoptr(FlPluginRegistrar) gtk_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
gtk_plugin_register_with_registrar(gtk_registrar);
g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
file_selector_linux
gtk
sqlite3_flutter_libs
url_launcher_linux
)
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation

import app_links
import connectivity_plus
import device_info_plus
import dynamic_color
Expand All @@ -22,6 +23,7 @@ import video_player_avfoundation
import webview_flutter_wkwebview

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
Expand Down
64 changes: 40 additions & 24 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
app_links:
dependency: "direct main"
description:
name: app_links
sha256: ad1a6d598e7e39b46a34f746f9a8b011ee147e4c275d407fa457e7a62f84dd99
url: "https://pub.dev"
source: hosted
version: "6.3.2"
app_links_linux:
dependency: transitive
description:
name: app_links_linux
sha256: f5f7173a78609f3dfd4c2ff2c95bd559ab43c80a87dc6a095921d96c05688c81
url: "https://pub.dev"
source: hosted
version: "1.0.3"
app_links_platform_interface:
dependency: transitive
description:
name: app_links_platform_interface
sha256: "05f5379577c513b534a29ddea68176a4d4802c46180ee8e2e966257158772a3f"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
app_links_web:
dependency: transitive
description:
name: app_links_web
sha256: af060ed76183f9e2b87510a9480e56a5352b6c249778d07bd2c95fc35632a555
url: "https://pub.dev"
source: hosted
version: "1.0.4"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -906,6 +938,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.2"
gtk:
dependency: transitive
description:
name: gtk
sha256: e8ce9ca4b1df106e4d72dad201d345ea1a036cc12c360f1a7d5a758f78ffa42c
url: "https://pub.dev"
source: hosted
version: "2.1.0"
html:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1815,30 +1855,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
uni_links:
dependency: "direct main"
description:
name: uni_links
sha256: "051098acfc9e26a9fde03b487bef5d3d228ca8f67693480c6f33fd4fbb8e2b6e"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
uni_links_platform_interface:
dependency: transitive
description:
name: uni_links_platform_interface
sha256: "929cf1a71b59e3b7c2d8a2605a9cf7e0b125b13bc858e55083d88c62722d4507"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
uni_links_web:
dependency: transitive
description:
name: uni_links_web
sha256: "7539db908e25f67de2438e33cc1020b30ab94e66720b5677ba6763b25f6394df"
url: "https://pub.dev"
source: hosted
version: "0.1.0"
unifiedpush:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:
git:
url: https://github.com/xaynetwork/xayn_readability
android_intent_plus: "^5.0.1"
app_links: "^6.3.2"
auto_size_text: "^3.0.0"
back_button_interceptor: "^7.0.0"
background_fetch: "^1.2.1"
Expand Down Expand Up @@ -80,7 +81,6 @@ dependencies:
stream_transform: "^2.1.0"
super_sliver_list: "^0.4.1"
swipeable_page_route: "^0.4.0"
uni_links: "^0.5.1"
unifiedpush: "^5.0.1"
url_launcher: "^6.1.11"
# There is an intentional space between the packge name and colon below. Do not remove!
Expand Down
Loading

0 comments on commit 8ae7eab

Please sign in to comment.