Skip to content

Commit

Permalink
Remove restriction of bfly files on import in files view
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 17, 2023
1 parent d7a77d0 commit c9c514a
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 41 deletions.
12 changes: 8 additions & 4 deletions app/lib/api/open.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ Future<bool> openHelp(List<String> pageLocation, [String? fragment]) {
mode: LaunchMode.externalApplication);
}

Future<Uint8List?> openBfly() async {
Future<(Uint8List?, String?)> openSupported(
[List<String>? fileExtension]) async {
final isMobile = !kIsWeb && (Platform.isAndroid || Platform.isIOS);
final files = await FilePicker.platform.pickFiles(
type: isMobile ? FileType.any : FileType.custom,
allowedExtensions: isMobile ? null : ['bfly'],
allowedExtensions: isMobile
? null
: (fileExtension ??
AssetFileType.values.expand((e) => e.getFileExtensions()).toList()),
allowMultiple: false,
withData: true,
);
if (files?.files.isEmpty ?? true) return null;
if (files?.files.isEmpty ?? true) return (null, null);
var e = files!.files.first;
return e.bytes;
return (e.bytes, e.extension);
}

void openFile(BuildContext context, AssetLocation location, [Object? data]) {
Expand Down
27 changes: 12 additions & 15 deletions app/lib/dialogs/load.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

mixin LoadingDialogHandler {
void setProgress(double progress) {}
void close() {}
class LoadingDialogHandler {
final GlobalKey<_LoadingDialogState> _key;

const LoadingDialogHandler._(this._key);

void setProgress(double progress) => _key.currentState?.setProgress(progress);
void close() => _key.currentState?.close();
}

_LoadingDialogState? showLoadingDialog(BuildContext context) {
LoadingDialogHandler? showLoadingDialog(BuildContext context) {
final key = GlobalKey<_LoadingDialogState>();
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return LoadingDialog(key: key);
},
builder: (_) => LoadingDialog(key: key),
);
return key.currentState;
return LoadingDialogHandler._(key);
}

class LoadingDialog extends StatefulWidget {
Expand All @@ -25,19 +27,14 @@ class LoadingDialog extends StatefulWidget {
State<LoadingDialog> createState() => _LoadingDialogState();
}

class _LoadingDialogState extends State<LoadingDialog>
with LoadingDialogHandler {
class _LoadingDialogState extends State<LoadingDialog> {
double _progress = 0.0;

@override
void setProgress(double progress) => setState(() {
_progress = progress;
});

@override
void close() {
Navigator.of(context).pop();
}
void close() => Navigator.of(context).pop();

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/dialogs/packs/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class _PacksDialogState extends State<PacksDialog>
PhosphorIconsLight.arrowSquareIn),
onTap: () async {
Navigator.of(ctx).pop();
final data = await openBfly();
final (data, _) = await openSupported(['bfly']);
if (data == null) return;
final pack = NoteData.fromData(data);
final metadata = pack.getMetadata();
Expand Down
8 changes: 5 additions & 3 deletions app/lib/handlers/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ Future<void> showImportAssetWizard(ImportType type, BuildContext context,
allowedExtensions: ['pdf'],
);
case ImportType.document:
final data = await openBfly();
if (data == null) return;
return importAsset(AssetFileType.note, data);
return importWithDialog(
AssetFileType.note,
type: FileType.custom,
allowedExtensions: ['bfly'],
);
case ImportType.markdown:
return importWithDialog(
AssetFileType.markdown,
Expand Down
1 change: 0 additions & 1 deletion app/lib/handlers/handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import 'package:share_plus/share_plus.dart';

import '../actions/paste.dart';
import '../actions/select.dart';
import '../api/open.dart';
import '../api/save_data.dart';
import '../cubits/current_index.dart';
import '../dialogs/import/camera.dart';
Expand Down
1 change: 1 addition & 0 deletions app/lib/services/import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ class ImportService {
?..add(ElementsCreated(elements))
..add(AreasCreated(areas));
}
page = page.copyWith(content: [...page.content, ...elements]);
document = document.setPage(page);
return document;
}
Expand Down
16 changes: 7 additions & 9 deletions app/lib/views/files/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,13 @@ class _FilesViewState extends State<FilesView> {
onPressed: () async {
final router = GoRouter.of(context);
final importService = context.read<ImportService>();
final result = await openBfly();
final (result, extension) = await openSupported();
if (result == null) return;
final model = await importService.importBfly(result,
final model = await importService.import(
AssetFileTypeHelper.fromFileExtension(extension) ??
AssetFileType.note,
result,
DocumentDefaults.createDocument(),
advanced: false);
if (model == null) return;
const route = '/native?name=document.bfly&type=note';
Expand All @@ -316,13 +320,7 @@ class _FilesViewState extends State<FilesView> {
_reloadFileSystem();
}
},
child: Column(
children: [
Text(AppLocalizations.of(context).import),
Text('.bfly',
style: Theme.of(context).textTheme.bodySmall),
],
),
child: Text(AppLocalizations.of(context).import),
),
if (settings.flags.contains('collaboration'))
MenuItemButton(
Expand Down
12 changes: 5 additions & 7 deletions app/lib/visualizer/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import 'package:phosphor_flutter/phosphor_flutter.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

extension PathShapeVisualizer on PathShape {
IconGetter get icon {
return map(
circle: (_) => PhosphorIcons.circle,
rectangle: (_) => PhosphorIcons.square,
line: (_) => PhosphorIcons.lineSegment,
);
}
IconGetter get icon => map(
circle: (_) => PhosphorIcons.circle,
rectangle: (_) => PhosphorIcons.square,
line: (_) => PhosphorIcons.lineSegment,
);

String getLocalizedName(BuildContext context) {
final loc = AppLocalizations.of(context);
Expand Down
6 changes: 5 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/80.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Add experiments settings in nightly version
* Add collaboration support (experimental) using websockets
* Remove restriction of bfly files on import in files view
* Fix android mimetype
* Fix global importing

View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.15
View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.16

0 comments on commit c9c514a

Please sign in to comment.