Version detection improvements, Mullvad web scraping fix and changelog addition, code readability improvements, general tweaks/bugfixes (#400)

1. Apps that don't have "standard" versioning formats now automatically stop using version detection. This will prevent users from having to learn about this feature and enable it manually.
    - For such Apps, the "standard" version detection option is greyed out.
2. The Mullvad Source recently broke due to a slight change in their website design. This is now fixed.
    - Mullvad also now provides an in-app changelog via their official GitHub repo.
3. Code has been refactored for readability (specifically the version detection code and UI code for most screens).
4. Minor UI tweaks and bugfixes.
This commit is contained in:
Imran Remtulla
2023-03-30 17:27:36 -04:00
committed by GitHub
parent c7cd35b6a1
commit 9fba747802
11 changed files with 1720 additions and 1873 deletions

View File

@@ -1,5 +1,7 @@
import 'package:html/parser.dart';
import 'package:http/http.dart';
import 'package:obtainium/app_sources/github.dart';
import 'package:obtainium/app_sources/html.dart';
import 'package:obtainium/custom_errors.dart';
import 'package:obtainium/providers/source_provider.dart';
@@ -27,23 +29,24 @@ class Mullvad extends AppSource {
String standardUrl,
Map<String, dynamic> additionalSettings,
) async {
Response res = await get(Uri.parse('$standardUrl/en/download/android'));
if (res.statusCode == 200) {
var version = parse(res.body)
.querySelector('p.subtitle.is-6')
?.querySelector('a')
?.attributes['href']
?.split('/')
.last;
if (version == null) {
throw NoVersionError();
}
return APKDetails(
version,
['https://mullvad.net/download/app/apk/latest'],
AppNames(name, 'Mullvad-VPN'));
} else {
throw getObtainiumHttpError(res);
var details = await HTML().getLatestAPKDetails(
'$standardUrl/en/download/android', additionalSettings);
var fileName = details.apkUrls[0].split('/').last;
var versionMatch = RegExp('[0-9]+(\\.[0-9]+)+').firstMatch(fileName);
if (versionMatch == null) {
throw NoVersionError();
}
details.version = fileName.substring(versionMatch.start, versionMatch.end);
details.names = AppNames(name, 'Mullvad-VPN');
try {
details.changeLog = (await GitHub().getLatestAPKDetails(
'https://github.com/mullvad/mullvadvpn-app',
{'fallbackToOlderReleases': true}))
.changeLog;
} catch (e) {
print(e);
// Ignore
}
return details;
}
}