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
bool get canUseWindowManager => false;
@override
Future<String> get applicationCachePath async {
final tempDir = await getTemporaryDirectory();
return tempDir.absolute.path;
}
@override
Future<String> get userAccessibleAppDataPath async {
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:path/path.dart' as p;
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:xdg_directories/xdg_directories.dart' as xdg;
@immutable
@internal
@ -29,12 +28,6 @@ class LinuxNeonPlatform implements NeonPlatform {
@override
bool get canUsePushNotifications => false;
@override
String get applicationCachePath => p.join(
xdg.cacheHome.absolute.path,
'de.provokateurin.neon',
);
@override
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;
FutureOr<String> get applicationCachePath;
FutureOr<String> get userAccessibleAppDataPath;
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:meta/meta.dart';
import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:rxdart/rxdart.dart';
import 'package:sqflite/sqflite.dart';
import 'package:xml/xml.dart' as xml;
@ -194,11 +194,9 @@ class Cache {
return;
}
final cacheDir = await getApplicationCacheDirectory();
_database = await openDatabase(
p.join(
await NeonPlatform.instance.applicationCachePath,
'cache.db',
),
p.join(cacheDir.path, 'cache.db'),
version: 1,
onCreate: (final db, final version) async {
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
vector_graphics: ^1.1.7
window_manager: ^0.3.6
xdg_directories: ^1.0.2
xml: ^6.3.0
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) {
wrapAction(
() async {
final file = File(
p.join(
await NeonPlatform.instance.applicationCachePath,
'files',
etag.replaceAll('"', ''),
path.last,
),
);
final cacheDir = await getApplicationCacheDirectory();
final file = File(p.join(cacheDir.path, 'files', etag.replaceAll('"', ''), path.last));
if (!file.existsSync()) {
debugPrint('Downloading ${path.join('/')} since it does not exist');
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:open_file/open_file.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
import 'package:queue/queue.dart';
import 'package:rxdart/rxdart.dart';

1
packages/neon/neon_files/pubspec.yaml

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

Loading…
Cancel
Save