From 513d9e19d85587ccaccf11a804f4fde3531f8220 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Sat, 17 Aug 2024 13:05:21 +0200 Subject: [PATCH] Improve file system --- app/lib/cubits/current_index.dart | 36 +++++++++++++++---------------- app/lib/views/app_bar.dart | 6 ++++-- app/lib/views/files/view.dart | 7 +++--- app/pubspec.lock | 20 ++++++++--------- app/pubspec.yaml | 2 +- metadata/en-US/changelogs/111.txt | 2 ++ 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/app/lib/cubits/current_index.dart b/app/lib/cubits/current_index.dart index 1b72cd57a278..4d7531ae595a 100644 --- a/app/lib/cubits/current_index.dart +++ b/app/lib/cubits/current_index.dart @@ -871,26 +871,26 @@ class CurrentIndexCubit extends Cubit { emit(state.copyWith(currentlySaving: true)); final storage = getRemoteStorage(); final fileSystem = blocState.fileSystem.buildDocumentSystem(storage); - while (state.saved == SaveState.unsaved) { - emit(state.copyWith( - saved: SaveState.saving, location: location ?? state.location)); - location ??= state.location; - final currentData = blocState.saveData(); - if (currentData == null) return AssetLocation.empty; - if (blocState.embedding != null) return AssetLocation.empty; - if (!location.path.endsWith('.bfly') || - state.absolute || - location.fileType != AssetFileType.note) { - final document = - await fileSystem.createFile(currentData.name ?? '', currentData); - if (document == null) return AssetLocation.empty; - location = document.location; - } else { - await fileSystem.updateFile(location.path, currentData); - } - state.settingsCubit.addRecentHistory(location); + while (state.saved == SaveState.saving) {} + if (state.saved == SaveState.saved) { + return state.location; } + emit(state.copyWith( + saved: SaveState.saving, location: location ?? state.location)); location ??= state.location; + final currentData = blocState.saveData(); + if (currentData == null) return AssetLocation.empty; + if (blocState.embedding != null) return AssetLocation.empty; + if (!location.path.endsWith('.bfly') || + state.absolute || + location.fileType != AssetFileType.note) { + final document = await fileSystem.createFileWithName( + name: currentData.name, fileExtension: '.bfly', currentData); + location = document.location; + } else { + await fileSystem.updateFile(location.path, currentData); + } + state.settingsCubit.addRecentHistory(location); emit(state.copyWith( location: location, saved: SaveState.saved, currentlySaving: false)); return location; diff --git a/app/lib/views/app_bar.dart b/app/lib/views/app_bar.dart index 4d9d98c06213..e5abff492ba9 100644 --- a/app/lib/views/app_bar.dart +++ b/app/lib/views/app_bar.dart @@ -184,8 +184,10 @@ class _AppBarTitle extends StatelessWidget { .removeRecentHistory(location); if (state is DocumentLoadSuccess) { await state.save(location.copyWith( - path: - '${location.parent}/${documentSystem.convertNameToFile(value)}.bfly', + path: documentSystem.convertNameToFile( + name: value, + fileExtension: '.bfly', + directory: location.parent), )); } bloc.add(DocumentDescriptionChanged(name: value)); diff --git a/app/lib/views/files/view.dart b/app/lib/views/files/view.dart index 276087a22a8c..1a990874c76e 100644 --- a/app/lib/views/files/view.dart +++ b/app/lib/views/files/view.dart @@ -108,9 +108,10 @@ class FilesViewState extends State { ); if (name == null) return; final path = _locationController.text; - final newPath = '$path/${_documentSystem.convertNameToFile(name)}.bfly'; - await _documentSystem.updateFile( - newPath, + await _documentSystem.createFileWithName( + directory: path, + name: name, + fileExtension: '.bfly', template.createDocument( name: name, )); diff --git a/app/pubspec.lock b/app/pubspec.lock index 6cf4a5baf7a0..49ce27dd3c11 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -297,10 +297,10 @@ packages: dependency: transitive description: name: crypto - sha256: "1dceb0cf05cb63a7852c11560060e53ec2f182079a16ced6f4395c5b0875baf8" + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 url: "https://pub.dev" source: hosted - version: "3.0.4" + version: "3.0.5" csslib: dependency: transitive description: @@ -823,8 +823,8 @@ packages: dependency: "direct main" description: path: "packages/lw_file_system" - ref: "3c975be33c84052c1b96f8646ad7ea2270bb9d34" - resolved-ref: "3c975be33c84052c1b96f8646ad7ea2270bb9d34" + ref: ebc79d7cf461d852cefeb976d2088cca9f7f4702 + resolved-ref: ebc79d7cf461d852cefeb976d2088cca9f7f4702 url: "https://github.com/LinwoodDev/dart_pkgs.git" source: git version: "1.0.0" @@ -1206,10 +1206,10 @@ packages: dependency: "direct main" description: name: share_plus - sha256: "38658034f9f3c29f3b37ab0068db15caea9df2dd70d83e99300991a0d756c2a6" + sha256: "468c43f285207c84bcabf5737f33b914ceb8eb38398b91e5e3ad1698d1b72a52" url: "https://pub.dev" source: hosted - version: "10.0.1" + version: "10.0.2" share_plus_platform_interface: dependency: transitive description: @@ -1222,10 +1222,10 @@ packages: dependency: "direct main" description: name: shared_preferences - sha256: c272f9cabca5a81adc9b0894381e9c1def363e980f960fa903c604c471b22f68 + sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" shared_preferences_android: dependency: transitive description: @@ -1387,10 +1387,10 @@ packages: dependency: transitive description: name: synchronized - sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" + sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255 url: "https://pub.dev" source: hosted - version: "3.1.0+1" + version: "3.2.0" term_glyph: dependency: transitive description: diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 79ca5af456ff..926ebfab1a9e 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -91,7 +91,7 @@ dependencies: lw_file_system: git: url: https://github.com/LinwoodDev/dart_pkgs.git - ref: 3c975be33c84052c1b96f8646ad7ea2270bb9d34 + ref: ebc79d7cf461d852cefeb976d2088cca9f7f4702 path: packages/lw_file_system flutter_localized_locales: ^2.0.5 dynamic_color: ^1.7.0 diff --git a/metadata/en-US/changelogs/111.txt b/metadata/en-US/changelogs/111.txt index 2d343de8ff62..bb2a48c24114 100644 --- a/metadata/en-US/changelogs/111.txt +++ b/metadata/en-US/changelogs/111.txt @@ -1,4 +1,6 @@ * Add wasm support for chromium based browsers +* Use date for default file name +* Fix unnamed files gets duplicated on save * Upgrade to flutter 3.24 Read more here: https://linwood.dev/butterfly/2.2.0-beta.2 \ No newline at end of file