FINALLY FIXED AUTO UPDATE

This commit is contained in:
Kima 2023-09-04 23:13:54 +02:00
parent 8feea02f68
commit fceb4e050f
2 changed files with 5 additions and 9 deletions

@ -9,7 +9,7 @@ import 'package:permission_handler/permission_handler.dart';
class StorageHelper {
static Future<bool> write(String path, Uint8List data) async {
try {
if (await Permission.storage.request().isGranted) {
if (await Permission.manageExternalStorage.request().isGranted) {
await File(path).writeAsBytes(data);
return true;
} else {
@ -34,5 +34,6 @@ class StorageHelper {
}
return downloads;
// return (await getTemporaryDirectory()).path;
}
}

@ -25,14 +25,9 @@ extension UpdateHelper on Release {
if (!await apk.exists()) {
updateCallback(-1, UpdateState.downloading);
var storagePerms = await Permission.storage.request().isGranted;
if (storagePerms) {
var bytes = await download(updateCallback: updateCallback);
if (!await StorageHelper.write(apk.path, bytes)) {
throw "failed to write apk: permission denied";
}
} else {
throw storagePerms;
var bytes = await download(updateCallback: updateCallback);
if (!await StorageHelper.write(apk.path, bytes)) {
throw "failed to write apk: permission denied";
}
}