Clearer version detection settings

This commit is contained in:
Imran Remtulla
2024-01-18 23:46:23 -05:00
parent 2da9a8cd59
commit 183fb26988
20 changed files with 94 additions and 85 deletions

View File

@@ -6,6 +6,7 @@ import 'package:obtainium/providers/source_provider.dart';
class APKCombo extends AppSource { class APKCombo extends AppSource {
APKCombo() { APKCombo() {
hosts = ['apkcombo.com']; hosts = ['apkcombo.com'];
showReleaseDateAsVersionToggle = true;
} }
@override @override

View File

@@ -11,6 +11,7 @@ class APKMirror extends AppSource {
APKMirror() { APKMirror() {
hosts = ['apkmirror.com']; hosts = ['apkmirror.com'];
enforceTrackOnly = true; enforceTrackOnly = true;
showReleaseDateAsVersionToggle = true;
additionalSourceAppSpecificSettingFormItems = [ additionalSourceAppSpecificSettingFormItems = [
[ [

View File

@@ -23,6 +23,7 @@ class APKPure extends AppSource {
hosts = ['apkpure.net', 'apkpure.com']; hosts = ['apkpure.net', 'apkpure.com'];
allowSubDomains = true; allowSubDomains = true;
naiveStandardVersionDetection = true; naiveStandardVersionDetection = true;
showReleaseDateAsVersionToggle = true;
} }
@override @override

View File

@@ -10,6 +10,7 @@ class Aptoide extends AppSource {
name = 'Aptoide'; name = 'Aptoide';
allowSubDomains = true; allowSubDomains = true;
naiveStandardVersionDetection = true; naiveStandardVersionDetection = true;
showReleaseDateAsVersionToggle = true;
} }
@override @override

View File

@@ -10,6 +10,7 @@ class FDroidRepo extends AppSource {
canSearch = true; canSearch = true;
excludeFromMassSearch = true; excludeFromMassSearch = true;
neverAutoSelect = true; neverAutoSelect = true;
showReleaseDateAsVersionToggle = true;
additionalSourceAppSpecificSettingFormItems = [ additionalSourceAppSpecificSettingFormItems = [
[ [

View File

@@ -16,6 +16,7 @@ class GitHub extends AppSource {
GitHub() { GitHub() {
hosts = ['github.com']; hosts = ['github.com'];
appIdInferIsOptional = true; appIdInferIsOptional = true;
showReleaseDateAsVersionToggle = true;
sourceConfigSettingFormItems = [ sourceConfigSettingFormItems = [
GeneratedFormTextField('github-creds', GeneratedFormTextField('github-creds',

View File

@@ -15,6 +15,7 @@ class GitLab extends AppSource {
GitLab() { GitLab() {
hosts = ['gitlab.com']; hosts = ['gitlab.com'];
canSearch = true; canSearch = true;
showReleaseDateAsVersionToggle = true;
sourceConfigSettingFormItems = [ sourceConfigSettingFormItems = [
GeneratedFormTextField('gitlab-creds', GeneratedFormTextField('gitlab-creds',

View File

@@ -174,8 +174,6 @@ class HTML extends AppSource {
]) ])
] ]
]; ];
overrideVersionDetectionFormDefault('noVersionDetection',
disableStandard: false, disableRelDate: true);
} }
@override @override

View File

@@ -7,8 +7,8 @@ class HuaweiAppGallery extends AppSource {
HuaweiAppGallery() { HuaweiAppGallery() {
name = 'Huawei AppGallery'; name = 'Huawei AppGallery';
hosts = ['appgallery.huawei.com']; hosts = ['appgallery.huawei.com'];
overrideVersionDetectionFormDefault('releaseDateAsVersion', versionDetectionDisallowed = true;
disableStandard: true); showReleaseDateAsVersionToggle = true;
} }
@override @override

View File

@@ -6,9 +6,9 @@ import 'package:obtainium/providers/source_provider.dart';
class Jenkins extends AppSource { class Jenkins extends AppSource {
Jenkins() { Jenkins() {
overrideVersionDetectionFormDefault('releaseDateAsVersion', versionDetectionDisallowed = true;
disableStandard: true);
neverAutoSelect = true; neverAutoSelect = true;
showReleaseDateAsVersionToggle = true;
} }
String trimJobUrl(String url) { String trimJobUrl(String url) {

View File

@@ -6,6 +6,7 @@ import 'package:obtainium/providers/source_provider.dart';
class NeutronCode extends AppSource { class NeutronCode extends AppSource {
NeutronCode() { NeutronCode() {
hosts = ['neutroncode.com']; hosts = ['neutroncode.com'];
showReleaseDateAsVersionToggle = true;
} }
@override @override

View File

@@ -9,6 +9,7 @@ import 'package:easy_localization/easy_localization.dart';
class SourceHut extends AppSource { class SourceHut extends AppSource {
SourceHut() { SourceHut() {
hosts = ['git.sr.ht']; hosts = ['git.sr.ht'];
showReleaseDateAsVersionToggle = true;
additionalSourceAppSpecificSettingFormItems = [ additionalSourceAppSpecificSettingFormItems = [
[ [

View File

@@ -9,6 +9,7 @@ class Uptodown extends AppSource {
hosts = ['uptodown.com']; hosts = ['uptodown.com'];
allowSubDomains = true; allowSubDomains = true;
naiveStandardVersionDetection = true; naiveStandardVersionDetection = true;
showReleaseDateAsVersionToggle = true;
} }
@override @override

View File

@@ -6,8 +6,7 @@ import 'package:obtainium/providers/source_provider.dart';
class WhatsApp extends AppSource { class WhatsApp extends AppSource {
WhatsApp() { WhatsApp() {
hosts = ['whatsapp.com']; hosts = ['whatsapp.com'];
overrideVersionDetectionFormDefault('noVersionDetection', versionDetectionDisallowed = true;
disableStandard: true, disableRelDate: true);
} }
@override @override

View File

@@ -96,11 +96,14 @@ class GeneratedFormDropdown extends GeneratedFormItem {
} }
class GeneratedFormSwitch extends GeneratedFormItem { class GeneratedFormSwitch extends GeneratedFormItem {
bool disabled = false;
GeneratedFormSwitch( GeneratedFormSwitch(
super.key, { super.key, {
super.label, super.label,
super.belowWidgets, super.belowWidgets,
bool super.defaultValue = false, bool super.defaultValue = false,
bool disabled = false,
List<String? Function(bool value)> super.additionalValidators = const [], List<String? Function(bool value)> super.additionalValidators = const [],
}); });
@@ -115,6 +118,7 @@ class GeneratedFormSwitch extends GeneratedFormItem {
label: label, label: label,
belowWidgets: belowWidgets, belowWidgets: belowWidgets,
defaultValue: defaultValue, defaultValue: defaultValue,
disabled: false,
additionalValidators: List.from(additionalValidators)); additionalValidators: List.from(additionalValidators));
} }
} }
@@ -368,12 +372,15 @@ class _GeneratedFormState extends State<GeneratedForm> {
), ),
Switch( Switch(
value: values[fieldKey], value: values[fieldKey],
onChanged: (value) { onChanged:
setState(() { (widget.items[r][e] as GeneratedFormSwitch).disabled
values[fieldKey] = value; ? null
someValueChanged(); : (value) {
}); setState(() {
}) values[fieldKey] = value;
someValueChanged();
});
})
], ],
); );
} else if (widget.items[r][e] is GeneratedFormTagInput) { } else if (widget.items[r][e] is GeneratedFormTagInput) {

View File

@@ -183,10 +183,7 @@ class _ObtainiumState extends State<Obtainium> {
value.versionName!, value.versionName!,
[], [],
0, 0,
{ {'includePrereleases': true, 'versionDetection': true},
'includePrereleases': true,
'versionDetection': 'standardVersionDetection'
},
null, null,
false) false)
], onlyIfExists: false); ], onlyIfExists: false);

View File

@@ -135,8 +135,7 @@ class AddAppPageState extends State<AddAppPage> {
getReleaseDateAsVersionConfirmationIfNeeded( getReleaseDateAsVersionConfirmationIfNeeded(
bool userPickedTrackOnly) async { bool userPickedTrackOnly) async {
return (!(additionalSettings['versionDetection'] == return (!(additionalSettings['releaseDateAsVersion'] == true &&
'releaseDateAsVersion' &&
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
await showDialog( await showDialog(
context: context, context: context,
@@ -192,8 +191,7 @@ class AddAppPageState extends State<AddAppPage> {
throw ObtainiumError(tr('appAlreadyAdded')); throw ObtainiumError(tr('appAlreadyAdded'));
} }
if (app.additionalSettings['trackOnly'] == true || if (app.additionalSettings['trackOnly'] == true ||
app.additionalSettings['versionDetection'] != app.additionalSettings['versionDetection'] != true) {
'standardVersionDetection') {
app.installedVersion = app.latestVersion; app.installedVersion = app.latestVersion;
} }
app.categories = pickedCategories; app.categories = pickedCategories;

View File

@@ -1,7 +1,6 @@
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:obtainium/components/generated_form.dart';
import 'package:obtainium/components/generated_form_modal.dart'; import 'package:obtainium/components/generated_form_modal.dart';
import 'package:obtainium/custom_errors.dart'; import 'package:obtainium/custom_errors.dart';
import 'package:obtainium/main.dart'; import 'package:obtainium/main.dart';
@@ -54,13 +53,11 @@ class _AppPageState extends State<AppPage> {
var trackOnly = app?.app.additionalSettings['trackOnly'] == true; var trackOnly = app?.app.additionalSettings['trackOnly'] == true;
bool isVersionDetectionStandard = bool isVersionDetectionStandard =
app?.app.additionalSettings['versionDetection'] == app?.app.additionalSettings['versionDetection'] == true;
'standardVersionDetection';
bool installedVersionIsEstimate = trackOnly || bool installedVersionIsEstimate = trackOnly ||
(app?.app.installedVersion != null && (app?.app.installedVersion != null &&
app?.app.additionalSettings['versionDetection'] == app?.app.additionalSettings['versionDetection'] != true);
'noVersionDetection');
getInfoColumn() => Column( getInfoColumn() => Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@@ -287,25 +284,6 @@ class _AppPageState extends State<AppPage> {
return row; return row;
}).toList(); }).toList();
items = items.map((row) {
row = row.map((e) {
if (e.key == 'versionDetection' && e is GeneratedFormDropdown) {
e.disabledOptKeys ??= [];
if (app?.app.installedVersion != null &&
app?.app.additionalSettings['versionDetection'] !=
'releaseDateAsVersion' &&
!appsProvider.isVersionDetectionPossible(app)) {
e.disabledOptKeys!.add('standardVersionDetection');
}
if (app?.app.releaseDate == null) {
e.disabledOptKeys!.add('releaseDateAsVersion');
}
}
return e;
}).toList();
return row;
}).toList();
return GeneratedFormModal( return GeneratedFormModal(
title: tr('additionalOptions'), items: items); title: tr('additionalOptions'), items: items);
}); });
@@ -320,9 +298,8 @@ class _AppPageState extends State<AppPage> {
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
showMessage(tr('appsFromSourceAreTrackOnly'), context); showMessage(tr('appsFromSourceAreTrackOnly'), context);
} }
if (app.app.additionalSettings['versionDetection'] == if (app.app.additionalSettings['releaseDateAsVersion'] == true) {
'releaseDateAsVersion') { if (originalSettings['releaseDateAsVersion'] != true) {
if (originalSettings['versionDetection'] != 'releaseDateAsVersion') {
if (app.app.releaseDate != null) { if (app.app.releaseDate != null) {
bool isUpdated = bool isUpdated =
app.app.installedVersion == app.app.latestVersion; app.app.installedVersion == app.app.latestVersion;
@@ -333,8 +310,7 @@ class _AppPageState extends State<AppPage> {
} }
} }
} }
} else if (originalSettings['versionDetection'] == } else if (originalSettings['releaseDateAsVersion'] == true) {
'releaseDateAsVersion') {
app.app.installedVersion = app.app.installedVersion =
app.installedInfo?.versionName ?? app.app.installedVersion; app.installedInfo?.versionName ?? app.app.installedVersion;
} }

View File

@@ -820,8 +820,7 @@ class AppsProvider with ChangeNotifier {
? app.installedInfo?.versionCode.toString() ? app.installedInfo?.versionCode.toString()
: app.installedInfo?.versionName; : app.installedInfo?.versionName;
return app.app.additionalSettings['trackOnly'] != true && return app.app.additionalSettings['trackOnly'] != true &&
app.app.additionalSettings['versionDetection'] != app.app.additionalSettings['releaseDateAsVersion'] != true &&
'releaseDateAsVersion' &&
realInstalledVersion != null && realInstalledVersion != null &&
app.app.installedVersion != null && app.app.installedVersion != null &&
(reconcileVersionDifferences( (reconcileVersionDifferences(
@@ -837,8 +836,7 @@ class AppsProvider with ChangeNotifier {
var modded = false; var modded = false;
var trackOnly = app.additionalSettings['trackOnly'] == true; var trackOnly = app.additionalSettings['trackOnly'] == true;
var versionDetectionIsStandard = var versionDetectionIsStandard =
app.additionalSettings['versionDetection'] == app.additionalSettings['versionDetection'] == true;
'standardVersionDetection';
var naiveStandardVersionDetection = var naiveStandardVersionDetection =
app.additionalSettings['naiveStandardVersionDetection'] == true || app.additionalSettings['naiveStandardVersionDetection'] == true ||
SourceProvider() SourceProvider()
@@ -892,7 +890,7 @@ class AppsProvider with ChangeNotifier {
versionDetectionIsStandard && versionDetectionIsStandard &&
!isVersionDetectionPossible( !isVersionDetectionPossible(
AppInMemory(app, null, installedInfo, null))) { AppInMemory(app, null, installedInfo, null))) {
app.additionalSettings['versionDetection'] = 'noVersionDetection'; app.additionalSettings['versionDetection'] = false;
logs.add('Could not reconcile version formats for: ${app.id}'); logs.add('Could not reconcile version formats for: ${app.id}');
modded = true; modded = true;
} }

View File

@@ -103,6 +103,15 @@ appJSONCompatibilityModifiers(Map<String, dynamic> json) {
additionalSettings.remove('releaseDateAsVersion'); additionalSettings.remove('releaseDateAsVersion');
} }
} }
// Convert dropdown style version detection options back into bool style
if (additionalSettings['versionDetection'] == 'standardVersionDetection') {
additionalSettings['versionDetection'] = true;
} else if (additionalSettings['versionDetection'] == 'noVersionDetection') {
additionalSettings['versionDetection'] = false;
} else if (additionalSettings['versionDetection'] == 'releaseDateAsVersion') {
additionalSettings['versionDetection'] = false;
additionalSettings['releaseDateAsVersion'] = true;
}
// Ensure additionalSettings are correctly typed // Ensure additionalSettings are correctly typed
for (var item in formItems) { for (var item in formItems) {
if (additionalSettings[item.key] != null) { if (additionalSettings[item.key] != null) {
@@ -380,28 +389,23 @@ abstract class AppSource {
bool allowSubDomains = false; bool allowSubDomains = false;
bool naiveStandardVersionDetection = false; bool naiveStandardVersionDetection = false;
bool neverAutoSelect = false; bool neverAutoSelect = false;
bool showReleaseDateAsVersionToggle = false;
bool versionDetectionDisallowed = false;
AppSource() { AppSource() {
name = runtimeType.toString(); name = runtimeType.toString();
} }
overrideVersionDetectionFormDefault(String vd, overrideAdditionalAppSpecificSourceAgnosticSettingSwitch(String key,
{bool disableStandard = false, bool disableRelDate = false}) { {bool disabled = true, bool defaultValue = true}) {
additionalAppSpecificSourceAgnosticSettingFormItems = additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly =
additionalAppSpecificSourceAgnosticSettingFormItems.map((e) { additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly
.map((e) {
return e.map((e2) { return e.map((e2) {
if (e2.key == 'versionDetection') { if (e2.key == key) {
var item = e2 as GeneratedFormDropdown; var item = e2 as GeneratedFormSwitch;
item.defaultValue = vd; item.disabled = disabled;
item.disabledOptKeys = []; item.defaultValue = defaultValue;
if (disableStandard) {
item.disabledOptKeys?.add('standardVersionDetection');
}
if (disableRelDate) {
item.disabledOptKeys?.add('releaseDateAsVersion');
}
item.disabledOptKeys =
item.disabledOptKeys?.where((element) => element != vd).toList();
} }
return e2; return e2;
}).toList(); }).toList();
@@ -457,7 +461,7 @@ abstract class AppSource {
// Some additional data may be needed for Apps regardless of Source // Some additional data may be needed for Apps regardless of Source
List<List<GeneratedFormItem>> List<List<GeneratedFormItem>>
additionalAppSpecificSourceAgnosticSettingFormItems = [ additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly = [
[ [
GeneratedFormSwitch( GeneratedFormSwitch(
'trackOnly', 'trackOnly',
@@ -475,16 +479,8 @@ abstract class AppSource {
label: tr('matchGroupToUse'), required: false, hint: '\$0') label: tr('matchGroupToUse'), required: false, hint: '\$0')
], ],
[ [
GeneratedFormDropdown( GeneratedFormSwitch('versionDetection',
'versionDetection', label: tr('versionDetection'), defaultValue: true)
[
MapEntry(
'standardVersionDetection', tr('standardVersionDetection')),
MapEntry('releaseDateAsVersion', tr('releaseDateAsVersion')),
MapEntry('noVersionDetection', tr('noVersionDetection'))
],
label: tr('versionDetection'),
defaultValue: 'standardVersionDetection')
], ],
[ [
GeneratedFormSwitch('useVersionCodeAsOSVersion', GeneratedFormSwitch('useVersionCodeAsOSVersion',
@@ -518,9 +514,39 @@ abstract class AppSource {
// Previous 2 variables combined into one at runtime for convenient usage // Previous 2 variables combined into one at runtime for convenient usage
List<List<GeneratedFormItem>> get combinedAppSpecificSettingFormItems { List<List<GeneratedFormItem>> get combinedAppSpecificSettingFormItems {
if (showReleaseDateAsVersionToggle == true) {
if (additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly
.indexWhere((List<GeneratedFormItem> e) =>
e.indexWhere((GeneratedFormItem i) =>
i.key == 'releaseDateAsVersion') >=
0) <
0) {
additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly.insert(
additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly
.indexWhere((List<GeneratedFormItem> e) =>
e.indexWhere((GeneratedFormItem i) =>
i.key == 'versionDetection') >=
0) +
1,
[
GeneratedFormSwitch('releaseDateAsVersion',
label: tr('releaseDateAsVersion'), defaultValue: false)
]);
}
}
if (versionDetectionDisallowed) {
overrideAdditionalAppSpecificSourceAgnosticSettingSwitch(
'versionDetection',
disabled: true,
defaultValue: false);
overrideAdditionalAppSpecificSourceAgnosticSettingSwitch(
'useVersionCodeAsOSVersion',
disabled: true,
defaultValue: false);
}
return [ return [
...additionalSourceAppSpecificSettingFormItems, ...additionalSourceAppSpecificSettingFormItems,
...additionalAppSpecificSourceAgnosticSettingFormItems ...additionalAppSpecificSourceAgnosticSettingFormItemsNeverUseDirectly
]; ];
} }
@@ -773,7 +799,7 @@ class SourceProvider {
} }
} }
if (additionalSettings['versionDetection'] == 'releaseDateAsVersion' && if (additionalSettings['releaseDateAsVersion'] == true &&
apk.releaseDate != null) { apk.releaseDate != null) {
apk.version = apk.releaseDate!.microsecondsSinceEpoch.toString(); apk.version = apk.releaseDate!.microsecondsSinceEpoch.toString();
} }