mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-22 22:19:29 +02:00
Add "refresh before download" + remove WhatsApp (#1943)
This commit is contained in:
@@ -7,6 +7,9 @@ import 'package:obtainium/providers/apps_provider.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
|
||||
String ensureAbsoluteUrl(String ambiguousUrl, Uri referenceAbsoluteUrl) {
|
||||
if (ambiguousUrl.startsWith('//')) {
|
||||
ambiguousUrl = '${referenceAbsoluteUrl.scheme}:$ambiguousUrl';
|
||||
}
|
||||
try {
|
||||
Uri.parse(ambiguousUrl).origin;
|
||||
return ambiguousUrl;
|
||||
|
@@ -1,55 +0,0 @@
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:obtainium/custom_errors.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
|
||||
class WhatsApp extends AppSource {
|
||||
WhatsApp() {
|
||||
hosts = ['whatsapp.com'];
|
||||
versionDetectionDisallowed = true;
|
||||
}
|
||||
|
||||
@override
|
||||
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
|
||||
return 'https://${hosts[0]}';
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> apkUrlPrefetchModifier(String apkUrl, String standardUrl,
|
||||
Map<String, dynamic> additionalSettings) async {
|
||||
Response res =
|
||||
await sourceRequest('$standardUrl/android', additionalSettings);
|
||||
if (res.statusCode == 200) {
|
||||
var targetLinks = parse(res.body)
|
||||
.querySelectorAll('a')
|
||||
.map((e) => e.attributes['href'] ?? '')
|
||||
.where((e) => e.isNotEmpty)
|
||||
.where((e) => e.contains('WhatsApp.apk'))
|
||||
.toList();
|
||||
if (targetLinks.isEmpty) {
|
||||
throw NoAPKError();
|
||||
}
|
||||
return targetLinks[0];
|
||||
} else {
|
||||
throw getObtainiumHttpError(res);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<APKDetails> getLatestAPKDetails(
|
||||
String standardUrl,
|
||||
Map<String, dynamic> additionalSettings,
|
||||
) async {
|
||||
// This is a CDN link that is consistent per version
|
||||
// But it has query params that change constantly
|
||||
Uri apkUri = Uri.parse(await apkUrlPrefetchModifier(
|
||||
standardUrl, standardUrl, additionalSettings));
|
||||
var unusableApkUrl = '${apkUri.origin}/${apkUri.path}';
|
||||
// So we use the param-less URL is a pseudo-version to add the app and check for updates
|
||||
// See #357 for why we can't scrape the version number directly
|
||||
// But we re-fetch the URL again with its latest query params at the actual download time
|
||||
String version = unusableApkUrl.hashCode.toString();
|
||||
return APKDetails(version, getApkUrlsFromUrls([unusableApkUrl]),
|
||||
AppNames('Meta', 'WhatsApp'));
|
||||
}
|
||||
}
|
@@ -888,6 +888,11 @@ class AppsProvider with ChangeNotifier {
|
||||
}
|
||||
MapEntry<String, String>? apkUrl;
|
||||
var trackOnly = apps[id]!.app.additionalSettings['trackOnly'] == true;
|
||||
var refreshBeforeDownload =
|
||||
apps[id]!.app.additionalSettings['refreshBeforeDownload'] == true;
|
||||
if (refreshBeforeDownload) {
|
||||
await checkUpdate(apps[id]!.app.id);
|
||||
}
|
||||
if (!trackOnly) {
|
||||
// ignore: use_build_context_synchronously
|
||||
apkUrl = await confirmAppFileUrl(apps[id]!.app, context, false);
|
||||
@@ -1074,6 +1079,11 @@ class AppsProvider with ChangeNotifier {
|
||||
throw ObtainiumError(tr('appNotFound'));
|
||||
}
|
||||
MapEntry<String, String>? fileUrl;
|
||||
var refreshBeforeDownload =
|
||||
apps[id]!.app.additionalSettings['refreshBeforeDownload'] == true;
|
||||
if (refreshBeforeDownload) {
|
||||
await checkUpdate(apps[id]!.app.id);
|
||||
}
|
||||
if (apps[id]!.app.apkUrls.isNotEmpty ||
|
||||
apps[id]!.app.otherAssetUrls.isNotEmpty) {
|
||||
// ignore: use_build_context_synchronously
|
||||
|
@@ -29,7 +29,6 @@ import 'package:obtainium/app_sources/telegramapp.dart';
|
||||
import 'package:obtainium/app_sources/tencent.dart';
|
||||
import 'package:obtainium/app_sources/uptodown.dart';
|
||||
import 'package:obtainium/app_sources/vlc.dart';
|
||||
import 'package:obtainium/app_sources/whatsapp.dart';
|
||||
import 'package:obtainium/components/generated_form.dart';
|
||||
import 'package:obtainium/custom_errors.dart';
|
||||
import 'package:obtainium/mass_app_sources/githubstars.dart';
|
||||
@@ -214,6 +213,21 @@ appJSONCompatibilityModifiers(Map<String, dynamic> json) {
|
||||
'\\d+.\\d+.\\d+';
|
||||
additionalSettings = replacementAdditionalSettings;
|
||||
}
|
||||
// WhatsApp from before it was removed should be converted to HTML (#1943)
|
||||
if (json['url'] == 'https://whatsapp.com' &&
|
||||
json['id'] == 'com.whatsapp' &&
|
||||
json['author'] == 'Meta' &&
|
||||
json['name'] == 'WhatsApp' &&
|
||||
json['overrideSource'] == null &&
|
||||
additionalSettings['trackOnly'] == false &&
|
||||
additionalSettings['versionExtractionRegEx'] == '' &&
|
||||
json['lastUpdateCheck'] != null) {
|
||||
json['url'] = 'https://whatsapp.com/android';
|
||||
var replacementAdditionalSettings = getDefaultValuesFromFormItems(
|
||||
HTML().combinedAppSpecificSettingFormItems);
|
||||
replacementAdditionalSettings['refreshBeforeDownload'] = true;
|
||||
additionalSettings = replacementAdditionalSettings;
|
||||
}
|
||||
}
|
||||
json['additionalSettings'] = jsonEncode(additionalSettings);
|
||||
// F-Droid no longer needs cloudflare exception since override can be used - migrate apps appropriately
|
||||
@@ -586,6 +600,10 @@ abstract class AppSource {
|
||||
label: tr('skipUpdateNotifications'))
|
||||
],
|
||||
[GeneratedFormTextField('about', label: tr('about'), required: false)],
|
||||
[
|
||||
GeneratedFormSwitch('refreshBeforeDownload',
|
||||
label: tr('refreshBeforeDownload'))
|
||||
]
|
||||
];
|
||||
|
||||
// Previous 2 variables combined into one at runtime for convenient usage
|
||||
@@ -809,7 +827,6 @@ class SourceProvider {
|
||||
Jenkins(),
|
||||
APKMirror(),
|
||||
VLC(),
|
||||
WhatsApp(),
|
||||
TelegramApp(),
|
||||
NeutronCode(),
|
||||
DirectAPKLink(),
|
||||
|
Reference in New Issue
Block a user