Skip to content

Commit 5821c60

Browse files
committed
fix: add macOS file picker entitlements
1 parent 164e4f4 commit 5821c60

5 files changed

Lines changed: 44 additions & 39 deletions

File tree

lib/core/file_picker_helper.dart

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,53 +24,32 @@ class FilePickerHelper {
2424
static bool _effectiveLockParentWindow(bool lockParentWindow) =>
2525
lockParentWindow || Platform.isWindows;
2626

27-
static Future<bool> _beforeDialog() async {
28-
if (!_isDesktop) return false;
29-
30-
var restoreMaximized = false;
31-
if (Platform.isMacOS && await windowManager.isMaximized()) {
32-
restoreMaximized = true;
33-
await windowManager.unmaximize();
34-
}
35-
36-
if (_shouldMinimizeDesktopWindow) {
37-
await windowManager.minimize();
38-
await Future.delayed(const Duration(milliseconds: 120));
39-
}
40-
41-
await windowManager.focus();
42-
return restoreMaximized;
27+
static Future<void> _beforeDialog() async {
28+
if (!_isDesktop || !_shouldMinimizeDesktopWindow) return;
29+
await windowManager.minimize();
30+
await Future.delayed(const Duration(milliseconds: 120));
4331
}
4432

45-
static Future<void> _afterDialog(bool restoreMaximized) async {
46-
if (!_isDesktop) return;
47-
48-
if (_shouldMinimizeDesktopWindow) {
49-
await windowManager.restore();
50-
await windowManager.maximize();
51-
await windowManager.focus();
52-
return;
53-
}
54-
55-
if (Platform.isMacOS && restoreMaximized) {
56-
await windowManager.maximize();
57-
await windowManager.focus();
58-
}
33+
static Future<void> _afterDialog() async {
34+
if (!_isDesktop || !_shouldMinimizeDesktopWindow) return;
35+
await windowManager.restore();
36+
await windowManager.maximize();
37+
await windowManager.focus();
5938
}
6039

6140
/// Replacement for [FilePicker.platform.getDirectoryPath].
6241
static Future<String?> getDirectoryPath({
6342
String? dialogTitle,
6443
bool lockParentWindow = false,
6544
}) async {
66-
final restoreMaximized = await _beforeDialog();
45+
await _beforeDialog();
6746
try {
6847
return await FilePicker.platform.getDirectoryPath(
6948
dialogTitle: dialogTitle,
7049
lockParentWindow: _effectiveLockParentWindow(lockParentWindow),
7150
);
7251
} finally {
73-
await _afterDialog(restoreMaximized);
52+
await _afterDialog();
7453
}
7554
}
7655

@@ -83,7 +62,7 @@ class FilePickerHelper {
8362
bool withData = false,
8463
bool lockParentWindow = false,
8564
}) async {
86-
final restoreMaximized = await _beforeDialog();
65+
await _beforeDialog();
8766
try {
8867
return await FilePicker.platform.pickFiles(
8968
dialogTitle: dialogTitle,
@@ -94,7 +73,7 @@ class FilePickerHelper {
9473
lockParentWindow: _effectiveLockParentWindow(lockParentWindow),
9574
);
9675
} finally {
97-
await _afterDialog(restoreMaximized);
76+
await _afterDialog();
9877
}
9978
}
10079

@@ -106,7 +85,7 @@ class FilePickerHelper {
10685
List<String>? allowedExtensions,
10786
bool lockParentWindow = false,
10887
}) async {
109-
final restoreMaximized = await _beforeDialog();
88+
await _beforeDialog();
11089
try {
11190
return await FilePicker.platform.saveFile(
11291
dialogTitle: dialogTitle,
@@ -116,7 +95,7 @@ class FilePickerHelper {
11695
lockParentWindow: _effectiveLockParentWindow(lockParentWindow),
11796
);
11897
} finally {
119-
await _afterDialog(restoreMaximized);
98+
await _afterDialog();
12099
}
121100
}
122101
}

lib/ui/screens/welcome_screen.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ class WelcomeScreen extends ConsumerWidget {
115115
}
116116

117117
Future<void> _openLibrary(BuildContext context, WidgetRef ref) async {
118-
final dir = await FilePickerHelper.getDirectoryPath(
118+
final dir = await _pickLibraryDirectory(
119+
context,
119120
dialogTitle: 'Open MediaShelf Library',
120121
);
121122
if (dir == null || !context.mounted) return;
122123
await _openPath(context, ref, dir);
123124
}
124125

125126
Future<void> _createLibrary(BuildContext context, WidgetRef ref) async {
126-
final dir = await FilePickerHelper.getDirectoryPath(
127+
final dir = await _pickLibraryDirectory(
128+
context,
127129
dialogTitle: 'Choose Folder for New Library',
128130
);
129131
if (dir == null || !context.mounted) return;
@@ -143,6 +145,22 @@ class WelcomeScreen extends ConsumerWidget {
143145
}
144146
}
145147

148+
Future<String?> _pickLibraryDirectory(
149+
BuildContext context, {
150+
required String dialogTitle,
151+
}) async {
152+
try {
153+
return await FilePickerHelper.getDirectoryPath(dialogTitle: dialogTitle);
154+
} catch (e) {
155+
if (context.mounted) {
156+
ScaffoldMessenger.of(context).showSnackBar(
157+
SnackBar(content: Text('Could not open folder picker: $e')),
158+
);
159+
}
160+
return null;
161+
}
162+
}
163+
146164
Future<void> _openPath(
147165
BuildContext context,
148166
WidgetRef ref,

macos/Runner/DebugProfile.entitlements

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<true/>
77
<key>com.apple.security.cs.allow-jit</key>
88
<true/>
9+
<key>com.apple.security.files.user-selected.read-write</key>
10+
<true/>
11+
<key>com.apple.security.network.client</key>
12+
<true/>
913
<key>com.apple.security.network.server</key>
1014
<true/>
1115
</dict>

macos/Runner/Release.entitlements

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
<dict>
55
<key>com.apple.security.app-sandbox</key>
66
<true/>
7+
<key>com.apple.security.files.user-selected.read-write</key>
8+
<true/>
9+
<key>com.apple.security.network.client</key>
10+
<true/>
711
</dict>
812
</plist>

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: mediashelf
22
description: "MediaShelf — Cross-platform Digital Asset Manager"
33
publish_to: 'none'
4-
version: 0.5.6+6
4+
version: 0.5.6+7
55

66
environment:
77
sdk: ^3.11.1

0 commit comments

Comments
 (0)