mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
fix: Handle selecting files and folders for patch options correctly (#1941)
This commit is contained in:
parent
3c36950aeb
commit
b26760b216
3 changed files with 54 additions and 23 deletions
|
@ -38,6 +38,8 @@ class ManagerAPI {
|
||||||
bool releaseBuild = false;
|
bool releaseBuild = false;
|
||||||
bool suggestedAppVersionSelected = true;
|
bool suggestedAppVersionSelected = true;
|
||||||
bool isDynamicThemeAvailable = false;
|
bool isDynamicThemeAvailable = false;
|
||||||
|
bool isScopedStorageAvailable = false;
|
||||||
|
int sdkVersion = 0;
|
||||||
String storedPatchesFile = '/selected-patches.json';
|
String storedPatchesFile = '/selected-patches.json';
|
||||||
String keystoreFile =
|
String keystoreFile =
|
||||||
'/sdcard/Android/data/app.revanced.manager.flutter/files/revanced-manager.keystore';
|
'/sdcard/Android/data/app.revanced.manager.flutter/files/revanced-manager.keystore';
|
||||||
|
@ -55,8 +57,13 @@ class ManagerAPI {
|
||||||
Future<void> initialize() async {
|
Future<void> initialize() async {
|
||||||
_prefs = await SharedPreferences.getInstance();
|
_prefs = await SharedPreferences.getInstance();
|
||||||
isRooted = await _rootAPI.isRooted();
|
isRooted = await _rootAPI.isRooted();
|
||||||
|
if (sdkVersion == 0) {
|
||||||
|
sdkVersion = await getSdkVersion();
|
||||||
|
}
|
||||||
isDynamicThemeAvailable =
|
isDynamicThemeAvailable =
|
||||||
(await getSdkVersion()) >= 31; // ANDROID_12_SDK_VERSION = 31
|
sdkVersion >= 31; // ANDROID_12_SDK_VERSION = 31
|
||||||
|
isScopedStorageAvailable =
|
||||||
|
sdkVersion >= 30; // ANDROID_11_SDK_VERSION = 30
|
||||||
storedPatchesFile =
|
storedPatchesFile =
|
||||||
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
|
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
|
||||||
if (kReleaseMode) {
|
if (kReleaseMode) {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:revanced_manager/app/app.locator.dart';
|
||||||
import 'package:revanced_manager/gen/strings.g.dart';
|
import 'package:revanced_manager/gen/strings.g.dart';
|
||||||
import 'package:revanced_manager/models/patch.dart';
|
import 'package:revanced_manager/models/patch.dart';
|
||||||
import 'package:revanced_manager/ui/views/patch_options/patch_options_viewmodel.dart';
|
import 'package:revanced_manager/services/manager_api.dart';
|
||||||
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
||||||
|
|
||||||
class BooleanPatchOption extends StatelessWidget {
|
class BooleanPatchOption extends StatelessWidget {
|
||||||
|
@ -398,6 +400,7 @@ class TextFieldForPatchOption extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
||||||
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
String? selectedKey;
|
String? selectedKey;
|
||||||
String? defaultValue;
|
String? defaultValue;
|
||||||
|
@ -524,29 +527,49 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
onSelected: (String selection) async {
|
onSelected: (String selection) async {
|
||||||
switch (selection) {
|
// manageExternalStorage permission is required for file/folder selection
|
||||||
case 'file':
|
// otherwise, the app will not complain, but the patches will error out
|
||||||
final String? result = await FlutterFileDialog.pickFile();
|
// the same way as if the user selected an empty file/folder.
|
||||||
if (result != null) {
|
// Android 11 and above requires the manageExternalStorage permission
|
||||||
controller.text = result;
|
final Map<String, dynamic> availableActions = {
|
||||||
widget.onChanged(controller.text);
|
t.patchOptionsView.selectFilePath: () async {
|
||||||
|
if (_managerAPI.isScopedStorageAvailable) {
|
||||||
|
final permission =
|
||||||
|
await Permission.manageExternalStorage.request();
|
||||||
|
if (!permission.isGranted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
final FilePickerResult? result =
|
||||||
case 'folder':
|
await FilePicker.platform.pickFiles();
|
||||||
final DirectoryLocation? result =
|
if (result == null) {
|
||||||
await FlutterFileDialog.pickDirectory();
|
return;
|
||||||
if (result != null) {
|
|
||||||
controller.text = result.toString();
|
|
||||||
widget.onChanged(controller.text);
|
|
||||||
}
|
}
|
||||||
break;
|
controller.text = result.files.single.path!;
|
||||||
case 'remove':
|
widget.onChanged(controller.text);
|
||||||
|
},
|
||||||
|
t.patchOptionsView.selectFolder: () async {
|
||||||
|
if (_managerAPI.isScopedStorageAvailable) {
|
||||||
|
final permission =
|
||||||
|
await Permission.manageExternalStorage.request();
|
||||||
|
if (!permission.isGranted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final String? result =
|
||||||
|
await FilePicker.platform.getDirectoryPath();
|
||||||
|
if (result == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controller.text = result;
|
||||||
|
widget.onChanged(controller.text);
|
||||||
|
},
|
||||||
|
t.remove: () {
|
||||||
widget.removeValue!();
|
widget.removeValue!();
|
||||||
break;
|
},
|
||||||
case 'null':
|
};
|
||||||
controller.text = '';
|
if (availableActions.containsKey(selection)) {
|
||||||
widget.onChanged(null);
|
await availableActions[selection]!();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -23,6 +23,7 @@ dependencies:
|
||||||
dynamic_color: ^1.7.0
|
dynamic_color: ^1.7.0
|
||||||
dynamic_themes: ^1.1.0
|
dynamic_themes: ^1.1.0
|
||||||
expandable: ^5.0.1
|
expandable: ^5.0.1
|
||||||
|
file_picker: ^8.0.3
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_background:
|
flutter_background:
|
||||||
|
|
Loading…
Reference in a new issue