Finished switch to new download/install process

This commit is contained in:
Imran Remtulla
2022-08-23 15:09:56 -04:00
parent c265cd01d9
commit b55fcafd95
4 changed files with 102 additions and 91 deletions

View File

@@ -72,7 +72,10 @@ class AppsProvider with ChangeNotifier {
StreamedResponse response =
await Client().send(Request('GET', Uri.parse(apps[appId]!.app.apkUrl)));
File downloadFile =
File('${(await getTemporaryDirectory()).path}/$appId.apk');
File('${(await getExternalStorageDirectory())!.path}/apks/$appId.apk');
if (downloadFile.existsSync()) {
downloadFile.deleteSync();
}
var length = response.contentLength;
var received = 0;
var sink = downloadFile.openWrite();
@@ -94,14 +97,13 @@ class AppsProvider with ChangeNotifier {
throw response.reasonPhrase ?? 'Unknown Error';
}
var res = await InstallPlugin.installApk(
downloadFile.path, 'dev.imranr.obtainium');
print(res);
// Unfortunately this 'await' does not actually wait for the APK to finish installing
// So we only know that the install prompt was shown, but the user could still cancel w/o us knowing
// This also does not use the 'session-based' installer API, so background/silent updates are impossible
await InstallPlugin.installApk(downloadFile.path, 'dev.imranr.obtainium');
apps[appId]!.app.installedVersion = apps[appId]!.app.latestVersion;
saveApp(apps[appId]!.app);
downloadFile.deleteSync();
}
Future<Directory> getAppsDir() async {