chore: Follow up router fixes

pull/516/head
krille-chan 2 years ago
parent 0c69ce0552
commit b7dac8365a
No known key found for this signature in database

@ -412,19 +412,17 @@ abstract class AppRoutes {
), ),
]; ];
static Page defaultPageBuilder(BuildContext context, Widget child) { static Page defaultPageBuilder(BuildContext context, Widget child) =>
Matrix.of(context).navigatorContext = context; CustomTransitionPage(
return CustomTransitionPage( child: child,
child: child, transitionsBuilder: (context, animation, secondaryAnimation, child) =>
transitionsBuilder: (context, animation, secondaryAnimation, child) => FluffyThemes.isColumnMode(context)
FluffyThemes.isColumnMode(context) ? FadeTransition(opacity: animation, child: child)
? FadeTransition(opacity: animation, child: child) : CupertinoPageTransition(
: CupertinoPageTransition( primaryRouteAnimation: animation,
primaryRouteAnimation: animation, secondaryRouteAnimation: secondaryAnimation,
secondaryRouteAnimation: secondaryAnimation, linearTransition: false,
linearTransition: false, child: child,
child: child, ),
), );
);
}
} }

@ -4,7 +4,6 @@ import 'package:flutter_blurhash/flutter_blurhash.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:fluffychat/pages/image_viewer/image_viewer.dart'; import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:fluffychat/widgets/mxc_image.dart';
class ImageBubble extends StatelessWidget { class ImageBubble extends StatelessWidget {
@ -72,7 +71,7 @@ class ImageBubble extends StatelessWidget {
} }
if (!tapToView) return; if (!tapToView) return;
showDialog( showDialog(
context: Matrix.of(context).navigatorContext, context: context,
useRootNavigator: false, useRootNavigator: false,
builder: (_) => ImageViewer(event), builder: (_) => ImageViewer(event),
); );

@ -28,13 +28,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_app_badger/flutter_app_badger.dart'; import 'package:flutter_app_badger/flutter_app_badger.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:unifiedpush/unifiedpush.dart'; import 'package:unifiedpush/unifiedpush.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
import 'package:fluffychat/utils/push_helper.dart'; import 'package:fluffychat/utils/push_helper.dart';
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
import '../config/app_config.dart'; import '../config/app_config.dart';
import '../config/setting_keys.dart'; import '../config/setting_keys.dart';
import '../widgets/matrix.dart'; import '../widgets/matrix.dart';
@ -53,15 +53,15 @@ class BackgroundPush {
FlutterLocalNotificationsPlugin(); FlutterLocalNotificationsPlugin();
Client client; Client client;
MatrixState? matrix; MatrixState? matrix;
BuildContext? get context => matrix?.navigatorContext;
String? _fcmToken; String? _fcmToken;
void Function(String errorMsg, {Uri? link})? onFcmError; void Function(String errorMsg, {Uri? link})? onFcmError;
L10n? l10n; L10n? l10n;
Store? _store; Store? _store;
Store get store => _store ??= Store(); Store get store => _store ??= Store();
Future<void> loadLocale() async { Future<void> loadLocale() async {
final context = matrix?.context;
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart // inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
l10n ??= (context != null ? L10n.of(context!) : null) ?? l10n ??= (context != null ? L10n.of(context) : null) ??
(await L10n.delegate.load(PlatformDispatcher.instance.locale)); (await L10n.delegate.load(PlatformDispatcher.instance.locale));
} }
@ -77,7 +77,6 @@ class BackgroundPush {
onRoomSync ??= client.onSync.stream onRoomSync ??= client.onSync.stream
.where((s) => s.hasRoomUpdate) .where((s) => s.hasRoomUpdate)
.listen((s) => _onClearingPush(getFromServer: false)); .listen((s) => _onClearingPush(getFromServer: false));
final context = this.context;
firebase?.setListeners( firebase?.setListeners(
onMessage: (message) => pushHelper( onMessage: (message) => pushHelper(
PushNotification.fromJson( PushNotification.fromJson(
@ -85,9 +84,7 @@ class BackgroundPush {
), ),
client: client, client: client,
l10n: l10n, l10n: l10n,
activeRoomId: context == null activeRoomId: matrix?.activeRoomId,
? null
: GoRouterState.of(context).pathParameters['roomid'],
onSelectNotification: goToRoom, onSelectNotification: goToRoom,
), ),
); );
@ -231,7 +228,7 @@ class BackgroundPush {
Logs().d("SetupPush"); Logs().d("SetupPush");
if (client.onLoginStateChanged.value != LoginState.loggedIn || if (client.onLoginStateChanged.value != LoginState.loggedIn ||
!PlatformInfos.isMobile || !PlatformInfos.isMobile ||
context == null) { matrix == null) {
return; return;
} }
// Do not setup unifiedpush if this has been initialized by // Do not setup unifiedpush if this has been initialized by
@ -261,7 +258,7 @@ class BackgroundPush {
} }
Future<void> _noFcmWarning() async { Future<void> _noFcmWarning() async {
if (context == null) { if (matrix == null) {
return; return;
} }
if (await store.getItemBool(SettingKeys.showNoGoogle, true) == true) { if (await store.getItemBool(SettingKeys.showNoGoogle, true) == true) {
@ -315,14 +312,15 @@ class BackgroundPush {
?.content ?.content
.tryGet<String>('type') == .tryGet<String>('type') ==
ClientStoriesExtension.storiesRoomType; ClientStoriesExtension.storiesRoomType;
context?.go(['', isStory ? 'stories' : 'rooms', roomId].join('/')); FluffyChatApp.router
.go(['', isStory ? 'stories' : 'rooms', roomId].join('/'));
} catch (e, s) { } catch (e, s) {
Logs().e('[Push] Failed to open room', e, s); Logs().e('[Push] Failed to open room', e, s);
} }
} }
Future<void> setupUp() async { Future<void> setupUp() async {
await UnifiedPush.registerAppWithDialog(context!); await UnifiedPush.registerAppWithDialog(matrix!.context);
} }
Future<void> _newUpEndpoint(String newEndpoint, String i) async { Future<void> _newUpEndpoint(String newEndpoint, String i) async {
@ -391,14 +389,11 @@ class BackgroundPush {
); );
// UP may strip the devices list // UP may strip the devices list
data['devices'] ??= []; data['devices'] ??= [];
final context = this.context;
await pushHelper( await pushHelper(
PushNotification.fromJson(data), PushNotification.fromJson(data),
client: client, client: client,
l10n: l10n, l10n: l10n,
activeRoomId: context == null activeRoomId: matrix?.activeRoomId,
? null
: GoRouterState.of(context).pathParameters['roomid'],
); );
} }

@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/matrix.dart';
extension UiaRequestManager on MatrixState { extension UiaRequestManager on MatrixState {
Future uiaRequestHandler(UiaRequest uiaRequest) async { Future uiaRequestHandler(UiaRequest uiaRequest) async {
final l10n = L10n.of(navigatorContext)!; final l10n = L10n.of(context)!;
try { try {
if (uiaRequest.state != UiaRequestState.waitForUser || if (uiaRequest.state != UiaRequestState.waitForUser ||
uiaRequest.nextStages.isEmpty) { uiaRequest.nextStages.isEmpty) {
@ -22,7 +22,7 @@ extension UiaRequestManager on MatrixState {
case AuthenticationTypes.password: case AuthenticationTypes.password:
final input = cachedPassword ?? final input = cachedPassword ??
(await showTextInputDialog( (await showTextInputDialog(
context: navigatorContext, context: context,
title: l10n.pleaseEnterYourPassword, title: l10n.pleaseEnterYourPassword,
okLabel: l10n.ok, okLabel: l10n.ok,
cancelLabel: l10n.cancel, cancelLabel: l10n.cancel,
@ -49,7 +49,7 @@ extension UiaRequestManager on MatrixState {
case AuthenticationTypes.emailIdentity: case AuthenticationTypes.emailIdentity:
if (currentThreepidCreds == null) { if (currentThreepidCreds == null) {
return uiaRequest.cancel( return uiaRequest.cancel(
UiaException(L10n.of(navigatorContext)!.serverRequiresEmail), UiaException(L10n.of(context)!.serverRequiresEmail),
); );
} }
final auth = AuthenticationThreePidCreds( final auth = AuthenticationThreePidCreds(
@ -63,7 +63,7 @@ extension UiaRequestManager on MatrixState {
if (OkCancelResult.ok == if (OkCancelResult.ok ==
await showOkCancelAlertDialog( await showOkCancelAlertDialog(
useRootNavigator: false, useRootNavigator: false,
context: navigatorContext, context: context,
title: l10n.weSentYouAnEmail, title: l10n.weSentYouAnEmail,
message: l10n.pleaseClickOnLink, message: l10n.pleaseClickOnLink,
okLabel: l10n.iHaveClickedOnLink, okLabel: l10n.iHaveClickedOnLink,
@ -88,7 +88,7 @@ extension UiaRequestManager on MatrixState {
await showOkCancelAlertDialog( await showOkCancelAlertDialog(
useRootNavigator: false, useRootNavigator: false,
message: l10n.pleaseFollowInstructionsOnWeb, message: l10n.pleaseFollowInstructionsOnWeb,
context: navigatorContext, context: context,
okLabel: l10n.next, okLabel: l10n.next,
cancelLabel: l10n.cancel, cancelLabel: l10n.cancel,
)) { )) {

@ -41,7 +41,7 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate {
late VoIP voip; late VoIP voip;
ConnectivityResult? _currentConnectivity; ConnectivityResult? _currentConnectivity;
OverlayEntry? overlayEntry; OverlayEntry? overlayEntry;
BuildContext get context => matrix.navigatorContext; BuildContext get context => matrix.context;
void _handleNetworkChanged(ConnectivityResult result) async { void _handleNetworkChanged(ConnectivityResult result) async {
/// Got a new connectivity status! /// Got a new connectivity status!

@ -43,10 +43,13 @@ class FluffyChatApp extends StatelessWidget {
localizationsDelegates: L10n.localizationsDelegates, localizationsDelegates: L10n.localizationsDelegates,
supportedLocales: L10n.supportedLocales, supportedLocales: L10n.supportedLocales,
routerConfig: router, routerConfig: router,
builder: (context, child) => Matrix( builder: (context, child) => Navigator(
context: context, onGenerateRoute: (_) => MaterialPageRoute(
clients: clients, builder: (_) => Matrix(
child: testWidget ?? child, clients: clients,
child: testWidget ?? child,
),
),
), ),
), ),
); );

@ -33,10 +33,9 @@ extension LocalNotificationsExtension on MatrixState {
if (room.notificationCount == 0) return; if (room.notificationCount == 0) return;
final event = Event.fromJson(eventUpdate.content, room); final event = Event.fromJson(eventUpdate.content, room);
final title = final title = room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!));
room.getLocalizedDisplayname(MatrixLocals(L10n.of(navigatorContext)!));
final body = await event.calcLocalizedBody( final body = await event.calcLocalizedBody(
MatrixLocals(L10n.of(navigatorContext)!), MatrixLocals(L10n.of(context)!),
withSenderNamePrefix: withSenderNamePrefix:
!room.isDirectChat || room.lastEvent?.senderId == client.userID, !room.isDirectChat || room.lastEvent?.senderId == client.userID,
plaintextBody: true, plaintextBody: true,
@ -95,11 +94,11 @@ extension LocalNotificationsExtension on MatrixState {
actions: [ actions: [
NotificationAction( NotificationAction(
DesktopNotificationActions.openChat.name, DesktopNotificationActions.openChat.name,
L10n.of(navigatorContext)!.openChat, L10n.of(context)!.openChat,
), ),
NotificationAction( NotificationAction(
DesktopNotificationActions.seen.name, DesktopNotificationActions.seen.name,
L10n.of(navigatorContext)!.markAsRead, L10n.of(context)!.markAsRead,
), ),
], ],
hints: [ hints: [
@ -114,7 +113,7 @@ extension LocalNotificationsExtension on MatrixState {
room.setReadMarker(event.eventId, mRead: event.eventId); room.setReadMarker(event.eventId, mRead: event.eventId);
break; break;
case DesktopNotificationActions.openChat: case DesktopNotificationActions.openChat:
navigatorContext.go(['', 'rooms', room.id].join('/')); context.go(['', 'rooms', room.id].join('/'));
break; break;
} }
}); });

@ -10,7 +10,6 @@ import 'package:collection/collection.dart';
import 'package:desktop_notifications/desktop_notifications.dart'; import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:matrix/encryption.dart'; import 'package:matrix/encryption.dart';
@ -24,6 +23,7 @@ import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/uia_request_manager.dart'; import 'package:fluffychat/utils/uia_request_manager.dart';
import 'package:fluffychat/utils/voip_plugin.dart'; import 'package:fluffychat/utils/voip_plugin.dart';
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
import '../config/app_config.dart'; import '../config/app_config.dart';
import '../config/setting_keys.dart'; import '../config/setting_keys.dart';
import '../pages/key_verification/key_verification_dialog.dart'; import '../pages/key_verification/key_verification_dialog.dart';
@ -37,16 +37,12 @@ import 'local_notifications_extension.dart';
class Matrix extends StatefulWidget { class Matrix extends StatefulWidget {
final Widget? child; final Widget? child;
@Deprecated('')
final BuildContext context;
final List<Client> clients; final List<Client> clients;
final Map<String, String>? queryParameters; final Map<String, String>? queryParameters;
const Matrix({ const Matrix({
this.child, this.child,
required this.context,
required this.clients, required this.clients,
this.queryParameters, this.queryParameters,
Key? key, Key? key,
@ -64,7 +60,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
int _activeClient = -1; int _activeClient = -1;
String? activeBundle; String? activeBundle;
Store store = Store(); Store store = Store();
late BuildContext navigatorContext;
HomeserverSummary? loginHomeserverSummary; HomeserverSummary? loginHomeserverSummary;
XFile? loginAvatar; XFile? loginAvatar;
@ -172,7 +167,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
ClientManager.addClientNameToStore(_loginClientCandidate!.clientName); ClientManager.addClientNameToStore(_loginClientCandidate!.clientName);
_registerSubs(_loginClientCandidate!.clientName); _registerSubs(_loginClientCandidate!.clientName);
_loginClientCandidate = null; _loginClientCandidate = null;
navigatorContext.go('/rooms'); FluffyChatApp.router.go('/rooms');
}); });
return candidate; return candidate;
} }
@ -239,8 +234,11 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
bool webHasFocus = true; bool webHasFocus = true;
String? get activeRoomId => String? get activeRoomId {
GoRouterState.of(navigatorContext).pathParameters['roomid']; final route = FluffyChatApp.router.routeInformationProvider.value.location;
if (route == null || !route.startsWith('/rooms/')) return null;
return route.split('/')[2];
}
final linuxNotifications = final linuxNotifications =
PlatformInfos.isLinux ? NotificationsClient() : null; PlatformInfos.isLinux ? NotificationsClient() : null;
@ -309,13 +307,13 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
if (!hidPopup && if (!hidPopup &&
{KeyVerificationState.done, KeyVerificationState.error} {KeyVerificationState.done, KeyVerificationState.error}
.contains(request.state)) { .contains(request.state)) {
Navigator.of(navigatorContext).pop('dialog'); Navigator.of(context).pop('dialog');
} }
hidPopup = true; hidPopup = true;
}; };
request.onUpdate = null; request.onUpdate = null;
hidPopup = true; hidPopup = true;
await KeyVerificationDialog(request: request).show(navigatorContext); await KeyVerificationDialog(request: request).show(context);
}); });
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) { onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
final loggedInWithMultipleClients = widget.clients.length > 1; final loggedInWithMultipleClients = widget.clients.length > 1;
@ -330,16 +328,11 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
); );
if (state != LoginState.loggedIn) { if (state != LoginState.loggedIn) {
navigatorContext.go( FluffyChatApp.router.go('/rooms');
Uri(
path: '/rooms',
queryParameters:
GoRouterState.of(navigatorContext).uri.queryParameters,
).toString(),
);
} }
} else { } else {
navigatorContext.go(state == LoginState.loggedIn ? '/rooms' : '/home'); FluffyChatApp.router
.go(state == LoginState.loggedIn ? '/rooms' : '/home');
} }
}); });
onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler); onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler);

Loading…
Cancel
Save