diff --git a/lib/pages/opener.dart b/lib/pages/opener.dart index 98fa9ce..54413d2 100644 --- a/lib/pages/opener.dart +++ b/lib/pages/opener.dart @@ -5,6 +5,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:humhub/pages/web_view.dart'; import 'package:humhub/util/const.dart'; import 'package:humhub/util/form_helper.dart'; +import 'package:humhub/util/intent/intent_plugin.dart'; +import 'package:humhub/util/notifications/channel.dart'; import 'package:humhub/util/opener_controller.dart'; import 'package:humhub/util/providers.dart'; import 'package:rive/rive.dart'; @@ -41,12 +43,17 @@ class OpenerState extends ConsumerState with SingleTickerProviderStateMi _animationReverse = SimpleAnimation('animation', autoplay: true); _controllerReverse = _animationReverse; - WidgetsBinding.instance.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) async { Future.delayed(const Duration(milliseconds: 700), () { setState(() { _textFieldAddInfoVisibility = true; }); }); + + String? urlIntent = InitFromIntent.usePayloadForInit(); + if(urlIntent != null){ + await RedirectNotificationChannel().onTap(urlIntent); + } }); } diff --git a/lib/pages/web_view.dart b/lib/pages/web_view.dart index 46fc01f..07a834f 100644 --- a/lib/pages/web_view.dart +++ b/lib/pages/web_view.dart @@ -185,7 +185,7 @@ class WebViewAppState extends ConsumerState { manifest = manifestPush.manifest; url = manifestPush.remoteMessage.data['url']; } - String? payloadFromPush = RedirectUrlFromInit.usePayloadForInit(); + String? payloadFromPush = InitFromPush.usePayload(); if (payloadFromPush != null) url = payloadFromPush; return URLRequest(url: Uri.parse(url ?? manifest.baseUrl), headers: ref.read(humHubProvider).customHeaders); } diff --git a/lib/util/intent/intent_plugin.dart b/lib/util/intent/intent_plugin.dart index a968add..a3897b2 100644 --- a/lib/util/intent/intent_plugin.dart +++ b/lib/util/intent/intent_plugin.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:humhub/pages/web_view.dart'; -import 'package:humhub/util/notifications/channel.dart'; import 'package:humhub/util/router.dart'; import 'package:humhub/util/universal_opener_controller.dart'; import 'package:loggy/loggy.dart'; @@ -92,6 +91,7 @@ class IntentPluginState extends ConsumerState { // In this example app this is an almost useless guard, but it is here to // show we are not going to call getInitialUri multiple times, even if this // was a widget that will be disposed of (ex. a navigation route change). + if (!_initialUriIsHandled) { _initialUriIsHandled = true; try { @@ -102,10 +102,14 @@ class IntentPluginState extends ConsumerState { _latestUri = uri; String? redirectUrl = uri.queryParameters['url']; if (redirectUrl != null && navigatorKey.currentState != null) { + logInfo('MD22 IF open: $_initialUriIsHandled'); tryNavigateWithOpener(redirectUrl); } else { if (redirectUrl != null) { - RedirectUrlFromInit.setPayloadForInit(redirectUrl); + UniversalOpenerController opener = UniversalOpenerController(url: redirectUrl); + await opener.initHumHub(); + navigatorKey.currentState!.pushNamed(WebViewApp.path, arguments: opener); + return; } } } on PlatformException { @@ -120,6 +124,7 @@ class IntentPluginState extends ConsumerState { } Future tryNavigateWithOpener(String redirectUrl) async { + logInfo('MD initHumHub payload: $redirectUrl'); bool isNewRouteSameAsCurrent = false; navigatorKey.currentState!.popUntil((route) { if (route.settings.name == WebViewApp.path) { @@ -134,3 +139,17 @@ class IntentPluginState extends ConsumerState { return isNewRouteSameAsCurrent; } } + +class InitFromIntent { + static String? _redirectUrl; + + static setPayloadForInit(String payload) { + _redirectUrl = payload; + } + + static String? usePayloadForInit() { + String? payload = _redirectUrl; + _redirectUrl = null; + return payload; + } +} diff --git a/lib/util/notifications/channel.dart b/lib/util/notifications/channel.dart index 92a3e5f..39f207d 100644 --- a/lib/util/notifications/channel.dart +++ b/lib/util/notifications/channel.dart @@ -50,6 +50,7 @@ class RedirectNotificationChannel extends NotificationChannel { } return true; }); + // TODO: Check here what does it happen if the WebView and Manifest is not init and we want to open it from the opener. UniversalOpenerController opener = UniversalOpenerController(url: payload); await opener.initHumHub(); if (isNewRouteSameAsCurrent) { @@ -59,20 +60,20 @@ class RedirectNotificationChannel extends NotificationChannel { navigatorKey.currentState!.pushNamed(WebViewApp.path, arguments: opener); } else { if (payload != null) { - RedirectUrlFromInit.setPayloadForInit(payload); + InitFromPush.setPayload(payload); } } } } -class RedirectUrlFromInit { +class InitFromPush { static String? _redirectUrlFromInit; - static setPayloadForInit(String payload) { + static setPayload(String payload) { _redirectUrlFromInit = payload; } - static String? usePayloadForInit() { + static String? usePayload() { String? payload = _redirectUrlFromInit; _redirectUrlFromInit = null; return payload;