diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 45859303..e10b694a 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -26,6 +26,20 @@
+
+
+
+
+
+
+
+
diff --git a/lib/src/pages/home_page.dart b/lib/src/pages/home_page.dart
index 8ccff84d..1ccf64c7 100644
--- a/lib/src/pages/home_page.dart
+++ b/lib/src/pages/home_page.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -11,9 +13,11 @@ import 'package:jhentai/src/pages/ranklist/ranklist_page_logic.dart';
import 'package:jhentai/src/pages/search/desktop/desktop_search_page_logic.dart';
import 'package:jhentai/src/pages/watched/watched_page_logic.dart';
import 'package:jhentai/src/setting/style_setting.dart';
+import 'package:jhentai/src/utils/log.dart';
import 'package:jhentai/src/utils/toast_util.dart';
import 'package:jhentai/src/widget/will_pop_interceptor.dart';
import 'package:jhentai/src/widget/windows_app.dart';
+import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import '../consts/eh_consts.dart';
import '../model/jh_layout.dart';
@@ -44,6 +48,7 @@ class HomePage extends StatefulWidget {
}
class _HomePageState extends State {
+ StreamSubscription? _intentDataStreamSubscription;
String? _lastDetectedUrl;
@override
@@ -51,10 +56,17 @@ class _HomePageState extends State {
super.initState();
initToast(context);
_initPageLogic();
+ _initSharingIntent();
_handleUrlInClipBoard();
AppStateListener.registerDidChangeAppLifecycleStateCallback(resumeAndHandleUrlInClipBoard);
}
+ @override
+ void dispose() {
+ _intentDataStreamSubscription?.cancel();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
return WindowsApp(
@@ -106,6 +118,58 @@ class _HomePageState extends State {
}
}
+ void _initPageLogic() {
+ /// Mobile layout v2
+ Get.lazyPut(() => DashboardPageLogic(), fenix: true);
+
+ /// Desktop layout
+ Get.lazyPut(() => GallerysPageLogic(), fenix: true);
+ Get.lazyPut(() => DesktopSearchPageLogic(), fenix: true);
+
+ /// Mobile layout v2 & Desktop layout
+ Get.lazyPut(() => PopularPageLogic(), fenix: true);
+ Get.lazyPut(() => RanklistPageLogic(), fenix: true);
+ Get.lazyPut(() => FavoritePageLogic(), fenix: true);
+ Get.lazyPut(() => WatchedPageLogic(), fenix: true);
+ Get.lazyPut(() => HistoryPageLogic(), fenix: true);
+ }
+
+ /// Listen to share or open urls/text coming from outside the app while the app is in the memory or is closed
+ void _initSharingIntent() {
+ if (!GetPlatform.isAndroid) {
+ return;
+ }
+
+ ReceiveSharingIntent.getInitialText().then(
+ (String? url) {
+ if (url != null) {
+ toRoute(
+ Routes.details,
+ arguments: url,
+ offAllBefore: false,
+ preventDuplicates: false,
+ );
+ }
+ },
+ );
+
+ _intentDataStreamSubscription = ReceiveSharingIntent.getTextStream().listen(
+ (String url) => toRoute(
+ Routes.details,
+ arguments: url,
+ offAllBefore: false,
+ preventDuplicates: false,
+ ),
+ onError: (e) {
+ Log.error('ReceiveSharingIntent Error!', e);
+ Log.upload(e);
+ },
+ );
+ }
+
+ /// user open a url in other app by JHenTai
+ void _handleUrlFromOtherApp() async {}
+
/// a gallery url exists in clipboard, show dialog to check whether enter detail page
void _handleUrlInClipBoard() async {
String text = await FlutterClipboard.paste();
@@ -134,20 +198,4 @@ class _HomePageState extends State {
longDuration: true,
);
}
-
- void _initPageLogic() {
- /// Mobile layout v2
- Get.lazyPut(() => DashboardPageLogic(), fenix: true);
-
- /// Desktop layout
- Get.lazyPut(() => GallerysPageLogic(), fenix: true);
- Get.lazyPut(() => DesktopSearchPageLogic(), fenix: true);
-
- /// Mobile layout v2 & Desktop layout
- Get.lazyPut(() => PopularPageLogic(), fenix: true);
- Get.lazyPut(() => RanklistPageLogic(), fenix: true);
- Get.lazyPut(() => FavoritePageLogic(), fenix: true);
- Get.lazyPut(() => WatchedPageLogic(), fenix: true);
- Get.lazyPut(() => HistoryPageLogic(), fenix: true);
- }
}
diff --git a/pubspec.lock b/pubspec.lock
index d774f000..53990a5e 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1054,6 +1054,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
+ receive_sharing_intent:
+ dependency: "direct main"
+ description:
+ name: receive_sharing_intent
+ url: "https://pub.flutter-io.cn"
+ source: hosted
+ version: "1.4.5"
retry:
dependency: "direct main"
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index 1a601390..e4e2e9ba 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -63,6 +63,7 @@ dependencies:
battery_plus: ^2.1.4
throttling: ^1.0.0
bitsdojo_window: ^0.1.2
+ receive_sharing_intent: ^1.4.5
dev_dependencies:
flutter_test: