Skip to content

Commit

Permalink
refactor(neon_framework): migrate to neon_storage
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Sep 13, 2024
1 parent 02eebe9 commit 40478d6
Show file tree
Hide file tree
Showing 44 changed files with 267 additions and 1,496 deletions.
15 changes: 7 additions & 8 deletions packages/neon_framework/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,13 @@ packages:
relative: true
source: path
version: "1.0.0"
neon_storage:
dependency: "direct overridden"
description:
path: "../packages/neon_storage"
relative: true
source: path
version: "0.1.0"
nested:
dependency: transitive
description:
Expand Down Expand Up @@ -1337,14 +1344,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
sqflite:
dependency: transitive
description:
name: sqflite
sha256: a43e5a27235518c03ca238e7b4732cf35eabe863a369ceba6cbefa537a66f16d
url: "https://pub.dev"
source: hosted
version: "2.3.3+1"
sqflite_common:
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,4 +1,4 @@
# 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
# melos_managed_dependency_overrides: account_repository,cookie_store,dashboard_app,dynamite_runtime,files_app,interceptor_http_client,neon_framework,neon_http_client,neon_lints,neon_storage,news_app,nextcloud,notes_app,notifications_app,sort_box,talk_app
dependency_overrides:
account_repository:
path: ../packages/account_repository
Expand All @@ -18,6 +18,8 @@ dependency_overrides:
path: ../packages/neon_http_client
neon_lints:
path: ../../neon_lints
neon_storage:
path: ../packages/neon_storage
news_app:
path: ../packages/news_app
nextcloud:
Expand Down
19 changes: 12 additions & 7 deletions packages/neon_framework/lib/l10n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ abstract class NeonLocalizations {
];

/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[Locale('en')];
static const List<Locale> supportedLocales = <Locale>[
Locale('en')
];

/// No description provided for @nextcloud.
///
Expand Down Expand Up @@ -888,14 +890,17 @@ class _NeonLocalizationsDelegate extends LocalizationsDelegate<NeonLocalizations
}

NeonLocalizations lookupNeonLocalizations(Locale locale) {


// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'en':
return NeonLocalizationsEn();
case 'en': return NeonLocalizationsEn();
}

throw FlutterError('NeonLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
throw FlutterError(
'NeonLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'
);
}
18 changes: 6 additions & 12 deletions packages/neon_framework/lib/l10n/localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get errorBruteforceThrottled => 'Your requests are throttled at the moment due to brute force protection';

@override
String get errorServerHadAProblemProcessingYourRequest =>
'The server had a problem while processing your request. You might want to try again';
String get errorServerHadAProblemProcessingYourRequest => 'The server had a problem while processing your request. You might want to try again';

@override
String get errorSomethingWentWrongTryAgainLater => 'Something went wrong. Please try again later';
Expand All @@ -101,12 +100,10 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get errorConnectionTimedOut => 'Connection has timed out';

@override
String get errorNoCompatibleNextcloudAppsFound =>
'No compatible Nextcloud apps could be found.\nWe are working hard to implement more and more apps!';
String get errorNoCompatibleNextcloudAppsFound => 'No compatible Nextcloud apps could be found.\nWe are working hard to implement more and more apps!';

@override
String get errorServerInMaintenanceMode =>
'The server is in maintenance mode. Please try again later or contact the server admin.';
String get errorServerInMaintenanceMode => 'The server is in maintenance mode. Please try again later or contact the server admin.';

