Compare commits

...

4 Commits

Author SHA1 Message Date
ba1cdc2c73 Increment version 2022-11-14 21:10:30 -05:00
aa2a25fffe Better GitHub error messages (#112) 2022-11-14 20:56:04 -05:00
c8ec67aef3 Existing APKs now reused again
With partial APKs avoided (#113)
2022-11-14 20:38:02 -05:00
9576a99a4e More efficient loading (addresses #110) 2022-11-14 12:56:52 -05:00
6 changed files with 68 additions and 62 deletions

View File

@ -167,14 +167,8 @@ class GitHub extends AppSource {
} }
return APKDetails(version, targetRelease['apkUrls']); return APKDetails(version, targetRelease['apkUrls']);
} else { } else {
if (res.headers['x-ratelimit-remaining'] == '0') { rateLimitErrorCheck(res);
throw RateLimitError( throw getObtainiumHttpError(res);
(int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') /
60000000)
.round());
}
throw NoReleasesError();
} }
} }
@ -200,15 +194,17 @@ class GitHub extends AppSource {
} }
return urlsWithDescriptions; return urlsWithDescriptions;
} else { } else {
rateLimitErrorCheck(res);
throw getObtainiumHttpError(res);
}
}
rateLimitErrorCheck(Response res) {
if (res.headers['x-ratelimit-remaining'] == '0') { if (res.headers['x-ratelimit-remaining'] == '0') {
throw RateLimitError( throw RateLimitError(
(int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') / (int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') /
60000000) 60000000)
.round()); .round());
} }
throw ObtainiumError(
res.reasonPhrase ?? 'Error ${res.statusCode.toString()}',
unexpected: true);
}
} }
} }

View File

@ -16,7 +16,7 @@ import 'package:dynamic_color/dynamic_color.dart';
import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus/device_info_plus.dart';
import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart'; import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
const String currentVersion = '0.7.2'; const String currentVersion = '0.7.3';
const String currentReleaseTag = const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES 'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES

View File

@ -27,14 +27,9 @@ class GitHubStars implements MassAppUrlSource {
} }
return urlsWithDescriptions; return urlsWithDescriptions;
} else { } else {
if (res.headers['x-ratelimit-remaining'] == '0') { var gh = GitHub();
throw RateLimitError( gh.rateLimitErrorCheck(res);
(int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') / throw getObtainiumHttpError(res);
60000000)
.round());
}
throw ObtainiumError('Unable to find user\'s starred repos');
} }
} }

View File

