From a0d466a074fcc1eb64cbd1ad8f21d70065e3d237 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 27 May 2023 21:01:16 -0400 Subject: [PATCH] Add toggle for App ID inferring where optional --- assets/translations/de.json | 1 + assets/translations/en.json | 1 + assets/translations/es.json | 1 + assets/translations/fa.json | 1 + assets/translations/fr.json | 1 + assets/translations/hu.json | 1 + assets/translations/it.json | 1 + assets/translations/ja.json | 1 + assets/translations/zh.json | 1 + lib/app_sources/github.dart | 1 + lib/pages/add_app.dart | 22 +++++++++++++++++++++- lib/providers/source_provider.dart | 11 ++++++++--- 12 files changed, 39 insertions(+), 4 deletions(-) diff --git a/assets/translations/de.json b/assets/translations/de.json index 7499014..f68da68 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -233,6 +233,7 @@ "about": "Über", "requiresCredentialsInSettings": "Benötigt zusätzliche Anmeldedaten (in den Einstellungen)", "checkOnStart": "Überprüfe einmalig beim Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "App entfernen?", "other": "Apps entfernen?" diff --git a/assets/translations/en.json b/assets/translations/en.json index 1f543ac..e9b4503 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -233,6 +233,7 @@ "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "Remove App?", "other": "Remove Apps?" diff --git a/assets/translations/es.json b/assets/translations/es.json index d3b6500..6c7cc05 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -233,6 +233,7 @@ "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "¿Eliminar Aplicación?", "other": "¿Eliminar Aplicaciones?" diff --git a/assets/translations/fa.json b/assets/translations/fa.json index d7eb778..0b4030a 100644 --- a/assets/translations/fa.json +++ b/assets/translations/fa.json @@ -233,6 +233,7 @@ "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "برنامه حذف شود؟", "other": "برنامه ها حذف شوند؟" diff --git a/assets/translations/fr.json b/assets/translations/fr.json index dfc8876..ea60088 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -233,6 +233,7 @@ "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "Supprimer l'application ?", "other": "Supprimer les applications ?" diff --git a/assets/translations/hu.json b/assets/translations/hu.json index 6d311b6..c3771af 100644 --- a/assets/translations/hu.json +++ b/assets/translations/hu.json @@ -232,6 +232,7 @@ "about": "Rólunk", "requiresCredentialsInSettings": "Ehhez további hitelesítő adatokra van szükség (a Beállításokban)", "checkOnStart": "Egyszer az indításkor", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "Eltávolítja az alkalmazást?", "other": "Eltávolítja az alkalmazást?" diff --git a/assets/translations/it.json b/assets/translations/it.json index 53b20c6..93c56e1 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -233,6 +233,7 @@ "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", "checkOnStart": "Check Once on Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "Rimuovere l'App?", "other": "Rimuovere le App?" diff --git a/assets/translations/ja.json b/assets/translations/ja.json index 135a8ab..c0d9c22 100644 --- a/assets/translations/ja.json +++ b/assets/translations/ja.json @@ -233,6 +233,7 @@ "about": "概要", "requiresCredentialsInSettings": "これには追加の認証が必要です (設定にて)", "checkOnStart": "Check Once on Start", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "アプリを削除しますか?", "other": "アプリを削除しますか?" diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 83c08b2..0b3837c 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -233,6 +233,7 @@ "about": "相关文档", "requiresCredentialsInSettings": "此功能需要额外的凭据(在“设置”中添加)", "checkOnStart": "启动时进行一次检查", + "tryInferAppIdFromCode": "Try inferring App ID from source code", "removeAppQuestion": { "one": "是否删除应用?", "other": "是否删除应用?" diff --git a/lib/app_sources/github.dart b/lib/app_sources/github.dart index 0d1c6a9..d75beb2 100644 --- a/lib/app_sources/github.dart +++ b/lib/app_sources/github.dart @@ -14,6 +14,7 @@ import 'package:url_launcher/url_launcher_string.dart'; class GitHub extends AppSource { GitHub() { host = 'github.com'; + appIdInferIsOptional = true; additionalSourceSpecificSettingFormItems = [ GeneratedFormTextField('github-creds', diff --git a/lib/pages/add_app.dart b/lib/pages/add_app.dart index c439f30..b31dc4d 100644 --- a/lib/pages/add_app.dart +++ b/lib/pages/add_app.dart @@ -33,6 +33,7 @@ class _AddAppPageState extends State { AppSource? pickedSource; Map additionalSettings = {}; bool additionalSettingsValid = true; + bool inferAppIdIfOptional = true; List pickedCategories = []; int searchnum = 0; SourceProvider sourceProvider = SourceProvider(); @@ -78,6 +79,7 @@ class _AddAppPageState extends State { additionalSettingsValid = source != null ? !sourceProvider.ifRequiredAppSpecificSettingsExist(source) : true; + inferAppIdIfOptional = true; } }); } @@ -147,7 +149,8 @@ class _AddAppPageState extends State { app = await sourceProvider.getApp( pickedSource!, userInput, additionalSettings, trackOnlyOverride: trackOnly, - overrideSource: pickedSourceOverride); + overrideSource: pickedSourceOverride, + inferAppIdIfOptional: inferAppIdIfOptional); // Only download the APK here if you need to for the package ID if (sourceProvider.isTempId(app) && app.additionalSettings['trackOnly'] != true) { @@ -428,6 +431,23 @@ class _AddAppPageState extends State { }), ], ), + if (pickedSource != null && pickedSource!.appIdInferIsOptional) + GeneratedForm( + key: const Key('inferAppIdIfOptional'), + items: [ + [ + GeneratedFormSwitch('inferAppIdIfOptional', + label: tr('tryInferAppIdFromCode'), + defaultValue: inferAppIdIfOptional) + ] + ], + onValueChanges: (values, valid, isBuilding) { + if (!isBuilding) { + setState(() { + inferAppIdIfOptional = values['inferAppIdIfOptional']; + }); + } + }), ], ); diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index fc06a03..41caa43 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -317,6 +317,7 @@ abstract class AppSource { late String name; bool enforceTrackOnly = false; bool changeLogIfAnyIsMarkDown = true; + bool appIdInferIsOptional = false; AppSource() { name = runtimeType.toString(); @@ -552,7 +553,8 @@ class SourceProvider { AppSource source, String url, Map additionalSettings, {App? currentApp, bool trackOnlyOverride = false, - String? overrideSource}) async { + String? overrideSource, + bool inferAppIdIfOptional = false}) async { if (trackOnlyOverride || source.enforceTrackOnly) { additionalSettings['trackOnly'] = true; } @@ -592,8 +594,11 @@ class SourceProvider { : apk.names.name[0].toUpperCase() + apk.names.name.substring(1); return App( currentApp?.id ?? - await source.tryInferringAppId(standardUrl, - additionalSettings: additionalSettings) ?? + ((!source.appIdInferIsOptional || + (source.appIdInferIsOptional && inferAppIdIfOptional)) + ? await source.tryInferringAppId(standardUrl, + additionalSettings: additionalSettings) + : null) ?? generateTempID(standardUrl, additionalSettings), standardUrl, apk.names.author[0].toUpperCase() + apk.names.author.substring(1),