Skip to content

Commit

Permalink
refactor(nextcloud): Deprecate AppIDs in favor of exported appID cons…
Browse files Browse the repository at this point in the history
…tants

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Aug 5, 2024
1 parent fb71571 commit e9c7be4
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 35 deletions.
4 changes: 2 additions & 2 deletions packages/neon/neon_dashboard/lib/neon_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import 'package:neon_dashboard/src/options.dart';
import 'package:neon_dashboard/src/pages/main.dart';
import 'package:neon_dashboard/src/routes.dart';
import 'package:neon_framework/models.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/dashboard.dart' as dashboard;

/// Implementation of the server `dashboard` app.
class DashboardApp extends AppImplementation<DashboardBloc, DashboardOptions> {
/// Creates a new Dashboard app implementation instance.
DashboardApp();

@override
final String id = AppIDs.dashboard;
final String id = dashboard.appID;

@override
final LocalizationsDelegate<DashboardLocalizations> localizationsDelegate = DashboardLocalizations.delegate;
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_dashboard/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon_dashboard/src/pages/main.dart';
import 'package:neon_framework/utils.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/dashboard.dart' as dashboard;

part 'routes.g.dart';

/// Route for the dashboard app.
@TypedGoRoute<DashboardAppRoute>(
path: '$appsBaseRoutePrefix${AppIDs.dashboard}',
name: AppIDs.dashboard,
path: '$appsBaseRoutePrefix${dashboard.appID}',
name: dashboard.appID,
)
@immutable
class DashboardAppRoute extends NeonBaseAppRoute {
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_files/lib/neon_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import 'package:neon_files/src/options.dart';
import 'package:neon_files/src/pages/main.dart';
import 'package:neon_files/src/routes.dart';
import 'package:neon_framework/models.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/files.dart' as files;

class FilesApp extends AppImplementation<FilesBloc, FilesOptions> {
FilesApp();

@override
final String id = AppIDs.files;
final String id = files.appID;

@override
final LocalizationsDelegate<FilesLocalizations> localizationsDelegate = FilesLocalizations.delegate;
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_files/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon_files/src/pages/main.dart';
import 'package:neon_framework/utils.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/files.dart' as files;

part 'routes.g.dart';

@TypedGoRoute<FilesAppRoute>(
path: '$appsBaseRoutePrefix${AppIDs.files}',
name: AppIDs.files,
path: '$appsBaseRoutePrefix${files.appID}',
name: files.appID,
)
@immutable
class FilesAppRoute extends NeonBaseAppRoute {
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_news/lib/neon_news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsOptions> {
NewsApp();

@override
final String id = AppIDs.news;
final String id = news.appID;

@override
final LocalizationsDelegate<NewsLocalizations> localizationsDelegate = NewsLocalizations.delegate;
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_news/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_news/src/pages/main.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/news.dart' as news;

part 'routes.g.dart';

@TypedGoRoute<NewsAppRoute>(
path: '$appsBaseRoutePrefix${AppIDs.news}',
name: AppIDs.news,
path: '$appsBaseRoutePrefix${news.appID}',
name: news.appID,
)
@immutable
class NewsAppRoute extends NeonBaseAppRoute {
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_notes/lib/neon_notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NotesApp extends AppImplementation<NotesBloc, NotesOptions> {
NotesApp();

@override
final String id = AppIDs.notes;
final String id = notes.appID;

@override
final List<Locale> supportedLocales = NotesLocalizations.supportedLocales;
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_notes/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_notes/src/pages/main.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notes.dart' as notes;

part 'routes.g.dart';

@TypedGoRoute<NotesAppRoute>(
path: '$appsBaseRoutePrefix${AppIDs.notes}',
name: AppIDs.notes,
path: '$appsBaseRoutePrefix${notes.appID}',
name: notes.appID,
)
@immutable
class NotesAppRoute extends NeonBaseAppRoute {
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_notifications/lib/neon_notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:neon_notifications/src/blocs/notifications.dart';
import 'package:neon_notifications/src/options.dart';
import 'package:neon_notifications/src/pages/main.dart';
import 'package:neon_notifications/src/routes.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notifications.dart' as notifications;
import 'package:rxdart/rxdart.dart';

class NotificationsApp extends AppImplementation<NotificationsBlocInterface, NotificationsOptions>
Expand All @@ -21,7 +21,7 @@ class NotificationsApp extends AppImplementation<NotificationsBlocInterface, Not
NotificationsApp();

@override
final String id = AppIDs.notifications;
final String id = notifications.appID;

@override
final LocalizationsDelegate<NotificationsLocalizations> localizationsDelegate = NotificationsLocalizations.delegate;
Expand Down
6 changes: 3 additions & 3 deletions packages/neon/neon_notifications/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_notifications/src/pages/main.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notifications.dart' as notifications;

part 'routes.g.dart';

@TypedGoRoute<NotificationsAppRoute>(
path: '$appsBaseRoutePrefix${AppIDs.notifications}',
name: AppIDs.notifications,
path: '$appsBaseRoutePrefix${notifications.appID}',
name: notifications.appID,
)
@immutable
class NotificationsAppRoute extends NeonBaseAppRoute {
Expand Down
4 changes: 2 additions & 2 deletions packages/neon/neon_talk/lib/neon_talk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:neon_talk/src/routes.dart';
import 'package:neon_talk/src/theme.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/spreed.dart';
import 'package:nextcloud/spreed.dart' as spreed;
import 'package:rxdart/rxdart.dart';

/// Implementation of the server `talk` app.
Expand All @@ -29,7 +29,7 @@ class TalkApp extends AppImplementation<TalkBloc, TalkOptions> {
final String id = 'talk';

@override
final BuiltSet<String> additionalMatchingIDs = BuiltSet([AppIDs.spreed]);
final BuiltSet<String> additionalMatchingIDs = BuiltSet([spreed.appID]);

@override
final LocalizationsDelegate<TalkLocalizations> localizationsDelegate = TalkLocalizations.delegate;
Expand Down
6 changes: 3 additions & 3 deletions packages/neon_framework/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'package:neon_framework/src/utils/localizations.dart';
import 'package:neon_framework/src/utils/provider.dart';
import 'package:neon_framework/src/utils/push_utils.dart';
import 'package:neon_framework/src/widgets/options_collection_builder.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notifications.dart' as notifications;
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:universal_io/io.dart';
Expand Down Expand Up @@ -117,7 +117,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, WindowLi
}

final allAppImplementations = NeonProvider.of<BuiltSet<AppImplementation>>(context);
final app = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?;
final app = allAppImplementations.tryFind(notifications.appID) as NotificationsAppInterface?;

if (app == null) {
return;
Expand All @@ -134,7 +134,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, WindowLi

final allAppImplementations = NeonProvider.of<BuiltSet<AppImplementation>>(context);

final notificationsApp = allAppImplementations.tryFind(AppIDs.notifications) as NotificationsAppInterface?;
final notificationsApp = allAppImplementations.tryFind(notifications.appID) as NotificationsAppInterface?;
if (notificationsApp != null) {
_accountsBloc
.getAppsBlocFor(account)
Expand Down
7 changes: 5 additions & 2 deletions packages/neon_framework/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import 'package:neon_framework/src/utils/account_options.dart';
import 'package:neon_framework/src/utils/findable.dart';
import 'package:neon_framework/src/utils/request_manager.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/dashboard.dart' as dashboard;
import 'package:nextcloud/files.dart' as files;
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notifications.dart' as notifications;
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';

Expand Down Expand Up @@ -116,7 +119,7 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
final notificationsCapabilities =
capabilitiesResult.requireData.capabilities.notificationsCapabilities?.notifications;
if (notificationsCapabilities != null) {
final notificationsApp = allAppImplementations.firstWhereOrNull((a) => a.id == AppIDs.notifications);
final notificationsApp = allAppImplementations.firstWhereOrNull((a) => a.id == notifications.appID);
if (notificationsApp != null) {
appImplementationsBuilder.add(notificationsApp);
}
Expand Down Expand Up @@ -167,7 +170,7 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
return null;
}

for (final fallback in {accountOptions.initialApp.value, AppIDs.dashboard, AppIDs.files}) {
for (final fallback in {accountOptions.initialApp.value, dashboard.appID, files.appID}) {
if (supportedApps.tryFind(fallback) != null) {
return fallback;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/neon_framework/lib/src/storage/keys.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:meta/meta.dart';
import 'package:nextcloud/nextcloud.dart';

/// Interface of a storable element.
///
Expand Down Expand Up @@ -36,7 +35,7 @@ enum StorageKeys implements Storable {
firstLaunch._('first-launch'),

/// The key for the `PushUtils`.
notifications._(AppIDs.notifications);
notifications._('notifications');

const StorageKeys._(this.value);

Expand Down
8 changes: 5 additions & 3 deletions packages/neon_framework/test/apps_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import 'package:neon_framework/models.dart';
import 'package:neon_framework/src/utils/account_options.dart';
import 'package:neon_framework/testing.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/dashboard.dart' as dashboard;
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/notifications.dart' as notifications;
import 'package:rxdart/rxdart.dart';
import 'package:version/version.dart';

Expand Down Expand Up @@ -47,7 +49,7 @@ Account mockAppsAccount() {
'unread': 0,
},
{
'id': AppIDs.dashboard,
'id': dashboard.appID,
'order': 2,
'href': '',
'icon': '',
Expand Down Expand Up @@ -254,7 +256,7 @@ void main() {
when(() => appImplementation1.blocsCache).thenReturn(MockAccountCache<Bloc>());

final appImplementation2 = MockAppImplementation();
when(() => appImplementation2.id).thenReturn(AppIDs.dashboard);
when(() => appImplementation2.id).thenReturn(dashboard.appID);
when(() => appImplementation2.blocsCache).thenReturn(MockAccountCache<Bloc>());

final allAppImplementation = BuiltSet<AppImplementation>([
Expand Down Expand Up @@ -293,7 +295,7 @@ void main() {
when(() => appImplementation1.blocsCache).thenReturn(MockAccountCache<Bloc>());

final appImplementation2 = MockAppImplementation();
when(() => appImplementation2.id).thenReturn(AppIDs.notifications);
when(() => appImplementation2.id).thenReturn(notifications.appID);
when(() => appImplementation2.blocsCache).thenReturn(MockAccountCache<Bloc>());

final allAppImplementation = BuiltSet<AppImplementation>([
Expand Down
2 changes: 2 additions & 0 deletions packages/nextcloud/generate_exports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void main() {
final library = Library((b) {
final appIDBuilder = ClassBuilder()
..docs.add('/// IDs of the apps.')
..annotations
.add(refer('Deprecated').call([refer("\"Use 'appID' from 'package:nextcloud/<id>.dart' instead.\"")]))
..name = 'AppIDs'
..modifier = ClassModifier.final$;

Expand Down
1 change: 1 addition & 0 deletions packages/nextcloud/lib/src/app_ids.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:nextcloud/user_status.dart' as _user_status;
import 'package:nextcloud/weather_status.dart' as _weather_status;

/// IDs of the apps.
@Deprecated("Use 'appID' from 'package:nextcloud/<id>.dart' instead.")
final class AppIDs {
/// ID for the comments app.
static const String comments = _comments.appID;
Expand Down

0 comments on commit e9c7be4

Please sign in to comment.