Make Third Party F-Droid Repos Searchable (#995)

This commit is contained in:
Imran Remtulla
2023-10-14 01:29:02 -04:00
parent 7f3e87767c
commit aa8d45e636
4 changed files with 95 additions and 15 deletions

View File

@@ -267,10 +267,10 @@ class AppsProvider with ChangeNotifier {
File downloadedFile, String downloadUrl) async {
// If the APK package ID is different from the App ID, it is either new (using a placeholder ID) or the ID has changed
// The former case should be handled (give the App its real ID), the latter is a security issue
var isTempId = SourceProvider().isTempId(app);
var isTempIdBool = isTempId(app);
if (newInfo != null) {
if (app.id != newInfo.packageName) {
if (apps[app.id] != null && !isTempId && !app.allowIdChange) {
if (apps[app.id] != null && !isTempIdBool && !app.allowIdChange) {
throw IDChangedError(newInfo.packageName!);
}
var idChangeWasAllowed = app.allowIdChange;
@@ -281,10 +281,10 @@ class AppsProvider with ChangeNotifier {
'${downloadedFile.parent.path}/${app.id}-${downloadUrl.hashCode}.${downloadedFile.path.split('.').last}');
if (apps[originalAppId] != null) {
await removeApps([originalAppId]);
await saveApps([app], onlyIfExists: !isTempId && !idChangeWasAllowed);
await saveApps([app], onlyIfExists: !isTempIdBool && !idChangeWasAllowed);
}
}
} else if (isTempId) {
} else if (isTempIdBool) {
throw ObtainiumError('Could not get ID from APK');
}
return downloadedFile;

View File

@@ -372,6 +372,10 @@ abstract class AppSource {
return null;
}
App endOfGetAppChanges(App app) {
return app;
}
Future<Response> sourceRequest(String url,
{bool followRedirects = true,
Map<String, dynamic> additionalSettings =
@@ -541,6 +545,11 @@ intValidator(String? value, {bool positive = false}) {
return null;
}
bool isTempId(App app) {
// return app.id == generateTempID(app.url, app.additionalSettings);
return RegExp('^[0-9]+\$').hasMatch(app.id);
}
class SourceProvider {
// Add more source classes here so they are available via the service
List<AppSource> get sources => [
@@ -626,11 +635,6 @@ class SourceProvider {
String standardUrl, Map<String, dynamic> additionalSettings) =>
(standardUrl + additionalSettings.toString()).hashCode.toString();
bool isTempId(App app) {
// return app.id == generateTempID(app.url, app.additionalSettings);
return RegExp('^[0-9]+\$').hasMatch(app.id);
}
Future<App> getApp(
AppSource source, String url, Map<String, dynamic> additionalSettings,
{App? currentApp,
@@ -672,7 +676,7 @@ class SourceProvider {
String apkVersion = apk.version.replaceAll('/', '-');
var name = currentApp != null ? currentApp.name.trim() : '';
name = name.isNotEmpty ? name : apk.names.name;
return App(
App finalApp = App(
currentApp?.id ??
((!source.appIdInferIsOptional ||
(source.appIdInferIsOptional && inferAppIdIfOptional))
@@ -698,6 +702,7 @@ class SourceProvider {
source.appIdInferIsOptional &&
inferAppIdIfOptional // Optional ID inferring may be incorrect - allow correction on first install
);
return source.endOfGetAppChanges(finalApp);
}
// Returns errors in [results, errors] instead of throwing them