Skip to content

Commit

Permalink
refactor(neon_framework): rewrite login flow and account handling
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Sep 12, 2024
1 parent aea3e89 commit 26dca5d
Show file tree
Hide file tree
Showing 99 changed files with 4,158 additions and 2,397 deletions.
39 changes: 39 additions & 0 deletions packages/neon_framework/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ packages:
description: dart
source: sdk
version: "0.3.2"
account_repository:
dependency: "direct overridden"
description:
path: "../packages/account_repository"
relative: true
source: path
version: "0.1.0"
analyzer:
dependency: transitive
description:
Expand Down Expand Up @@ -70,6 +77,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
bloc:
dependency: transitive
description:
name: bloc
sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e"
url: "https://pub.dev"
source: hosted
version: "8.1.4"
bloc_concurrency:
dependency: transitive
description:
name: bloc_concurrency
sha256: "456b7a3616a7c1ceb975c14441b3f198bf57d81cb95b7c6de5cb0c60201afcd8"
url: "https://pub.dev"
source: hosted
version: "0.2.5"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -315,6 +338,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
equatable:
dependency: transitive
description:
name: equatable
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2
url: "https://pub.dev"
source: hosted
version: "2.0.5"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -407,6 +438,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_bloc:
dependency: transitive
description:
name: flutter_bloc
sha256: b594505eac31a0518bdcb4b5b79573b8d9117b193cc80cc12e17d639b10aa27a
url: "https://pub.dev"
source: hosted
version: "8.1.6"
flutter_blurhash:
dependency: transitive
description:
Expand Down
4 changes: 3 additions & 1 deletion packages/neon_framework/example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# melos_managed_dependency_overrides: cookie_store,dashboard_app,dynamite_runtime,files_app,interceptor_http_client,neon_framework,neon_http_client,neon_lints,news_app,nextcloud,notes_app,notifications_app,sort_box,talk_app
# melos_managed_dependency_overrides: account_repository,cookie_store,dashboard_app,dynamite_runtime,files_app,interceptor_http_client,neon_framework,neon_http_client,neon_lints,news_app,nextcloud,notes_app,notifications_app,sort_box,talk_app
dependency_overrides:
account_repository:
path: ../packages/account_repository
cookie_store:
path: ../../cookie_store
dashboard_app:
Expand Down
32 changes: 24 additions & 8 deletions packages/neon_framework/lib/l10n/en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,42 @@
"loginWorksWith": "works with",
"loginUsingQRcode": "Login using a QR code",
"loginUsingServerAddress": "Login using the server address",
"loginCheckingServerVersion": "Checking server version",
"loginSupportedServerVersion": "Supported server version: {version}",
"@loginSupportedServerVersion": {
"loginServerVersion": "Checking server version",
"@loginServerVersion": {
"description": "When the server version is checked an not yet known"
},
"loginServerVersionSupported": "Supported server version: {version}",
"@loginServerVersionSupported": {
"description": "When the server version is known and supported",
"placeholders": {
"version": {
"type": "String"
"type": "String",
"example": "29.0.0"
}
}
},
"loginUnsupportedServerVersion": "Unsupported server version: {version}",
"@loginUnsupportedServerVersion": {
"loginServerVersionUnsupported": "Unsupported server version: {version}}",
"@loginServerVersionUnsupported": {
"description": "When the server version is known but unsupported",
"placeholders": {
"version": {
"type": "String"
"type": "String",
"example": "29.0.0"
}
}
},
"loginCheckingMaintenanceMode": "Checking maintenance mode",
"loginMaintenanceMode": "Checking maintenance mode",
"@loginMaintenanceMode": {
"description": "when the maintenance mode is loaded from the server"
},
"loginMaintenanceModeEnabled": "Maintenance mode enabled",
"@loginMaintenanceModeEnabled": {
"description": "When the maintenance mode is enabled"
},
"loginMaintenanceModeDisabled": "Maintenance mode disabled",
"@loginMaintenanceModeDisabled": {
"description": "When the maintenance mode is disabled"
},
"loginCheckingAccount": "Checking account",
"errorCredentialsForAccountNoLongerMatch": "The credentials for this account no longer match",
"errorBruteforceThrottled": "Your requests are throttled at the moment due to brute force protection",
Expand Down
22 changes: 11 additions & 11 deletions packages/neon_framework/lib/l10n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,37 @@ abstract class NeonLocalizations {
/// **'Login using the server address'**
String get loginUsingServerAddress;

/// No description provided for @loginCheckingServerVersion.
/// When the server version is checked an not yet known
///
/// In en, this message translates to:
/// **'Checking server version'**
String get loginCheckingServerVersion;
String get loginServerVersion;

/// No description provided for @loginSupportedServerVersion.
/// When the server version is known and supported
///
/// In en, this message translates to:
/// **'Supported server version: {version}'**
String loginSupportedServerVersion(String version);
String loginServerVersionSupported(String version);

/// No description provided for @loginUnsupportedServerVersion.
/// When the server version is known but unsupported
///
/// In en, this message translates to:
/// **'Unsupported server version: {version}'**
String loginUnsupportedServerVersion(String version);
/// **'Unsupported server version: {version}}'**
String loginServerVersionUnsupported(String version);

/// No description provided for @loginCheckingMaintenanceMode.
/// when the maintenance mode is loaded from the server
///
/// In en, this message translates to:
/// **'Checking maintenance mode'**
String get loginCheckingMaintenanceMode;
String get loginMaintenanceMode;

/// No description provided for @loginMaintenanceModeEnabled.
/// When the maintenance mode is enabled
///
/// In en, this message translates to:
/// **'Maintenance mode enabled'**
String get loginMaintenanceModeEnabled;

/// No description provided for @loginMaintenanceModeDisabled.
/// When the maintenance mode is disabled
///
/// In en, this message translates to:
/// **'Maintenance mode disabled'**
Expand Down
8 changes: 4 additions & 4 deletions packages/neon_framework/lib/l10n/localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get loginUsingServerAddress => 'Login using the server address';

@override
String get loginCheckingServerVersion => 'Checking server version';
String get loginServerVersion => 'Checking server version';

@override
String loginSupportedServerVersion(String version) {
String loginServerVersionSupported(String version) {
return 'Supported server version: $version';
}

@override
String loginUnsupportedServerVersion(String version) {
String loginServerVersionUnsupported(String version) {
return 'Unsupported server version: $version';
}

@override
String get loginCheckingMaintenanceMode => 'Checking maintenance mode';
String get loginMaintenanceMode => 'Checking maintenance mode';

@override
String get loginMaintenanceModeEnabled => 'Maintenance mode enabled';
Expand Down
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// {@canonicalFor label_builder.LabelBuilder}
library;

export 'package:neon_framework/src/models/account.dart' hide Credentials, LoginQRcode;
export 'package:account_repository/account_repository.dart' show Account;
export 'package:neon_framework/src/models/app_implementation.dart';
export 'package:neon_framework/src/models/label_builder.dart';
export 'package:neon_framework/src/models/notifications_interface.dart';
27 changes: 24 additions & 3 deletions packages/neon_framework/lib/neon.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:async';

import 'package:account_repository/account_repository.dart';
import 'package:built_collection/built_collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:neon_framework/src/app.dart';
import 'package:neon_framework/src/blocs/accounts.dart';
Expand All @@ -13,6 +16,7 @@ import 'package:neon_framework/src/blocs/push_notifications.dart';
import 'package:neon_framework/src/models/app_implementation.dart';
import 'package:neon_framework/src/models/disposable.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/theme/neon.dart';
import 'package:neon_framework/src/utils/global_options.dart';
import 'package:neon_framework/src/utils/provider.dart';
Expand All @@ -30,6 +34,7 @@ import 'package:timezone/timezone.dart' as tz;
Future<void> runNeon({
required BuiltSet<AppImplementation> appImplementations,
required NeonTheme theme,
http.Client? httpClient,
}) async {
assert(appImplementations.isNotEmpty, 'At least one AppImplementation required');

Expand All @@ -51,20 +56,35 @@ Future<void> runNeon({
await NeonStorage().init();

final packageInfo = await PackageInfo.fromPlatform();
buildUserAgent(packageInfo);

final globalOptions = GlobalOptions(
packageInfo,
);

final accountStorage = AccountStorage(
accountsPersistence: NeonStorage().singleValueStore(StorageKeys.accounts),
lastAccountPersistence: NeonStorage().singleValueStore(StorageKeys.lastUsedAccount),
);

final accountRepository = AccountRepository(
userAgent: buildUserAgent(packageInfo, theme.branding.name),
httpClient: httpClient ?? http.Client(),
storage: accountStorage,
);

await accountRepository.loadAccounts(
initialAccount: globalOptions.initialAccount.value,
rememberLastUsedAccount: globalOptions.rememberLastUsedAccount.value,
);

final accountsBloc = AccountsBloc(
globalOptions: globalOptions,
allAppImplementations: appImplementations,
accountRepository: accountRepository,
);

PushNotificationsBloc(
accountsSubject: accountsBloc.accounts,
globalOptions: globalOptions,
accountRepository: accountRepository,
);
final firstLaunchBloc = FirstLaunchBloc();
final nextPushBloc = NextPushBloc(
Expand All @@ -75,6 +95,7 @@ Future<void> runNeon({
runApp(
MultiProvider(
providers: [
RepositoryProvider.value(value: accountRepository),
NeonProvider<GlobalOptions>.value(value: globalOptions),
NeonProvider<AccountsBloc>.value(value: accountsBloc),
NeonProvider<FirstLaunchBloc>.value(value: firstLaunchBloc),
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
@@ -1,19 +1,18 @@
import 'dart:async';
import 'dart:convert';

import 'package:account_repository/account_repository.dart';
import 'package:built_collection/built_collection.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:meta/meta.dart';
import 'package:neon_framework/blocs.dart';
import 'package:neon_framework/l10n/localizations.dart';
import 'package:neon_framework/models.dart';
import 'package:neon_framework/src/blocs/accounts.dart';
import 'package:neon_framework/src/blocs/maintenance_mode.dart';
import 'package:neon_framework/src/blocs/unified_search.dart';
import 'package:neon_framework/src/models/account.dart';
import 'package:neon_framework/src/models/app_implementation.dart';
import 'package:neon_framework/src/models/notifications_interface.dart';
import 'package:neon_framework/src/models/push_notification.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:neon_framework/src/router.dart';
Expand Down Expand Up @@ -62,6 +61,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, WindowLi
late final AccountsBloc _accountsBloc;
late final _routerDelegate = buildAppRouter(
navigatorKey: _navigatorKey,
accountRepository: context.read<AccountRepository>(),
);

@override
Expand Down
Loading

0 comments on commit 26dca5d

Please sign in to comment.