Browse Source

refactor(neon,neon_files,neon_news,neon_notes,neon_notifications): Use shared constants for app ids

pull/517/head
jld3103 1 year ago
parent
commit
f8abb76674
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 1
      packages/neon/neon/lib/models.dart
  2. 5
      packages/neon/neon/lib/src/app.dart
  3. 13
      packages/neon/neon/lib/src/blocs/apps.dart
  4. 3
      packages/neon/neon/lib/src/blocs/push_notifications.dart
  5. 6
      packages/neon/neon/lib/src/models/app_ids.dart
  6. 3
      packages/neon/neon/lib/src/utils/push_utils.dart
  7. 4
      packages/neon/neon_files/lib/neon_files.dart
  8. 5
      packages/neon/neon_files/lib/routes.dart
  9. 4
      packages/neon/neon_news/lib/neon_news.dart
  10. 5
      packages/neon/neon_news/lib/routes.dart
  11. 4
      packages/neon/neon_notes/lib/neon_notes.dart
  12. 5
      packages/neon/neon_notes/lib/routes.dart
  13. 4
      packages/neon/neon_notifications/lib/neon_notifications.dart
  14. 2
      packages/neon/neon_notifications/lib/pages/main.dart
  15. 5
      packages/neon/neon_notifications/lib/routes.dart

1
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/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/app_implementation.dart';
export 'package:neon/src/models/notifications_interface.dart'; export 'package:neon/src/models/notifications_interface.dart';

