Browse Source

refactor(neon,neon_files): Use application cache directory from path provider

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/665/head
jld3103 1 year ago
parent
commit
55f268124b
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 6
      packages/neon/neon/lib/src/platform/android.dart
  2. 7
      packages/neon/neon/lib/src/platform/linux.dart
  3. 2
      packages/neon/neon/lib/src/platform/platform.dart
  4. 8
      packages/neon/neon/lib/src/utils/request_manager.dart
  5. 1
      packages/neon/neon/pubspec.yaml
  6. 10
      packages/neon/neon_files/lib/blocs/files.dart
  7. 1
      packages/neon/neon_files/lib/neon_files.dart
  8. 1
      packages/neon/neon_files/pubspec.yaml

6
packages/neon/neon/lib/src/platform/android.dart

@ -28,12 +28,6 @@ class AndroidNeonPlatform implements NeonPlatform {
@override @override
bool get canUseWindowManager => false; bool get canUseWindowManager => false;
@override
Future<String> get applicationCachePath async {
final tempDir = await getTemporaryDirectory();
return tempDir.absolute.path;
}
@override @override
Future<String> get userAccessibleAppDataPath async { Future<String> get userAccessibleAppDataPath async {
if (!await Permission.storage.request().isGranted) { if (!await Permission.storage.request().isGranted) {

7
packages/neon/neon/lib/src/platform/linux.dart

@ -4,7 +4,6 @@ import 'package:meta/meta.dart';
import 'package:neon/src/platform/platform.dart'; import 'package:neon/src/platform/platform.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:xdg_directories/xdg_directories.dart' as xdg;
@immutable @immutable
@internal @internal
@ -29,12 +28,6 @@ class LinuxNeonPlatform implements NeonPlatform {
@override @override
bool get canUsePushNotifications => false; bool get canUsePushNotifications => false;
@override
String get applicationCachePath => p.join(
xdg.cacheHome.absolute.path,
'de.provokateurin.neon',
);
@override @override
String get userAccessibleAppDataPath => p.join(Platform.environment['HOME']!, 'Neon'); String get userAccessibleAppDataPath => p.join(Platform.environment['HOME']!, 'Neon');

2
packages/neon/neon/lib/src/platform/platform.dart

@ -53,8 +53,6 @@ abstract interface class NeonPlatform {
abstract final bool canUsePushNotifications; abstract final bool canUsePushNotifications;
FutureOr<String> get applicationCachePath;
FutureOr<String> get userAccessibleAppDataPath; FutureOr<String> get userAccessibleAppDataPath;
FutureOr init(); FutureOr init();

8
packages/neon/neon/lib/src/utils/request_manager.dart

@ -3,9 +3,9 @@ import 'dart:convert';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:sqflite/sqflite.dart'; import 'package:sqflite/sqflite.dart';
import 'package:xml/xml.dart' as xml; import 'package:xml/xml.dart' as xml;
@ -194,11 +194,9 @@ class Cache {
return; return;
} }
final cacheDir = await getApplicationCacheDirectory();
_database = await openDatabase( _database = await openDatabase(
p.join( p.join(cacheDir.path, 'cache.db'),
await NeonPlatform.instance.applicationCachePath,
'cache.db',
),
version: 1, version: 1,
onCreate: (final db, final version) async { onCreate: (final db, final version) async {
await db.execute('CREATE TABLE cache (id INTEGER PRIMARY KEY, key TEXT, value TEXT, UNIQUE(key))'); await db.execute('CREATE TABLE cache (id INTEGER PRIMARY KEY, key TEXT, value TEXT, UNIQUE(key))');

1
packages/neon/neon/pubspec.yaml

@ -54,7 +54,6 @@ dependencies:
url_launcher: ^6.1.12 url_launcher: ^6.1.12
vector_graphics: ^1.1.7 vector_graphics: ^1.1.7
window_manager: ^0.3.6 window_manager: ^0.3.6
xdg_directories: ^1.0.2
xml: ^6.3.0 xml: ^6.3.0
dev_dependencies: dev_dependencies:

10
packages/neon/neon_files/lib/blocs/files.dart

@ -82,14 +82,8 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta
void openFile(final List<String> path, final String etag, final String? mimeType) { void openFile(final List<String> path, final String etag, final String? mimeType) {
wrapAction( wrapAction(
() async { () async {
final file = File( final cacheDir = await getApplicationCacheDirectory();
p.join( final file = File(p.join(cacheDir.path, 'files', etag.replaceAll('"', ''), path.last));
await NeonPlatform.instance.applicationCachePath,
'files',
etag.replaceAll('"', ''),
path.last,
),
);
if (!file.existsSync()) { if (!file.existsSync()) {
debugPrint('Downloading ${path.join('/')} since it does not exist'); debugPrint('Downloading ${path.join('/')} since it does not exist');
if (!file.parent.existsSync()) { if (!file.parent.existsSync()) {

1
packages/neon/neon_files/lib/neon_files.dart

@ -25,6 +25,7 @@ import 'package:neon_files/routes.dart';
import 'package:neon_files/widgets/file_list_tile.dart'; import 'package:neon_files/widgets/file_list_tile.dart';
import 'package:open_file/open_file.dart'; import 'package:open_file/open_file.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:queue/queue.dart'; import 'package:queue/queue.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';

1
packages/neon/neon_files/pubspec.yaml

@ -26,6 +26,7 @@ dependencies:
path: packages/neon/neon path: packages/neon/neon
open_file: ^3.3.2 open_file: ^3.3.2
path: ^1.8.3 path: ^1.8.3
path_provider: ^2.1.0
provider: ^6.0.5 provider: ^6.0.5
queue: ^3.1.0+2 queue: ^3.1.0+2
rxdart: ^0.27.7 rxdart: ^0.27.7

Loading…
Cancel
Save