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 15dea3e
Show file tree
Hide file tree
Showing 42 changed files with 249 additions and 1,477 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
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);
}
}
67 changes: 0 additions & 67 deletions packages/neon_framework/lib/src/storage/persistence.dart

This file was deleted.

Loading

0 comments on commit 15dea3e

Please sign in to comment.