mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-28 12:03:45 +01:00 
			
		
		
		
	Source configuration settings changes
- "Source config" refers to source-specific, app-agnostic settings - Don't use saved config for overridden sources - For overridden sources, use app-specific source config - Allow sources to show notes on add-app page (#720)
This commit is contained in:
		| @@ -240,6 +240,10 @@ | ||||
|    "disablePageTransitions": "Ugasite animaciju prijelaza stranice", | ||||
|    "reversePageTransitions": "Reverzne animacije prijelaza stranice", | ||||
|    "minStarCount": "Minimum Star Count", | ||||
|    "addInfoBelow": "Add this info below.", | ||||
|    "addInfoInSettings": "Add this info in the Settings.", | ||||
|    "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|    "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|    "removeAppQuestion": { | ||||
|       "one": "Želite li ukloniti aplikaciju?", | ||||
|       "other": "Želite li ukloniti aplikacije?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Disable page transition animations", | ||||
|     "reversePageTransitions": "Reverse page transition animations", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "App entfernen?", | ||||
|         "other": "Apps entfernen?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Disable page transition animations", | ||||
|     "reversePageTransitions": "Reverse page transition animations", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Remove App?", | ||||
|         "other": "Remove Apps?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Disable page transition animations", | ||||
|     "reversePageTransitions": "Reverse page transition animations", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "¿Eliminar Aplicación?", | ||||
|         "other": "¿Eliminar Aplicaciones?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Disable page transition animations", | ||||
|     "reversePageTransitions": "Reverse page transition animations", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "برنامه حذف شود؟", | ||||
|         "other": "برنامه ها حذف شوند؟" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Disable page transition animations", | ||||
|     "reversePageTransitions": "Reverse page transition animations", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Supprimer l'application ?", | ||||
|         "other": "Supprimer les applications ?" | ||||
|   | ||||
| @@ -239,6 +239,10 @@ | ||||
|     "disablePageTransitions": "Lap áttűnési animációk tiltása", | ||||
|     "reversePageTransitions": "Fordított lap áttűnési animációk", | ||||
|     "minStarCount": "Minimális csillag szám", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Eltávolítja az alkalmazást?", | ||||
|         "other": "Eltávolítja az alkalmazást?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Disable page transition animations", | ||||
|     "reversePageTransitions": "Reverse page transition animations", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Rimuovere l'app?", | ||||
|         "other": "Rimuovere le app?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "ページ遷移アニメーションを無効化する", | ||||
|     "reversePageTransitions": "ページ遷移アニメーションを反転する", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "アプリを削除しますか?", | ||||
|         "other": "アプリを削除しますか?" | ||||
|   | ||||
| @@ -244,6 +244,10 @@ | ||||
|     "disablePageTransitions": "Wyłącz animacje przejścia między stronami", | ||||
|     "reversePageTransitions": "Odwróć animacje przejścia pomiędzy stronami", | ||||
|     "minStarCount": "Minimum Star Count", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Usunąć aplikację?", | ||||
|         "other": "Usunąć aplikacje?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "Отключить анимацию перехода между страницами", | ||||
|     "reversePageTransitions": "Реверс анимации перехода между страницами", | ||||
|     "minStarCount": "Минимальное количество звёзд", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Удалить приложение?", | ||||
|         "other": "Удалить приложения?" | ||||
|   | ||||
| @@ -240,6 +240,10 @@ | ||||
|     "disablePageTransitions": "禁用页面过渡动画效果", | ||||
|     "reversePageTransitions": "反转页面过渡动画效果", | ||||
|     "minStarCount": "最小星标数", | ||||
|     "addInfoBelow": "Add this info below.", | ||||
|     "addInfoInSettings": "Add this info in the Settings.", | ||||
|     "githubSourceNote": "GitHub rate limiting can be avoided using an API key.", | ||||
|     "gitlabSourceNote": "GitLab APK extraction may not work without an API key.", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "是否删除应用?", | ||||
|         "other": "是否删除应用?" | ||||
|   | ||||
| @@ -9,8 +9,6 @@ class Codeberg extends AppSource { | ||||
|   Codeberg() { | ||||
|     host = 'codeberg.org'; | ||||
|  | ||||
|     additionalSourceSpecificSettingFormItems = []; | ||||
|  | ||||
|     additionalSourceAppSpecificSettingFormItems = [ | ||||
|       [ | ||||
|         GeneratedFormSwitch('includePrereleases', | ||||
|   | ||||
| @@ -16,7 +16,7 @@ class GitHub extends AppSource { | ||||
|     host = 'github.com'; | ||||
|     appIdInferIsOptional = true; | ||||
|  | ||||
|     additionalSourceSpecificSettingFormItems = [ | ||||
|     sourceConfigSettingFormItems = [ | ||||
|       GeneratedFormTextField('github-creds', | ||||
|           label: tr('githubPATLabel'), | ||||
|           password: true, | ||||
| @@ -107,7 +107,7 @@ class GitHub extends AppSource { | ||||
|     for (var path in possibleBuildGradleLocations) { | ||||
|       try { | ||||
|         var res = await sourceRequest( | ||||
|             '${await convertStandardUrlToAPIUrl(standardUrl)}/contents/$path'); | ||||
|             '${await convertStandardUrlToAPIUrl(standardUrl, additionalSettings)}/contents/$path'); | ||||
|         if (res.statusCode == 200) { | ||||
|           try { | ||||
|             var body = jsonDecode(res.body); | ||||
| @@ -155,19 +155,30 @@ class GitHub extends AppSource { | ||||
|     return url.substring(0, match.end); | ||||
|   } | ||||
|  | ||||
|   Future<String> getCredentialPrefixIfAny() async { | ||||
|   Future<String> getCredentialPrefixIfAny( | ||||
|       Map<String, dynamic> additionalSettings) async { | ||||
|     SettingsProvider settingsProvider = SettingsProvider(); | ||||
|     await settingsProvider.initializeSettings(); | ||||
|     String? creds = settingsProvider | ||||
|         .getSettingString(additionalSourceSpecificSettingFormItems[0].key); | ||||
|     var sourceConfig = | ||||
|         await getSourceConfigValues(additionalSettings, settingsProvider); | ||||
|     String? creds = sourceConfig['github-creds']; | ||||
|     return creds != null && creds.isNotEmpty ? '$creds@' : ''; | ||||
|   } | ||||
|  | ||||
|   Future<String> getAPIHost() async => | ||||
|       'https://${await getCredentialPrefixIfAny()}api.$host'; | ||||
|   @override | ||||
|   Future<String?> getSourceNote() async { | ||||
|     if (!hostChanged && (await getCredentialPrefixIfAny({})).isEmpty) { | ||||
|       return '${tr('githubSourceNote')} ${hostChanged ? tr('addInfoBelow') : tr('addInfoInSettings')}'; | ||||
|     } | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   Future<String> convertStandardUrlToAPIUrl(String standardUrl) async => | ||||
|       '${await getAPIHost()}/repos${standardUrl.substring('https://$host'.length)}'; | ||||
|   Future<String> getAPIHost(Map<String, dynamic> additionalSettings) async => | ||||
|       'https://${await getCredentialPrefixIfAny(additionalSettings)}api.$host'; | ||||
|  | ||||
|   Future<String> convertStandardUrlToAPIUrl( | ||||
|           String standardUrl, Map<String, dynamic> additionalSettings) async => | ||||
|       '${await getAPIHost(additionalSettings)}/repos${standardUrl.substring('https://$host'.length)}'; | ||||
|  | ||||
|   @override | ||||
|   String? changeLogPageFromStandardUrl(String standardUrl) => | ||||
| @@ -311,7 +322,7 @@ class GitHub extends AppSource { | ||||
|   ) async { | ||||
|     return await getLatestAPKDetailsCommon2(standardUrl, additionalSettings, | ||||
|         (bool useTagUrl) async { | ||||
|       return '${await convertStandardUrlToAPIUrl(standardUrl)}/${useTagUrl ? 'tags' : 'releases'}?per_page=100'; | ||||
|       return '${await convertStandardUrlToAPIUrl(standardUrl, additionalSettings)}/${useTagUrl ? 'tags' : 'releases'}?per_page=100'; | ||||
|     }, (Response res) { | ||||
|       rateLimitErrorCheck(res); | ||||
|     }); | ||||
| @@ -360,7 +371,7 @@ class GitHub extends AppSource { | ||||
|       {Map<String, dynamic> querySettings = const {}}) async { | ||||
|     return searchCommon( | ||||
|         query, | ||||
|         '${await getAPIHost()}/search/repositories?q=${Uri.encodeQueryComponent(query)}&per_page=100', | ||||
|         '${await getAPIHost({})}/search/repositories?q=${Uri.encodeQueryComponent(query)}&per_page=100', | ||||
|         'items', onHttpErrorCode: (Response res) { | ||||
|       rateLimitErrorCheck(res); | ||||
|     }, querySettings: querySettings); | ||||
|   | ||||
| @@ -16,7 +16,7 @@ class GitLab extends AppSource { | ||||
|     host = 'gitlab.com'; | ||||
|     canSearch = true; | ||||
|  | ||||
|     additionalSourceSpecificSettingFormItems = [ | ||||
|     sourceConfigSettingFormItems = [ | ||||
|       GeneratedFormTextField('gitlab-creds', | ||||
|           label: tr('gitlabPATLabel'), | ||||
|           password: true, | ||||
| @@ -60,18 +60,27 @@ class GitLab extends AppSource { | ||||
|     return url.substring(0, match.end); | ||||
|   } | ||||
|  | ||||
|   Future<String?> getPATIfAny() async { | ||||
|   Future<String?> getPATIfAny(Map<String, dynamic> additionalSettings) async { | ||||
|     SettingsProvider settingsProvider = SettingsProvider(); | ||||
|     await settingsProvider.initializeSettings(); | ||||
|     String? creds = settingsProvider | ||||
|         .getSettingString(additionalSourceSpecificSettingFormItems[0].key); | ||||
|     var sourceConfig = | ||||
|         await getSourceConfigValues(additionalSettings, settingsProvider); | ||||
|     String? creds = sourceConfig['gitlab-creds']; | ||||
|     return creds != null && creds.isNotEmpty ? creds : null; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   Future<String?> getSourceNote() async { | ||||
|     if ((await getPATIfAny({})) == null) { | ||||
|       return '${tr('gitlabSourceNote')} ${hostChanged ? tr('addInfoBelow') : tr('addInfoInSettings')}'; | ||||
|     } | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   Future<Map<String, List<String>>> search(String query, | ||||
|       {Map<String, dynamic> querySettings = const {}}) async { | ||||
|     String? PAT = await getPATIfAny(); | ||||
|     String? PAT = await getPATIfAny({}); | ||||
|     if (PAT == null) { | ||||
|       throw CredsNeededError(name); | ||||
|     } | ||||
| @@ -103,7 +112,7 @@ class GitLab extends AppSource { | ||||
|   ) async { | ||||
|     bool fallbackToOlderReleases = | ||||
|         additionalSettings['fallbackToOlderReleases'] == true; | ||||
|     String? PAT = await getPATIfAny(); | ||||
|     String? PAT = await getPATIfAny(hostChanged ? additionalSettings : {}); | ||||
|     Iterable<APKDetails> apkDetailsList = []; | ||||
|     if (PAT != null) { | ||||
|       var names = GitHub().getAppNames(standardUrl); | ||||
|   | ||||
| @@ -16,7 +16,7 @@ class GitHubStars implements MassAppUrlSource { | ||||
|   Future<Map<String, List<String>>> getOnePageOfUserStarredUrlsWithDescriptions( | ||||
|       String username, int page) async { | ||||
|     Response res = await get(Uri.parse( | ||||
|         'https://${await GitHub().getCredentialPrefixIfAny()}api.github.com/users/$username/starred?per_page=100&page=$page')); | ||||
|         'https://${await GitHub().getCredentialPrefixIfAny({})}api.github.com/users/$username/starred?per_page=100&page=$page')); | ||||
|     if (res.statusCode == 200) { | ||||
|       Map<String, List<String>> urlsWithDescriptions = {}; | ||||
|       for (var e in (jsonDecode(res.body) as List<dynamic>)) { | ||||
|   | ||||
| @@ -41,6 +41,7 @@ class _AddAppPageState extends State<AddAppPage> { | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     AppsProvider appsProvider = context.read<AppsProvider>(); | ||||
|     SettingsProvider settingsProvider = context.watch<SettingsProvider>(); | ||||
|  | ||||
|     bool doingSomething = gettingAppInfo || searching; | ||||
|  | ||||
| @@ -85,8 +86,7 @@ class _AddAppPageState extends State<AddAppPage> { | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     Future<bool> getTrackOnlyConfirmationIfNeeded( | ||||
|         bool userPickedTrackOnly, SettingsProvider settingsProvider, | ||||
|     Future<bool> getTrackOnlyConfirmationIfNeeded(bool userPickedTrackOnly, | ||||
|         {bool ignoreHideSetting = false}) async { | ||||
|       var useTrackOnly = userPickedTrackOnly || pickedSource!.enforceTrackOnly; | ||||
|       if (useTrackOnly && | ||||
| @@ -138,11 +138,9 @@ class _AddAppPageState extends State<AddAppPage> { | ||||
|         gettingAppInfo = true; | ||||
|       }); | ||||
|       try { | ||||
|         var settingsProvider = context.read<SettingsProvider>(); | ||||
|         var userPickedTrackOnly = additionalSettings['trackOnly'] == true; | ||||
|         App? app; | ||||
|         if ((await getTrackOnlyConfirmationIfNeeded( | ||||
|                 userPickedTrackOnly, settingsProvider)) && | ||||
|         if ((await getTrackOnlyConfirmationIfNeeded(userPickedTrackOnly)) && | ||||
|             (await getReleaseDateAsVersionConfirmationIfNeeded( | ||||
|                 userPickedTrackOnly))) { | ||||
|           var trackOnly = pickedSource!.enforceTrackOnly || userPickedTrackOnly; | ||||
| @@ -410,7 +408,13 @@ class _AddAppPageState extends State<AddAppPage> { | ||||
|             ), | ||||
|             GeneratedForm( | ||||
|                 key: Key(pickedSource.runtimeType.toString()), | ||||
|                 items: pickedSource!.combinedAppSpecificSettingFormItems, | ||||
|                 items: [ | ||||
|                   ...pickedSource!.combinedAppSpecificSettingFormItems, | ||||
|                   ...(pickedSourceOverride != null | ||||
|                       ? pickedSource!.sourceConfigSettingFormItems | ||||
|                           .map((e) => [e]) | ||||
|                       : []) | ||||
|                 ], | ||||
|                 onValueChanges: (values, valid, isBuilding) { | ||||
|                   if (!isBuilding) { | ||||
|                     setState(() { | ||||
| @@ -504,6 +508,18 @@ class _AddAppPageState extends State<AddAppPage> { | ||||
|                                   HTML().runtimeType.toString())) | ||||
|                         getHTMLSourceOverrideDropdown(), | ||||
|                       if (shouldShowSearchBar()) getSearchBarRow(), | ||||
|                       if (pickedSource != null) | ||||
|                         FutureBuilder( | ||||
|                             builder: (ctx, val) { | ||||
|                               return val.data != null && val.data!.isNotEmpty | ||||
|                                   ? Text( | ||||
|                                       val.data!, | ||||
|                                       style: | ||||
|                                           Theme.of(context).textTheme.bodySmall, | ||||
|                                     ) | ||||
|                                   : const SizedBox(); | ||||
|                             }, | ||||
|                             future: pickedSource?.getSourceNote()), | ||||
|                       const SizedBox( | ||||
|                         height: 16, | ||||
|                       ), | ||||
|   | ||||
| @@ -166,9 +166,9 @@ class _SettingsPageState extends State<SettingsPage> { | ||||
|         }); | ||||
|  | ||||
|     var sourceSpecificFields = sourceProvider.sources.map((e) { | ||||
|       if (e.additionalSourceSpecificSettingFormItems.isNotEmpty) { | ||||
|       if (e.sourceConfigSettingFormItems.isNotEmpty) { | ||||
|         return GeneratedForm( | ||||
|             items: e.additionalSourceSpecificSettingFormItems.map((e) { | ||||
|             items: e.sourceConfigSettingFormItems.map((e) { | ||||
|               e.defaultValue = settingsProvider.getSettingString(e.key); | ||||
|               return [e]; | ||||
|             }).toList(), | ||||
|   | ||||
| @@ -28,6 +28,7 @@ import 'package:obtainium/app_sources/vlc.dart'; | ||||
| import 'package:obtainium/components/generated_form.dart'; | ||||
| import 'package:obtainium/custom_errors.dart'; | ||||
| import 'package:obtainium/mass_app_sources/githubstars.dart'; | ||||
| import 'package:obtainium/providers/settings_provider.dart'; | ||||
|  | ||||
| class AppNames { | ||||
|   late String author; | ||||
| @@ -424,12 +425,31 @@ abstract class AppSource { | ||||
|   } | ||||
|  | ||||
|   // Some Sources may have additional settings at the Source level (not specific to Apps) - these use SettingsProvider | ||||
|   List<GeneratedFormItem> additionalSourceSpecificSettingFormItems = []; | ||||
|   // If the source has been overridden, we expect the user to define one-time values as additional settings - don't use the stored values | ||||
|   List<GeneratedFormItem> sourceConfigSettingFormItems = []; | ||||
|   Future<Map<String, String>> getSourceConfigValues( | ||||
|       Map<String, dynamic> additionalSettings, | ||||
|       SettingsProvider settingsProvider) async { | ||||
|     Map<String, String> results = {}; | ||||
|     sourceConfigSettingFormItems.forEach((e) { | ||||
|       var val = hostChanged | ||||
|           ? additionalSettings[e.key] | ||||
|           : settingsProvider.getSettingString(e.key); | ||||
|       if (val != null) { | ||||
|         results[e.key] = val; | ||||
|       } | ||||
|     }); | ||||
|     return results; | ||||
|   } | ||||
|  | ||||
|   String? changeLogPageFromStandardUrl(String standardUrl) { | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   Future<String?> getSourceNote() async { | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   Future<String> apkUrlPrefetchModifier( | ||||
|       String apkUrl, String standardUrl) async { | ||||
|     return apkUrl; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user