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']);
} else {
if (res.headers['x-ratelimit-remaining'] == '0') {
throw RateLimitError(
(int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') /
60000000)
.round());
}
throw NoReleasesError();
rateLimitErrorCheck(res);
throw getObtainiumHttpError(res);
}
}
@ -200,15 +194,17 @@ class GitHub extends AppSource {
}
return urlsWithDescriptions;
} else {
rateLimitErrorCheck(res);
throw getObtainiumHttpError(res);
}
}
rateLimitErrorCheck(Response res) {
if (res.headers['x-ratelimit-remaining'] == '0') {
throw RateLimitError(
(int.parse(res.headers['x-ratelimit-reset'] ?? '1800000000') /
60000000)
.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:android_alarm_manager_plus/android_alarm_manager_plus.dart';
const String currentVersion = '0.7.2';
const String currentVersion = '0.7.3';
const String currentReleaseTag =
'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES

View File

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

View File

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

View File

@ -4,6 +4,7 @@
import 'dart:convert';
import 'package:html/dom.dart';
import 'package:http/http.dart';
import 'package:obtainium/app_sources/fdroid.dart';
import 'package:obtainium/app_sources/github.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 {
late String name;
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
# 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.
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:
sdk: '>=2.18.2 <3.0.0'