From 6d5126162be15cb62b31d2a97b1273ed528ea3a2 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Tue, 23 Aug 2022 16:12:37 -0400 Subject: [PATCH] Fixed version extraction + re-added background wait --- lib/services/apps_provider.dart | 13 +++++++++++++ lib/services/source_service.dart | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/services/apps_provider.dart b/lib/services/apps_provider.dart index 0cb49da..9c4a00b 100644 --- a/lib/services/apps_provider.dart +++ b/lib/services/apps_provider.dart @@ -97,6 +97,19 @@ class AppsProvider with ChangeNotifier { throw response.reasonPhrase ?? 'Unknown Error'; } + if (!isForeground) { + await notify( + 1, + 'Complete App Installation', + 'Obtainium must be open to install Apps', + 'COMPLETE_INSTALL', + 'Complete App Installation', + 'Asks the user to return to Obtanium to finish installing an App'); + while (await FGBGEvents.stream.first != FGBGType.foreground) { + // We need to wait for the App to come to the foreground since the APK installer doesn't work otherwise + } + } + // 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 diff --git a/lib/services/source_service.dart b/lib/services/source_service.dart index 7c1dce2..a70357e 100644 --- a/lib/services/source_service.dart +++ b/lib/services/source_service.dart @@ -1,7 +1,6 @@ // Exposes functions related to interacting with App sources and retrieving App info // Stateless - not a provider -import 'dart:convert'; import 'package:http/http.dart'; import 'package:html/parser.dart'; @@ -25,7 +24,7 @@ class APKDetails { abstract class AppSource { String standardizeURL(String url); - Future getLatestAPKUrl(String standardUrl); + Future getLatestAPKDetails(String standardUrl); AppNames getAppNames(String standardUrl); } @@ -95,7 +94,7 @@ class GitHub implements AppSource { } @override - Future getLatestAPKUrl(String standardUrl) async { + Future getLatestAPKDetails(String standardUrl) async { Response res = await get(Uri.parse('$standardUrl/releases/latest')); if (res.statusCode == 200) { var standardUri = Uri.parse(standardUrl); @@ -106,7 +105,11 @@ class GitHub implements AppSource { caseSensitive: false) .hasMatch(element.attributes['href']!); }).toList(); - String? version = parsedHtml.querySelector('h1')?.innerHtml; + String? version = parsedHtml + .querySelector('.octicon-tag') + ?.nextElementSibling + ?.innerHtml + .trim(); if (apkUrlList.isEmpty || version == null) { throw 'No APK found'; } @@ -143,7 +146,7 @@ class SourceService { AppSource source = getSource(url); String standardUrl = source.standardizeURL(url); AppNames names = source.getAppNames(standardUrl); - APKDetails apk = await source.getLatestAPKUrl(standardUrl); + APKDetails apk = await source.getLatestAPKDetails(standardUrl); return App( '${names.author}_${names.name}', standardUrl,