From 45658327909f61cc1ebc1375073d90a193f7e67a Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 13 Jun 2023 09:46:20 +0200 Subject: [PATCH 1/2] app, neon, neon_notifications: allow iterable in appImplementations --- packages/neon/neon/lib/neon.dart | 4 ++-- packages/neon/neon/lib/src/app.dart | 8 ++++---- packages/neon/neon/lib/src/blocs/accounts.dart | 2 +- packages/neon/neon/lib/src/blocs/apps.dart | 16 ++++++++-------- packages/neon/neon/lib/src/models/account.dart | 2 +- packages/neon/neon/lib/src/pages/home.dart | 2 +- packages/neon/neon/lib/src/pages/settings.dart | 2 +- packages/neon/neon/lib/src/router.dart | 2 +- .../neon/lib/src/utils/app_implementation.dart | 2 +- .../lib/src/utils/settings_export_helper.dart | 2 +- .../neon/neon_notifications/lib/pages/main.dart | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 6294ebf9..3ecbe8d2 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -103,7 +103,7 @@ part 'src/widgets/user_avatar.dart'; Future runNeon({ required final WidgetsBinding binding, - required final List Function(SharedPreferences, RequestManager, NeonPlatform) + required final Iterable Function(SharedPreferences, RequestManager, NeonPlatform) getAppImplementations, required final Branding branding, final SharedPreferences? sharedPreferencesOverride, @@ -183,7 +183,7 @@ Future runNeon({ Provider( create: (final _) => nextPushBloc, ), - Provider>( + Provider>( create: (final _) => allAppImplementations, ), Provider( diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index da3ad4ae..48c7bded 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -22,7 +22,7 @@ class NeonApp extends StatefulWidget { class _NeonAppState extends State with WidgetsBindingObserver, tray.TrayListener, WindowListener { final _appRegex = RegExp(r'^app_([a-z]+)$', multiLine: true); final _navigatorKey = GlobalKey(); - late final List _appImplementations; + late final Iterable _appImplementations; late final NeonPlatform _platform; late final GlobalOptions _globalOptions; late final AccountsBloc _accountsBloc; @@ -37,7 +37,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra void initState() { super.initState(); - _appImplementations = Provider.of>(context, listen: false); + _appImplementations = Provider.of>(context, listen: false); _platform = Provider.of(context, listen: false); _globalOptions = Provider.of(context, listen: false); _accountsBloc = Provider.of(context, listen: false); @@ -122,13 +122,13 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra if (account == null) { return; } - final app = Provider.of>(context, listen: false).find('notifications'); + final app = Provider.of>(context, listen: false).find('notifications'); if (app != null) { await _accountsBloc.getAppsBlocFor(account).getAppBloc(app).refresh(); } }; Global.onPushNotificationClicked = (final pushNotificationWithAccountID) async { - final allAppImplementations = Provider.of>(context, listen: false); + final allAppImplementations = Provider.of>(context, listen: false); final app = (pushNotificationWithAccountID.subject.app != null ? allAppImplementations.find(pushNotificationWithAccountID.subject.app!) diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index c667c10c..614136f2 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -91,7 +91,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState late final AppStorage _storage = AppStorage('accounts', _sharedPreferences); final SharedPreferences _sharedPreferences; final GlobalOptions _globalOptions; - final List _allAppImplementations; + final Iterable _allAppImplementations; final _keyLastUsedAccount = 'last-used-account'; final _accountsOptions = {}; diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 5dceb6d8..85f2cd28 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -9,7 +9,7 @@ abstract class AppsBlocEvents { abstract class AppsBlocStates { BehaviorSubject>> get apps; - BehaviorSubject>> get appImplementations; + BehaviorSubject>> get appImplementations; BehaviorSubject> get notificationsAppImplementation; @@ -28,7 +28,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates ) { apps.listen((final result) { appImplementations - .add(result.transform((final data) => _filteredAppImplementations(data.map((final a) => a.id).toList()))); + .add(result.transform((final data) => _filteredAppImplementations(data.map((final a) => a.id)))); }); appImplementations.listen((final result) { @@ -42,7 +42,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates } else if (result.data!.isNotEmpty) { // This should never happen, because the files app is always installed and can not be removed, but just in // case this changes at a later point. - initialApp = result.data![0].id; + initialApp = result.data!.first.id; } } if (!activeAppID.hasValue) { @@ -73,14 +73,14 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates return null; } - List _filteredAppImplementations(final List appIds) => - _allAppImplementations.where((final a) => appIds.contains(a.id)).toList(); + Iterable _filteredAppImplementations(final Iterable appIds) => + _allAppImplementations.where((final a) => appIds.contains(a.id)); final RequestManager _requestManager; final CapabilitiesBloc _capabilitiesBloc; final AccountsBloc _accountsBloc; final Account _account; - final List _allAppImplementations; + final Iterable _allAppImplementations; final Map _blocs = {}; @@ -100,8 +100,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates BehaviorSubject activeAppID = BehaviorSubject(); @override - BehaviorSubject>>> appImplementations = - BehaviorSubject>>(); + BehaviorSubject>>> appImplementations = + BehaviorSubject>>(); @override BehaviorSubject>> apps = BehaviorSubject>>(); diff --git a/packages/neon/neon/lib/src/models/account.dart b/packages/neon/neon/lib/src/models/account.dart index 57a2b975..999e7710 100644 --- a/packages/neon/neon/lib/src/models/account.dart +++ b/packages/neon/neon/lib/src/models/account.dart @@ -103,7 +103,7 @@ extension NextcloudClientHelpers on NextcloudClient { } } -extension AccountFind on List { +extension AccountFind on Iterable { Account? find(final String accountID) { for (final account in this) { if (account.id == accountID) { diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index 620e6b7d..5a802ccb 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -165,7 +165,7 @@ class _HomePageState extends State { @override Widget build(final BuildContext context) => ResultBuilder( stream: _capabilitiesBloc.capabilities, - builder: (final context, final capabilities) => ResultBuilder>( + builder: (final context, final capabilities) => ResultBuilder>( stream: _appsBloc.appImplementations, builder: (final context, final appImplementations) => ResultBuilder( stream: _appsBloc.notificationsAppImplementation, diff --git a/packages/neon/neon/lib/src/pages/settings.dart b/packages/neon/neon/lib/src/pages/settings.dart index efebfb80..65197ebe 100644 --- a/packages/neon/neon/lib/src/pages/settings.dart +++ b/packages/neon/neon/lib/src/pages/settings.dart @@ -14,7 +14,7 @@ class _SettingsPageState extends State { Widget build(final BuildContext context) { final globalOptions = Provider.of(context); final accountsBloc = Provider.of(context, listen: false); - final appImplementations = Provider.of>(context); + final appImplementations = Provider.of>(context); return Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar( diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index a3ca0b3d..699f4cad 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -119,7 +119,7 @@ class NextcloudAppSettingsRoute extends GoRouteData { @override Widget build(final BuildContext context, final GoRouterState state) { - final appImplementations = Provider.of>(context, listen: false); + final appImplementations = Provider.of>(context, listen: false); final appImplementation = appImplementations.find(appid)!; return NextcloudAppSettingsPage(appImplementation: appImplementation); diff --git a/packages/neon/neon/lib/src/utils/app_implementation.dart b/packages/neon/neon/lib/src/utils/app_implementation.dart index 61a75194..c1e207ab 100644 --- a/packages/neon/neon/lib/src/utils/app_implementation.dart +++ b/packages/neon/neon/lib/src/utils/app_implementation.dart @@ -51,7 +51,7 @@ abstract class AppImplementation { +extension AppImplementationFind on Iterable { AppImplementation? find(final String appID) { for (final app in this) { if (app.id == appID) { diff --git a/packages/neon/neon/lib/src/utils/settings_export_helper.dart b/packages/neon/neon/lib/src/utils/settings_export_helper.dart index 83e9d683..d20be57b 100644 --- a/packages/neon/neon/lib/src/utils/settings_export_helper.dart +++ b/packages/neon/neon/lib/src/utils/settings_export_helper.dart @@ -8,7 +8,7 @@ class SettingsExportHelper { }); final GlobalOptions globalOptions; - final List appImplementations; + final Iterable appImplementations; final Map> accountSpecificOptions; Future applyFromJson(final Map data) async { diff --git a/packages/neon/neon_notifications/lib/pages/main.dart b/packages/neon/neon_notifications/lib/pages/main.dart index f647a860..1d984746 100644 --- a/packages/neon/neon_notifications/lib/pages/main.dart +++ b/packages/neon/neon_notifications/lib/pages/main.dart @@ -51,7 +51,7 @@ class _NotificationsMainPageState extends State { final BuildContext context, final NextcloudNotificationsNotification notification, ) { - final app = Provider.of>(context, listen: false).find(notification.app); + final app = Provider.of>(context, listen: false).find(notification.app); return ListTile( title: Text(notification.subject), From dc648d85c087ef65fb4f6afeefe8435ad87c1ce0 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 13 Jun 2023 11:37:34 +0200 Subject: [PATCH 2/2] neon, app: don't require widget WidgetsBinding --- packages/app/integration_test/screenshot_test.dart | 2 +- packages/app/lib/main.dart | 2 -- packages/neon/neon/lib/neon.dart | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/app/integration_test/screenshot_test.dart b/packages/app/integration_test/screenshot_test.dart index ae18b993..064af93d 100644 --- a/packages/app/integration_test/screenshot_test.dart +++ b/packages/app/integration_test/screenshot_test.dart @@ -93,9 +93,9 @@ Future runTestApp( final Account? account, }) async { await runNeon( - binding: binding, getAppImplementations: getAppImplementations, branding: getNeonBranding(), + bindingOverride: binding, sharedPreferencesOverride: MemorySharedPreferences(), account: account, firstLaunchDisabled: true, diff --git a/packages/app/lib/main.dart b/packages/app/lib/main.dart index 6d3a21d3..2a2e91b7 100644 --- a/packages/app/lib/main.dart +++ b/packages/app/lib/main.dart @@ -1,11 +1,9 @@ import 'package:app/apps.dart'; import 'package:app/branding.dart'; -import 'package:flutter/material.dart'; import 'package:neon/neon.dart'; Future main() async { await runNeon( - binding: WidgetsFlutterBinding.ensureInitialized(), getAppImplementations: getAppImplementations, branding: getNeonBranding(), ); diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 3ecbe8d2..6542e5b0 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -102,15 +102,16 @@ part 'src/widgets/text_settings_tile.dart'; part 'src/widgets/user_avatar.dart'; Future runNeon({ - required final WidgetsBinding binding, required final Iterable Function(SharedPreferences, RequestManager, NeonPlatform) getAppImplementations, required final Branding branding, + final WidgetsBinding? bindingOverride, final SharedPreferences? sharedPreferencesOverride, final Account? account, final bool firstLaunchDisabled = false, final bool nextPushDisabled = false, }) async { + final binding = bindingOverride ?? WidgetsFlutterBinding.ensureInitialized(); FlutterNativeSplash.preserve(widgetsBinding: binding); final sharedPreferences = sharedPreferencesOverride ?? await SharedPreferences.getInstance();