@ -65,7 +65,9 @@ class AppsProvider with ChangeNotifier {
// Delete existing APKs // Delete existing APKs
(await getExternalStorageDirectory()) (await getExternalStorageDirectory())
?.listSync() ?.listSync()
.where((element) => element.path.endsWith('.apk')) .where((element) =>
element.path.endsWith('.apk') ||
element.path.endsWith('.apk.part'))
.forEach((apk) { .forEach((apk) {
apk.delete(); apk.delete();
}); });
@ -73,20 +75,21 @@ class AppsProvider with ChangeNotifier {
} }
} }
downloadFile(String url, String fileName, Function? onProgress) async { downloadFile(String url, String fileName, Function? onProgress,
{bool useExisting = true}) async {
var destDir = (await getExternalStorageDirectory())!.path; var destDir = (await getExternalStorageDirectory())!.path;
StreamedResponse response = StreamedResponse response =
await Client().send(Request('GET', Uri.parse(url))); await Client().send(Request('GET', Uri.parse(url)));
File downloadedFile = File('$destDir/$fileName'); File downloadedFile = File('$destDir/$fileName');
if (!(downloadedFile.existsSync() && useExisting)) {
if (downloadedFile.existsSync()) { File tempDownloadedFile = File('${downloadedFile.path}.part');
downloadedFile.deleteSync(); if (tempDownloadedFile.existsSync()) {
tempDownloadedFile.deleteSync();
} }
var length = response.contentLength; var length = response.contentLength;
var received = 0; var received = 0;
double? progress; double? progress;
var sink = downloadedFile.openWrite(); var sink = tempDownloadedFile.openWrite();
await response.stream.map((s) { await response.stream.map((s) {
received += s.length; received += s.length;
progress = (length != null ? received / length * 100 : 30); progress = (length != null ? received / length * 100 : 30);
@ -95,17 +98,17 @@ class AppsProvider with ChangeNotifier {
} }
return s; return s;
}).pipe(sink); }).pipe(sink);
await sink.close(); await sink.close();
progress = null; progress = null;
if (onProgress != null) { if (onProgress != null) {
onProgress(progress); onProgress(progress);
} }
if (response.statusCode != 200) { if (response.statusCode != 200) {
downloadedFile.deleteSync(); tempDownloadedFile.deleteSync();
throw response.reasonPhrase ?? 'Unknown Error'; throw response.reasonPhrase ?? 'Unknown Error';
} }
tempDownloadedFile.renameSync(downloadedFile.path);
}
return downloadedFile; return downloadedFile;
} }
@ -424,22 +427,28 @@ class AppsProvider with ChangeNotifier {
} }
loadingApps = true; loadingApps = true;
notifyListeners(); notifyListeners();
List<FileSystemEntity> appFiles = (await getAppsDir()) List<App> newApps = (await getAppsDir())
.listSync() .listSync()
.where((item) => item.path.toLowerCase().endsWith('.json')) .where((item) => item.path.toLowerCase().endsWith('.json'))
.map((e) => App.fromJson(jsonDecode(File(e.path).readAsStringSync())))
.toList(); .toList();
apps.clear(); var idsToDelete = apps.values
.map((e) => e.app.id)
.toSet()
.difference(newApps.map((e) => e.id).toSet());
for (var id in idsToDelete) {
apps.remove(id);
}
var sp = SourceProvider(); var sp = SourceProvider();
List<List<String>> errors = []; List<List<String>> errors = [];
for (int i = 0; i < appFiles.length; i++) { for (int i = 0; i < newApps.length; i++) {
App app = var info = await getInstalledInfo(newApps[i].id);
App.fromJson(jsonDecode(File(appFiles[i].path).readAsStringSync()));
var info = await getInstalledInfo(app.id);
try { try {
sp.getSource(app.url); sp.getSource(newApps[i].url);
apps.putIfAbsent(app.id, () => AppInMemory(app, null, info)); apps.putIfAbsent(
newApps[i].id, () => AppInMemory(newApps[i], null, info));
} catch (e) { } catch (e) {
errors.add([app.id, app.name, e.toString()]); errors.add([newApps[i].id, newApps[i].name, e.toString()]);
} }
} }
if (errors.isNotEmpty) { if (errors.isNotEmpty) {

View File

@ -4,6 +4,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:html/dom.dart'; import 'package:html/dom.dart';
import 'package:http/http.dart';
import 'package:obtainium/app_sources/fdroid.dart'; import 'package:obtainium/app_sources/fdroid.dart';
import 'package:obtainium/app_sources/github.dart'; import 'package:obtainium/app_sources/github.dart';
import 'package:obtainium/app_sources/gitlab.dart'; import 'package:obtainium/app_sources/gitlab.dart';
@ -164,6 +165,11 @@ class AppSource {
} }
} }
ObtainiumError getObtainiumHttpError(Response res) {
return ObtainiumError(
res.reasonPhrase ?? 'Error ${res.statusCode.toString()}');
}
abstract class MassAppUrlSource { abstract class MassAppUrlSource {
late String name; late String name;
late List<String> requiredArgs; late List<String> requiredArgs;

View File

@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 0.7.2+58 # When changing this, update the tag in main() accordingly version: 0.7.3+59 # When changing this, update the tag in main() accordingly
environment: environment:
sdk: '>=2.18.2 <3.0.0' sdk: '>=2.18.2 <3.0.0'