Skip to content

Commit

Permalink
fix: open the directory of saved image file on desktop platforms othe…
Browse files Browse the repository at this point in the history
…r than Windows
  • Loading branch information
EchoEllet committed Dec 3, 2024
1 parent 001ce56 commit fa09be7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
22 changes: 17 additions & 5 deletions flutter_quill_extensions/lib/src/editor/image/image_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart'
show ImageUrl, QuillController, StyleAttribute, getEmbedNode;
import 'package:flutter_quill/internal.dart';
import 'package:path/path.dart' as p;
import 'package:url_launcher/url_launcher.dart';

import '../../common/utils/element_utils/element_utils.dart';
Expand All @@ -22,7 +23,7 @@ class ImageOptionsMenu extends StatelessWidget {
required this.imageSize,
required this.readOnly,
required this.imageProvider,
this.prefersGallerySave = true,
this.prefersGallerySave = false,
super.key,
});

Expand Down Expand Up @@ -200,10 +201,21 @@ class ImageOptionsMenu extends StatelessWidget {
messenger.showSnackBar(
SnackBar(
content: Text(localizations.successImageSaved),
action: SnackBarAction(
label: localizations.openFileLocation,
onPressed: () => launchUrl(Uri.file(imageFilePath)),
),
// On macOS the app only has access to the picked file from the system save
// dialog and not the directory where it was saved.
// Opening the directory of that file requires entitlements on macOS
// See https://pub.dev/packages/url_launcher#macos-file-access-configuration
// Open the saved image file instead of the directory
action: defaultTargetPlatform == TargetPlatform.macOS
? SnackBarAction(
label: localizations.openFile,
onPressed: () => launchUrl(Uri.file(imageFilePath)),
)
: SnackBarAction(
label: localizations.openFileLocation,
onPressed: () => launchUrl(
Uri.directory(p.dirname(imageFilePath))),
),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ void main() {
find.text(localizations.openFileLocation),
findsNothing,
);
expect(
find.text(localizations.openFile),
findsNothing,
);
expect(
find.text(localizations.openGallery),
findsNothing,
Expand Down Expand Up @@ -214,7 +218,9 @@ void main() {
);

expect(
find.text(localizations.openFileLocation),
find.text(defaultTargetPlatform == TargetPlatform.macOS
? localizations.openFile
: localizations.openFileLocation),
findsOneWidget,
);

Expand Down

0 comments on commit fa09be7

Please sign in to comment.