Skip to content

Commit ee70847

Browse files
committed
fix: deepLink
1 parent e9036bf commit ee70847

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<category android:name="android.intent.category.LAUNCHER" />
4040
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
4141
</intent-filter>
42+
4243
<intent-filter android:label="Add Repo">
4344
<action android:name="android.intent.action.VIEW" />
4445
<category android:name="android.intent.category.DEFAULT" />

lib/main.dart

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Future init() async {
9191
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
9292
await WindowManager.instance.ensureInitialized();
9393
}
94-
initDeepLinkListener();
94+
9595
TypeFactory.registerAllTypes();
9696
initializeDateFormatting();
9797
final supportedLocales = DateFormat.allLocalesWithSymbols();
@@ -109,6 +109,7 @@ Future init() async {
109109
}
110110
}
111111
Discord.getSavedToken();
112+
initDeepLinkListener();
112113
Get.config(
113114
enableLog: true,
114115
logWriterCallback: (text, {isError = false}) async {
@@ -126,38 +127,31 @@ void initDeepLinkListener() async {
126127
snackString('Error getting initial deep link: $err');
127128
}
128129

129-
uriLinkStream.listen((Uri? uri) {
130-
if (uri != null) {
131-
handleDeepLink(uri);
132-
}
133-
}, onError: (err) {
134-
snackString('Error Opening link: $err');
135-
});
130+
uriLinkStream.listen(
131+
(uri) => uri != null ? handleDeepLink(uri) : null,
132+
onError: (err) => snackString('Error Opening link: $err'),
133+
);
136134
}
137135

138136
void handleDeepLink(Uri uri) {
139-
if (uri.host == "add-repo") {
140-
String? animeUrl =
141-
uri.queryParameters["url"] ?? uri.queryParameters['anime_url'];
142-
String? mangaUrl = uri.queryParameters["manga_url"];
143-
String? novelUrl = uri.queryParameters["novel_url"];
137+
if (uri.host != "add-repo") return;
144138

145-
if (animeUrl != null) {
146-
Extensions.setRepo(ItemType.anime, animeUrl);
147-
}
148-
if (mangaUrl != null) {
149-
Extensions.setRepo(ItemType.manga, mangaUrl);
150-
}
151-
if (novelUrl != null) {
152-
Extensions.setRepo(ItemType.novel, novelUrl);
153-
}
139+
final repoMap = {
140+
ItemType.anime: uri.queryParameters["url"] ?? uri.queryParameters["anime_url"],
141+
ItemType.manga: uri.queryParameters["manga_url"],
142+
ItemType.novel: uri.queryParameters["novel_url"],
143+
};
144+
145+
bool isRepoAdded = false;
154146

155-
if (animeUrl != null || mangaUrl != null || novelUrl != null) {
156-
snackString("Added Repo Links Successfully!");
157-
} else {
158-
snackString("Missing required parameters in the link.");
147+
repoMap.forEach((type, url) {
148+
if (url != null && url.isNotEmpty) {
149+
Extensions.setRepo(type, url);
150+
isRepoAdded = true;
159151
}
160-
}
152+
});
153+
154+
snackString(isRepoAdded ? "Added Repo Links Successfully!" : "Missing required parameters in the link.");
161155
}
162156

163157
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

0 commit comments

Comments
 (0)