Skip to content

Commit

Permalink
Improve file system
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Aug 17, 2024
1 parent 08b066a commit 513d9e1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
36 changes: 18 additions & 18 deletions app/lib/cubits/current_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -871,26 +871,26 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
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;
Expand Down
6 changes: 4 additions & 2 deletions app/lib/views/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 4 additions & 3 deletions app/lib/views/files/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ class FilesViewState extends State<FilesView> {
);
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,
));
Expand Down
20 changes: 10 additions & 10 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions metadata/en-US/changelogs/111.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 513d9e1

Please sign in to comment.