diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index 39df45f6..610bc645 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -42,15 +42,12 @@ class NeonApp extends StatefulWidget { // ignore: prefer_mixin class _NeonAppState extends State with WidgetsBindingObserver, tray.TrayListener, WindowListener { final _appRegex = RegExp(r'^app_([a-z]+)$', multiLine: true); - final _navigatorKey = GlobalKey(); + late final GlobalKey _navigatorKey; late final Iterable _appImplementations; late final NeonPlatform _platform; late final GlobalOptions _globalOptions; late final AccountsBloc _accountsBloc; - late final _routerDelegate = AppRouter( - navigatorKey: _navigatorKey, - accountsBloc: _accountsBloc, - ); + late final AppRouter _routerDelegate; Rect? _lastBounds; @@ -63,6 +60,9 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra _globalOptions = Provider.of(context, listen: false); _accountsBloc = Provider.of(context, listen: false); + _routerDelegate = _accountsBloc.router; + _navigatorKey = _routerDelegate.navigatorKey; + WidgetsBinding.instance.addObserver(this); if (_platform.canUseSystemTray) { tray.trayManager.addListener(this); diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 88ebd811..fe8c856e 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -10,6 +10,7 @@ import 'package:neon/src/blocs/user_statuses.dart'; import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/platform/platform.dart'; +import 'package:neon/src/router.dart'; import 'package:neon/src/settings/models/storage.dart'; import 'package:neon/src/utils/account_options.dart'; import 'package:neon/src/utils/global_options.dart'; @@ -63,6 +64,10 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState this._globalOptions, this._allAppImplementations, ) { + router = AppRouter( + accountsBloc: this, + appImplementations: _allAppImplementations, + ); accounts ..add(loadAccounts(_storage)) ..listen((final as) async { @@ -105,6 +110,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState final SharedPreferences _sharedPreferences; final GlobalOptions _globalOptions; final Iterable _allAppImplementations; + late final AppRouter router; final _keyLastUsedAccount = 'last-used-account'; final _accountsOptions = {}; @@ -239,6 +245,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState this, account, _allAppImplementations, + router, ); } diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 12def172..35af07ca 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -10,6 +10,7 @@ import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/app_ids.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/models/notifications_interface.dart'; +import 'package:neon/src/router.dart'; import 'package:neon/src/settings/models/nextcloud_app_options.dart'; import 'package:neon/src/utils/request_manager.dart'; import 'package:nextcloud/nextcloud.dart'; @@ -46,6 +47,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates this._accountsBloc, this._account, this._allAppImplementations, + this._router, ) { apps.listen((final result) { appImplementations @@ -154,6 +156,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates final AccountsBloc _accountsBloc; final Account _account; final Iterable _allAppImplementations; + final AppRouter _router; @override void dispose() { diff --git a/packages/neon/neon/lib/src/models/app_implementation.dart b/packages/neon/neon/lib/src/models/app_implementation.dart index 5c387cff..c363a563 100644 --- a/packages/neon/neon/lib/src/models/app_implementation.dart +++ b/packages/neon/neon/lib/src/models/app_implementation.dart @@ -80,17 +80,17 @@ abstract class AppImplementation /// Route for the app. /// /// All pages of the app must be specified as subroutes. - /// If this is not [GoRoute] an inital route name must be specified by overriding [initialRouteName]. + /// If this is not a [GoRoute] an inital path must be specified by overriding [initialPath]. RouteBase get route; /// Name of the initial route for this app. /// /// Subclasses that don't provide a [GoRoute] for [route] must override this. - String get initialRouteName { + String get initialPath { final route = this.route; - if (route is GoRoute && route.name != null) { - return route.name!; + if (route is GoRoute) { + return route.path; } throw FlutterError('No name for the initial route provided.'); diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index 8db0007f..190d70bd 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -25,9 +25,21 @@ part 'router.g.dart'; @internal class AppRouter extends GoRouter { - AppRouter({ - required final GlobalKey navigatorKey, + factory AppRouter({ required final AccountsBloc accountsBloc, + required final Iterable appImplementations, + final GlobalKey? navigatorKey, + }) => + AppRouter._( + navigatorKey: navigatorKey ?? GlobalKey(), + accountsBloc: accountsBloc, + appImplementations: appImplementations, + ); + + AppRouter._({ + required this.navigatorKey, + required final AccountsBloc accountsBloc, + required final Iterable appImplementations, }) : super( debugLogDiagnostics: kDebugMode, refreshListenable: StreamListenable(accountsBloc.activeAccount), @@ -52,6 +64,8 @@ class AppRouter extends GoRouter { }, routes: $appRoutes, ); + + final GlobalKey navigatorKey; } @immutable