5
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/accounts.dart';
import 'package:neon/src/blocs/capabilities.dart'; import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/account.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/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart'; import 'package:neon/src/models/notifications_interface.dart';
import 'package:neon/src/models/push_notification.dart'; import 'package:neon/src/models/push_notification.dart';
@ -144,7 +145,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
} }
final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false); final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
final app = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?; final app = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?;
if (app == null) { if (app == null) {
return; return;
@ -161,7 +162,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false); final allAppImplementations = Provider.of<Iterable<AppImplementation>>(context, listen: false);
final notificationsApp = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?; final notificationsApp = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?;
if (notificationsApp != null) { if (notificationsApp != null) {
_accountsBloc _accountsBloc
.getAppsBlocFor(account) .getAppsBlocFor(account)

13
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/accounts.dart';
import 'package:neon/src/blocs/capabilities.dart'; import 'package:neon/src/blocs/capabilities.dart';
import 'package:neon/src/models/account.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/app_implementation.dart';
import 'package:neon/src/models/notifications_interface.dart'; import 'package:neon/src/models/notifications_interface.dart';
import 'package:neon/src/settings/models/nextcloud_app_options.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) { _capabilitiesBloc.capabilities.listen((final result) {
notificationsAppImplementation.add( notificationsAppImplementation.add(
result.transform( 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. /// Returns null when no app is supported by the server.
String? _getInitialAppFallback() { String? _getInitialAppFallback() {
final supportedApps = appImplementations.value.requireData; final supportedApps = appImplementations.value.requireData;
if (supportedApps.tryFind('files') != null) { if (supportedApps.tryFind(AppIDs.files) != null) {
return 'files'; return AppIDs.files;
} else if (supportedApps.isNotEmpty) { } else if (supportedApps.isNotEmpty) {
return supportedApps.first.id; return supportedApps.first.id;
} }
@ -115,8 +116,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
try { try {
final (supported, minVersion) = switch (id) { final (supported, minVersion) = switch (id) {
'core' => _account.client.core.isSupported(capabilities.requireData), 'core' => _account.client.core.isSupported(capabilities.requireData),
'news' => await _account.client.news.isSupported(), AppIDs.news => await _account.client.news.isSupported(),
'notes' => _account.client.notes.isSupported(capabilities.requireData), AppIDs.notes => _account.client.notes.isSupported(capabilities.requireData),
_ => (true, null), _ => (true, null),
}; };
@ -201,7 +202,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override @override
Future setActiveApp(final String appID) async { Future setActiveApp(final String appID) async {
if (appID == 'notifications') { if (appID == AppIDs.notifications) {
openNotifications.add(null); openNotifications.add(null);
return; return;
} }

3
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/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.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/models/push_notification.dart';
import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/settings/models/storage.dart'; import 'package:neon/src/settings/models/storage.dart';
@ -39,7 +40,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
final AccountsBloc _accountsBloc; final AccountsBloc _accountsBloc;
final NeonPlatform _platform; final NeonPlatform _platform;
final SharedPreferences _sharedPreferences; final SharedPreferences _sharedPreferences;
late final _storage = AppStorage('notifications', _sharedPreferences); late final _storage = AppStorage(AppIDs.notifications, _sharedPreferences);
final GlobalOptions _globalOptions; final GlobalOptions _globalOptions;
final _notificationsController = StreamController<PushNotification>(); final _notificationsController = StreamController<PushNotification>();

6
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';
}

3
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:meta/meta.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.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/models/push_notification.dart';
import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/settings/models/storage.dart'; import 'package:neon/src/settings/models/storage.dart';
@ -74,7 +75,7 @@ class PushUtils {
); );
final sharedPreferences = await SharedPreferences.getInstance(); 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) { for (final message in Uri(query: utf8.decode(messages)).queryParameters.values) {
final data = json.decode(message) as Map<String, dynamic>; final data = json.decode(message) as Map<String, dynamic>;

4
packages/neon/neon_files/lib/neon_files.dart

@ -49,9 +49,7 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
FilesApp(super.sharedPreferences, super.requestManager, super.platform); FilesApp(super.sharedPreferences, super.requestManager, super.platform);
@override @override
String id = appId; String id = AppIDs.files;
static const String appId = 'files';
@override @override
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;

5
packages/neon/neon_files/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart'; import 'package:neon/utils.dart';
import 'package:neon_files/neon_files.dart'; import 'package:neon_files/neon_files.dart';
part 'routes.g.dart'; part 'routes.g.dart';
@TypedGoRoute<FilesAppRoute>( @TypedGoRoute<FilesAppRoute>(
path: '$appsRoutePrefix${FilesApp.appId}', path: '$appsRoutePrefix${AppIDs.files}',
name: FilesApp.appId, name: AppIDs.files,
) )
@immutable @immutable
class FilesAppRoute extends NeonAppRoute { class FilesAppRoute extends NeonAppRoute {

4
packages/neon/neon_news/lib/neon_news.dart

@ -55,9 +55,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
NewsApp(super.sharedPreferences, super.requestManager, super.platform); NewsApp(super.sharedPreferences, super.requestManager, super.platform);
@override @override
String id = appId; String id = AppIDs.news;
static const String appId = 'news';
@override @override
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;

5
packages/neon/neon_news/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart'; import 'package:neon/utils.dart';
import 'package:neon_news/neon_news.dart'; import 'package:neon_news/neon_news.dart';
part 'routes.g.dart'; part 'routes.g.dart';
@TypedGoRoute<NewsAppRoute>( @TypedGoRoute<NewsAppRoute>(
path: '$appsRoutePrefix${NewsApp.appId}', path: '$appsRoutePrefix${AppIDs.news}',
name: NewsApp.appId, name: AppIDs.news,
) )
@immutable @immutable
class NewsAppRoute extends NeonAppRoute { class NewsAppRoute extends NeonAppRoute {

4
packages/neon/neon_notes/lib/neon_notes.dart

@ -45,9 +45,7 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
NotesApp(super.sharedPreferences, super.requestManager, super.platform); NotesApp(super.sharedPreferences, super.requestManager, super.platform);
@override @override
String id = appId; String id = AppIDs.notes;
static const String appId = 'notes';
@override @override
List<Locale> supportedLocales = AppLocalizations.supportedLocales; List<Locale> supportedLocales = AppLocalizations.supportedLocales;

5
packages/neon/neon_notes/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart'; import 'package:neon/utils.dart';
import 'package:neon_notes/neon_notes.dart'; import 'package:neon_notes/neon_notes.dart';
part 'routes.g.dart'; part 'routes.g.dart';
@TypedGoRoute<NotesAppRoute>( @TypedGoRoute<NotesAppRoute>(
path: '$appsRoutePrefix${NotesApp.appId}', path: '$appsRoutePrefix${AppIDs.notes}',
name: NotesApp.appId, name: AppIDs.notes,
) )
@immutable @immutable
class NotesAppRoute extends NeonAppRoute { class NotesAppRoute extends NeonAppRoute {

4
packages/neon/neon_notifications/lib/neon_notifications.dart

@ -25,9 +25,7 @@ class NotificationsApp extends AppImplementation<NotificationsBloc, Notification
NotificationsApp(super.sharedPreferences, super.requestManager, super.platform); NotificationsApp(super.sharedPreferences, super.requestManager, super.platform);
@override @override
String id = appId; String id = AppIDs.notifications;
static const String appId = 'notifications';
@override @override
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;

2
packages/neon/neon_notifications/lib/pages/main.dart

@ -85,7 +85,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
), ),
), ),
onTap: () async { onTap: () async {
if (notification.app == 'notifications') { if (notification.app == AppIDs.notifications) {
return; return;
} }
if (app != null) { if (app != null) {

5
packages/neon/neon_notifications/lib/routes.dart

@ -1,13 +1,14 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:neon/models.dart';
import 'package:neon/utils.dart'; import 'package:neon/utils.dart';
import 'package:neon_notifications/neon_notifications.dart'; import 'package:neon_notifications/neon_notifications.dart';
part 'routes.g.dart'; part 'routes.g.dart';
@TypedGoRoute<NotificationsAppRoute>( @TypedGoRoute<NotificationsAppRoute>(
path: '$appsRoutePrefix${NotificationsApp.appId}', path: '$appsRoutePrefix${AppIDs.notifications}',
name: NotificationsApp.appId, name: AppIDs.notifications,
) )
@immutable @immutable
class NotificationsAppRoute extends NeonAppRoute { class NotificationsAppRoute extends NeonAppRoute {

Loading…
Cancel
Save