Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Saving files in custom data dir not working #1442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Needed for reading files opened with the app -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />


<!-- Install update APKs -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Expand Down
6 changes: 5 additions & 1 deletion lib/components/settings/settings_directory_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:saber/data/file_manager/file_manager.dart';
import 'package:saber/data/nextcloud/saber_syncer.dart';
import 'package:saber/data/prefs.dart';
import 'package:saber/i18n/strings.g.dart';
import 'package:saber/main_common.dart';

class SettingsDirectorySelector extends StatelessWidget {
const SettingsDirectorySelector({
Expand Down Expand Up @@ -114,7 +115,7 @@ class _DirectorySelectorState extends State<DirectorySelector> {

final dir = Directory(directory);
_directory = directory;
_isEmpty = dir.existsSync() ? dir.listSync().isEmpty : true;
_isEmpty = (dir.existsSync() ? dir.listSync().isEmpty : true) || true;

if (!mounted) return;
setState(() {});
Expand All @@ -123,6 +124,9 @@ class _DirectorySelectorState extends State<DirectorySelector> {
void _onConfirm() {
Prefs.customDataDir.value = _directory;
context.pop();
if (Platform.isAndroid) {
requestStoragePermission();
}
}

@override
Expand Down
14 changes: 13 additions & 1 deletion lib/main_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
import 'package:window_manager/window_manager.dart';
import 'package:worker_manager/worker_manager.dart';
import 'package:workmanager/workmanager.dart';
import 'package:permission_handler/permission_handler.dart';

Check notice on line 31 in lib/main_common.dart

View workflow job for this annotation

GitHub Actions / Run Flutter tests

Sort directive sections alphabetically.

Try sorting the directives. See https://dart.dev/lints/directives_ordering to learn more about this problem.

Future<void> requestStoragePermission() async {
final status = await Permission.manageExternalStorage.request();
if (status.isGranted) {
// Permission is granted
} else if (status.isDenied) {
// Permission is denied
} else if (status.isPermanentlyDenied) {
// Permission is permanently denied
openAppSettings(); // Open app settings to manually grant permission
}
}

Future<void> main(
List<String> args, {
Expand All @@ -36,7 +49,6 @@
void Function(Widget) runApp = runApp,
}) async {
initWidgetsBinding();

final parser = ArgParser()..addFlag('verbose', abbr: 'v', negatable: false);
final parsedArgs = parser.parse(args);

Expand Down