diff --git a/packages/neon/neon/lib/models.dart b/packages/neon/neon/lib/models.dart index ce1f317b..600a662b 100644 --- a/packages/neon/neon/lib/models.dart +++ b/packages/neon/neon/lib/models.dart @@ -1,3 +1,4 @@ export 'package:neon/src/models/account.dart' hide Credentials, LoginQrcode; +export 'package:neon/src/models/app_ids.dart'; export 'package:neon/src/models/app_implementation.dart'; export 'package:neon/src/models/notifications_interface.dart'; diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index facb5fe9..ab6224ed 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -10,6 +10,7 @@ import 'package:neon/src/bloc/result_builder.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/capabilities.dart'; 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/models/push_notification.dart'; @@ -144,7 +145,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra } final allAppImplementations = Provider.of>(context, listen: false); - final app = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?; + final app = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?; if (app == null) { return; @@ -161,7 +162,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra final allAppImplementations = Provider.of>(context, listen: false); - final notificationsApp = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?; + final notificationsApp = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?; if (notificationsApp != null) { _accountsBloc .getAppsBlocFor(account) diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index bd2fee0d..4ba93dc3 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -7,6 +7,7 @@ import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/capabilities.dart'; 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/settings/models/nextcloud_app_options.dart'; @@ -66,7 +67,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates _capabilitiesBloc.capabilities.listen((final result) { notificationsAppImplementation.add( result.transform( - (final data) => data.capabilities.notifications != null ? _findAppImplementation('notifications') : null, + (final data) => data.capabilities.notifications != null ? _findAppImplementation(AppIDs.notifications) : null, ), ); @@ -86,8 +87,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates /// Returns null when no app is supported by the server. String? _getInitialAppFallback() { final supportedApps = appImplementations.value.requireData; - if (supportedApps.tryFind('files') != null) { - return 'files'; + if (supportedApps.tryFind(AppIDs.files) != null) { + return AppIDs.files; } else if (supportedApps.isNotEmpty) { return supportedApps.first.id; } @@ -115,8 +116,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates try { final (supported, minVersion) = switch (id) { 'core' => _account.client.core.isSupported(capabilities.requireData), - 'news' => await _account.client.news.isSupported(), - 'notes' => _account.client.notes.isSupported(capabilities.requireData), + AppIDs.news => await _account.client.news.isSupported(), + AppIDs.notes => _account.client.notes.isSupported(capabilities.requireData), _ => (true, null), }; @@ -201,7 +202,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates @override Future setActiveApp(final String appID) async { - if (appID == 'notifications') { + if (appID == AppIDs.notifications) { openNotifications.add(null); return; } diff --git a/packages/neon/neon/lib/src/blocs/push_notifications.dart b/packages/neon/neon/lib/src/blocs/push_notifications.dart index 4c1435f4..15e3d6c0 100644 --- a/packages/neon/neon/lib/src/blocs/push_notifications.dart +++ b/packages/neon/neon/lib/src/blocs/push_notifications.dart @@ -6,6 +6,7 @@ import 'package:meta/meta.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; +import 'package:neon/src/models/app_ids.dart'; import 'package:neon/src/models/push_notification.dart'; import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/settings/models/storage.dart'; @@ -39,7 +40,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, final AccountsBloc _accountsBloc; final NeonPlatform _platform; final SharedPreferences _sharedPreferences; - late final _storage = AppStorage('notifications', _sharedPreferences); + late final _storage = AppStorage(AppIDs.notifications, _sharedPreferences); final GlobalOptions _globalOptions; final _notificationsController = StreamController(); diff --git a/packages/neon/neon/lib/src/models/app_ids.dart b/packages/neon/neon/lib/src/models/app_ids.dart new file mode 100644 index 00000000..e4eaaaf3 --- /dev/null +++ b/packages/neon/neon/lib/src/models/app_ids.dart @@ -0,0 +1,6 @@ +sealed class AppIDs { + static const files = 'files'; + static const news = 'news'; + static const notes = 'notes'; + static const notifications = 'notifications'; +} diff --git a/packages/neon/neon/lib/src/utils/push_utils.dart b/packages/neon/neon/lib/src/utils/push_utils.dart index f96016e1..7a99d025 100644 --- a/packages/neon/neon/lib/src/utils/push_utils.dart +++ b/packages/neon/neon/lib/src/utils/push_utils.dart @@ -11,6 +11,7 @@ import 'package:flutter_svg/flutter_svg.dart' show SvgFileLoader, vg; import 'package:meta/meta.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/models/account.dart'; +import 'package:neon/src/models/app_ids.dart'; import 'package:neon/src/models/push_notification.dart'; import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/settings/models/storage.dart'; @@ -74,7 +75,7 @@ class PushUtils { ); final sharedPreferences = await SharedPreferences.getInstance(); - final keypair = await loadRSAKeypair(AppStorage('notifications', sharedPreferences)); + final keypair = await loadRSAKeypair(AppStorage(AppIDs.notifications, sharedPreferences)); for (final message in Uri(query: utf8.decode(messages)).queryParameters.values) { final data = json.decode(message) as Map; diff --git a/packages/neon/neon_files/lib/neon_files.dart b/packages/neon/neon_files/lib/neon_files.dart index 9a3dbb54..d830140f 100644 --- a/packages/neon/neon_files/lib/neon_files.dart +++ b/packages/neon/neon_files/lib/neon_files.dart @@ -49,9 +49,7 @@ class FilesApp extends AppImplementation { FilesApp(super.sharedPreferences, super.requestManager, super.platform); @override - String id = appId; - - static const String appId = 'files'; + String id = AppIDs.files; @override LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; diff --git a/packages/neon/neon_files/lib/routes.dart b/packages/neon/neon_files/lib/routes.dart index 395b10a4..ed634d9a 100644 --- a/packages/neon/neon_files/lib/routes.dart +++ b/packages/neon/neon_files/lib/routes.dart @@ -1,13 +1,14 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; +import 'package:neon/models.dart'; import 'package:neon/utils.dart'; import 'package:neon_files/neon_files.dart'; part 'routes.g.dart'; @TypedGoRoute( - path: '$appsRoutePrefix${FilesApp.appId}', - name: FilesApp.appId, + path: '$appsRoutePrefix${AppIDs.files}', + name: AppIDs.files, ) @immutable class FilesAppRoute extends NeonAppRoute { diff --git a/packages/neon/neon_news/lib/neon_news.dart b/packages/neon/neon_news/lib/neon_news.dart index 9b9863ea..727a1f5a 100644 --- a/packages/neon/neon_news/lib/neon_news.dart +++ b/packages/neon/neon_news/lib/neon_news.dart @@ -55,9 +55,7 @@ class NewsApp extends AppImplementation { NewsApp(super.sharedPreferences, super.requestManager, super.platform); @override - String id = appId; - - static const String appId = 'news'; + String id = AppIDs.news; @override LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; diff --git a/packages/neon/neon_news/lib/routes.dart b/packages/neon/neon_news/lib/routes.dart index cba521f9..12f505de 100644 --- a/packages/neon/neon_news/lib/routes.dart +++ b/packages/neon/neon_news/lib/routes.dart @@ -1,13 +1,14 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; +import 'package:neon/models.dart'; import 'package:neon/utils.dart'; import 'package:neon_news/neon_news.dart'; part 'routes.g.dart'; @TypedGoRoute( - path: '$appsRoutePrefix${NewsApp.appId}', - name: NewsApp.appId, + path: '$appsRoutePrefix${AppIDs.news}', + name: AppIDs.news, ) @immutable class NewsAppRoute extends NeonAppRoute { diff --git a/packages/neon/neon_notes/lib/neon_notes.dart b/packages/neon/neon_notes/lib/neon_notes.dart index 7478f852..e032f25f 100644 --- a/packages/neon/neon_notes/lib/neon_notes.dart +++ b/packages/neon/neon_notes/lib/neon_notes.dart @@ -45,9 +45,7 @@ class NotesApp extends AppImplementation { NotesApp(super.sharedPreferences, super.requestManager, super.platform); @override - String id = appId; - - static const String appId = 'notes'; + String id = AppIDs.notes; @override List supportedLocales = AppLocalizations.supportedLocales; diff --git a/packages/neon/neon_notes/lib/routes.dart b/packages/neon/neon_notes/lib/routes.dart index 8cbb7f3f..b4e00b50 100644 --- a/packages/neon/neon_notes/lib/routes.dart +++ b/packages/neon/neon_notes/lib/routes.dart @@ -1,13 +1,14 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; +import 'package:neon/models.dart'; import 'package:neon/utils.dart'; import 'package:neon_notes/neon_notes.dart'; part 'routes.g.dart'; @TypedGoRoute( - path: '$appsRoutePrefix${NotesApp.appId}', - name: NotesApp.appId, + path: '$appsRoutePrefix${AppIDs.notes}', + name: AppIDs.notes, ) @immutable class NotesAppRoute extends NeonAppRoute { diff --git a/packages/neon/neon_notifications/lib/neon_notifications.dart b/packages/neon/neon_notifications/lib/neon_notifications.dart index eee8591f..a297768a 100644 --- a/packages/neon/neon_notifications/lib/neon_notifications.dart +++ b/packages/neon/neon_notifications/lib/neon_notifications.dart @@ -25,9 +25,7 @@ class NotificationsApp extends AppImplementation { ), ), onTap: () async { - if (notification.app == 'notifications') { + if (notification.app == AppIDs.notifications) { return; } if (app != null) { diff --git a/packages/neon/neon_notifications/lib/routes.dart b/packages/neon/neon_notifications/lib/routes.dart index 39f79ba7..c2f57b75 100644 --- a/packages/neon/neon_notifications/lib/routes.dart +++ b/packages/neon/neon_notifications/lib/routes.dart @@ -1,13 +1,14 @@ import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; +import 'package:neon/models.dart'; import 'package:neon/utils.dart'; import 'package:neon_notifications/neon_notifications.dart'; part 'routes.g.dart'; @TypedGoRoute( - path: '$appsRoutePrefix${NotificationsApp.appId}', - name: NotificationsApp.appId, + path: '$appsRoutePrefix${AppIDs.notifications}', + name: AppIDs.notifications, ) @immutable class NotificationsAppRoute extends NeonAppRoute {