@override
String errorMissingPermission(String name) {
Expand Down Expand Up @@ -169,8 +166,7 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get nextPushSupported => 'NextPush is supported!';

@override
String get nextPushSupportedText =>
'NextPush is a FOSS way of receiving push notifications using the UnifiedPush protocol via a Nextcloud instance.\nYou can install NextPush from the F-Droid app store.';
String get nextPushSupportedText => 'NextPush is a FOSS way of receiving push notifications using the UnifiedPush protocol via a Nextcloud instance.\nYou can install NextPush from the F-Droid app store.';

@override
String get nextPushSupportedInstall => 'Install NextPush';
Expand Down Expand Up @@ -225,8 +221,7 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get settingsResetForExplanation => 'This will reset your account preferences back to their default settings.';

@override
String get settingsResetForClientExplanation =>
'This will reset all preferences for the app back to their default settings.';
String get settingsResetForClientExplanation => 'This will reset all preferences for the app back to their default settings.';

@override
String settingsResetForConfirmation(String name) {
Expand Down Expand Up @@ -285,8 +280,7 @@ class NeonLocalizationsEn extends NeonLocalizations {
String get globalOptionsPushNotificationsEnabled => 'Enabled';

@override
String get globalOptionsPushNotificationsEnabledDisabledNotice =>
'No UnifiedPush distributor could be found or you denied the permission for showing notifications. Please go to the app settings and allow notifications and go to https://unifiedpush.org/users/distributors and setup any of the listed distributors. Then re-open this app and you should be able to enable notifications';
String get globalOptionsPushNotificationsEnabledDisabledNotice => 'No UnifiedPush distributor could be found or you denied the permission for showing notifications. Please go to the app settings and allow notifications and go to https://unifiedpush.org/users/distributors and setup any of the listed distributors. Then re-open this app and you should be able to enable notifications';

@override
String get globalOptionsPushNotificationsDistributor => 'UnifiedPush Distributor';
Expand Down
3 changes: 1 addition & 2 deletions packages/neon_framework/lib/neon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ 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/storage/storage.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';
import 'package:neon_framework/src/utils/timezone.dart';
import 'package:neon_framework/src/utils/user_agent.dart';
import 'package:neon_framework/storage.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:timezone/data/latest.dart' as tzdata;
Expand Down
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/src/blocs/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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_cache.dart';
import 'package:neon_framework/src/models/disposable.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/storage/storage_keys.dart';
import 'package:neon_framework/src/utils/account_options.dart';
import 'package:neon_framework/storage.dart';
import 'package:rxdart/rxdart.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/src/blocs/first_launch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:neon_framework/src/bloc/bloc.dart';
import 'package:neon_framework/src/models/disposable.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/storage/storage_keys.dart';
import 'package:neon_framework/storage.dart';
import 'package:rxdart/rxdart.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:neon_framework/src/bloc/bloc.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/storage/storage_keys.dart';
import 'package:neon_framework/src/utils/global_options.dart';
import 'package:neon_framework/src/utils/push_utils.dart';
import 'package:neon_framework/storage.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:neon_framework/src/bloc/bloc.dart';
import 'package:neon_framework/src/models/account_cache.dart';
import 'package:neon_framework/src/models/disposable.dart';
import 'package:neon_framework/src/settings/models/options_collection.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/storage/storage_keys.dart';
import 'package:neon_framework/src/utils/findable.dart';
import 'package:neon_framework/src/utils/provider.dart';
import 'package:neon_framework/src/widgets/drawer_destination.dart';
Expand Down
6 changes: 1 addition & 5 deletions packages/neon_framework/lib/src/platform/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:typed_data';
import 'package:file_picker/file_picker.dart';
import 'package:meta/meta.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:universal_io/io.dart';

/// Linux specific platform information.
Expand Down Expand Up @@ -43,10 +42,7 @@ class LinuxNeonPlatform implements NeonPlatform {
bool get canUsePaths => true;

@override
void init() {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
}
void init() {}

@override
Future<void> saveFileWithPickDialog(String fileName, String mimeType, Uint8List data) async {
Expand Down
6 changes: 1 addition & 5 deletions packages/neon_framework/lib/src/platform/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import 'dart:typed_data';

import 'package:meta/meta.dart';
import 'package:neon_framework/src/platform/platform.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
import 'package:web/web.dart';

@immutable
Expand Down Expand Up @@ -39,9 +37,7 @@ class WebNeonPlatform implements NeonPlatform {
bool get canUsePaths => false;

@override
Future<void> init() async {
databaseFactory = databaseFactoryFfiWeb;
}
void init() {}

@override
Future<String?> saveFileWithPickDialog(String fileName, String mimeType, Uint8List data) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:neon_framework/models.dart';
import 'package:neon_framework/src/blocs/accounts.dart';
import 'package:neon_framework/src/settings/models/exportable.dart';
import 'package:neon_framework/src/settings/models/option.dart';
import 'package:neon_framework/src/storage/keys.dart';
import 'package:neon_framework/src/storage/storage_keys.dart';
import 'package:neon_framework/src/utils/findable.dart';

/// Helper class to export all [Option]s.
Expand Down
67 changes: 67 additions & 0 deletions packages/neon_framework/lib/src/storage/neon_cache_db.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'dart:async';

import 'package:cookie_store/cookie_store.dart';
import 'package:flutter/foundation.dart';
import 'package:neon_storage/neon_sqlite.dart';
import 'package:neon_storage/neon_storage.dart';

import 'package:path_provider/path_provider.dart';

/// Database holding the neon cache.
final class NeonCacheDB extends MultiTableDatabase {
/// Creates a new database with the given [tables].
factory NeonCacheDB({
Iterable<Table>? tables,
}) {
return NeonCacheDB._(
tables: [
...?tables,
if (!kIsWeb) SQLiteRequestCache.table,
if (!kIsWeb) SQLiteCookiePersistence.table,
],
);
}

NeonCacheDB._({
required super.tables,
});

@override
String get name => 'cache';

@override
Future<String> get path async {
final cacheDir = await getApplicationCacheDirectory();

return buildDatabasePath(cacheDir.path, name);
}

/// The current request cache if available.
RequestCache? get requestCache {
if (kIsWeb) {
return null;
}

assertInitialized();

return const SQLiteRequestCache();
}

/// Creates a new `CookieStore` scoped to the given [accountID] and [serverURL].
///
/// Cookies will only be sent to cookies matching the [serverURL].
CookieStore? cookieStore({required String accountID, required Uri serverURL}) {
if (kIsWeb) {
return null;
}

assertInitialized();

final persistence = SQLiteCookiePersistence(
accountID: accountID,
allowedBaseUri: serverURL,
);

return DefaultCookieStore(persistence);
}
}
34 changes: 34 additions & 0 deletions packages/neon_framework/lib/src/storage/neon_data_db.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:async';

import 'package:neon_storage/neon_sqlite.dart';
import 'package:neon_storage/neon_storage.dart';
import 'package:path_provider/path_provider.dart';

/// Database holding the neon data.
final class NeonDataDB extends MultiTableDatabase {
/// Creates a new database with the given [tables].
factory NeonDataDB({
Iterable<Table>? tables,
}) {
return NeonDataDB._(
tables: [
...?tables,
SQLiteCachedPersistence.table,
],
);
}

NeonDataDB._({
required super.tables,
});

@override
String get name => 'preferences';

@override
Future<String> get path async {
final cacheDir = await getApplicationSupportDirectory();

return buildDatabasePath(cacheDir.path, name);
}
}
Loading

0 comments on commit 40478d6

Please sign in to comment.