Skip to content

Commit

Permalink
Merge pull request #1853 from ImranR98/dev
Browse files Browse the repository at this point in the history
- Add Tencent App Store (#1848)
- Enable icon caching (#1837)
  • Loading branch information
ImranR98 authored Sep 27, 2024
2 parents 1fcb923 + 10c558f commit 1e03194
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 43 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Currently supported App sources:
- [Aptoide](https://aptoide.com/)
- [Uptodown](https://uptodown.com/)
- [Huawei AppGallery](https://appgallery.huawei.com/)
- [Tencent App Store](https://sj.qq.com/)
- Jenkins Jobs
- [APKMirror](https://apkmirror.com/) (Track-Only)
- Open Source - App-Specific:
Expand Down
78 changes: 78 additions & 0 deletions lib/app_sources/tencent.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'dart:convert';

import 'package:obtainium/custom_errors.dart';
import 'package:obtainium/providers/source_provider.dart';

class Tencent extends AppSource {
Tencent() {
name = 'Tencent App Store';
hosts = ['sj.qq.com'];
naiveStandardVersionDetection = true;
showReleaseDateAsVersionToggle = true;
}

@override
String sourceSpecificStandardizeURL(String url, {bool forSelection = false}) {
RegExp standardUrlRegEx = RegExp(
'^https?://${getSourceRegex(hosts)}/appdetail/[^/]+',
caseSensitive: false);
var match = standardUrlRegEx.firstMatch(url);
if (match == null) {
throw InvalidURLError(name);
}
return match.group(0)!;
}

@override
Future<String?> tryInferringAppId(String standardUrl,
{Map<String, dynamic> additionalSettings = const {}}) async {
return Uri.parse(standardUrl).pathSegments.last;
}

@override
Future<APKDetails> getLatestAPKDetails(
String standardUrl,
Map<String, dynamic> additionalSettings,
) async {
String appId = (await tryInferringAppId(standardUrl))!;
String baseHost = Uri.parse(standardUrl)
.host
.split('.')
.reversed
.toList()
.sublist(0, 2)
.reversed
.join('.');

var res = await sourceRequest(
'https://upage.html5.$baseHost/wechat-apkinfo', additionalSettings,
followRedirects: false, postBody: {"packagename": appId});

if (res.statusCode == 200) {
var json = jsonDecode(res.body);
if (json['app_detail_records'][appId] == null) {
throw NoReleasesError();
}
var version =
json['app_detail_records'][appId]['apk_all_data']['version_name'];
var apkUrl = json['app_detail_records'][appId]['apk_all_data']['url'];
if (apkUrl == null) {
throw NoAPKError();
}
var appName = json['app_detail_records'][appId]['app_info']['name'];
var author = json['app_detail_records'][appId]['app_info']['author'];
var releaseDate =
json['app_detail_records'][appId]['app_info']['update_time'];

return APKDetails(
version,
[MapEntry(Uri.parse(apkUrl).queryParameters['fsname']!, apkUrl)],
AppNames(author, appName),
releaseDate: releaseDate != null
? DateTime.fromMillisecondsSinceEpoch(releaseDate * 1000)
: null);
} else {
throw getObtainiumHttpError(res);
}
}
}
3 changes: 2 additions & 1 deletion lib/pages/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class _AppPageState extends State<AppPage> {
children: [
const SizedBox(height: 20),
FutureBuilder(
future: appsProvider.updateAppIcon(app?.app.id),
future:
appsProvider.updateAppIcon(app?.app.id, ignoreCache: true),
builder: (ctx, val) {
return app?.icon != null
? Row(
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ class AppsPageState extends State<AppsPage> {
? Image.memory(
listedApps[appIndex].icon!,
gaplessPlayback: true,
opacity: AlwaysStoppedAnimation(
listedApps[appIndex].installedInfo == null ? 0.6 : 1),
)
: Row(
mainAxisSize: MainAxisSize.min,
Expand Down
22 changes: 19 additions & 3 deletions lib/providers/apps_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class AppsProvider with ChangeNotifier {
late Stream<FGBGType>? foregroundStream;
late StreamSubscription<FGBGType>? foregroundSubscription;
late Directory APKDir;
late Directory iconsCacheDir;
late SettingsProvider settingsProvider = SettingsProvider();

Iterable<AppInMemory> getAppValues() => apps.values.map((a) => a.deepCopy());
Expand All @@ -393,12 +394,21 @@ class AppsProvider with ChangeNotifier {
var cacheDirs = await getExternalCacheDirectories();
if (cacheDirs?.isNotEmpty ?? false) {
APKDir = cacheDirs!.first;
iconsCacheDir = Directory('${cacheDirs.first.path}/icons');
if (!iconsCacheDir.existsSync()) {
iconsCacheDir.createSync();
}
} else {
APKDir =
Directory('${(await getExternalStorageDirectory())!.path}/apks');
if (!APKDir.existsSync()) {
APKDir.createSync();
}
iconsCacheDir =
Directory('${(await getExternalStorageDirectory())!.path}/icons');
if (!iconsCacheDir.existsSync()) {
iconsCacheDir.createSync();
}
}
if (!isBg) {
// Load Apps into memory (in background processes, this is done later instead of in the constructor)
Expand Down Expand Up @@ -1297,10 +1307,16 @@ class AppsProvider with ChangeNotifier {
notifyListeners();
}

Future<void> updateAppIcon(String? appId) async {
Future<void> updateAppIcon(String? appId, {bool ignoreCache = false}) async {
if (apps[appId]?.icon == null) {
var icon =
(await apps[appId]?.installedInfo?.applicationInfo?.getAppIcon());
var cachedIcon = File('${iconsCacheDir.path}/$appId.png');
var alreadyCached = cachedIcon.existsSync() && !ignoreCache;
var icon = alreadyCached
? (await cachedIcon.readAsBytes())
: (await apps[appId]?.installedInfo?.applicationInfo?.getAppIcon());
if (icon != null && !alreadyCached) {
cachedIcon.writeAsBytes(icon.toList());
}
if (icon != null) {
apps.update(
apps[appId]!.app.id,
Expand Down
14 changes: 11 additions & 3 deletions lib/providers/source_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:obtainium/app_sources/sourceforge.dart';
import 'package:obtainium/app_sources/sourcehut.dart';
import 'package:obtainium/app_sources/steammobile.dart';
import 'package:obtainium/app_sources/telegramapp.dart';
import 'package:obtainium/app_sources/tencent.dart';
import 'package:obtainium/app_sources/uptodown.dart';
import 'package:obtainium/app_sources/vlc.dart';
import 'package:obtainium/app_sources/whatsapp.dart';
Expand Down Expand Up @@ -465,19 +466,25 @@ abstract class AppSource {

Future<Response> sourceRequest(
String url, Map<String, dynamic> additionalSettings,
{bool followRedirects = true}) async {
{bool followRedirects = true, Object? postBody}) async {
var requestHeaders = await getRequestHeaders(additionalSettings);
if (requestHeaders != null || followRedirects == false) {
var req = Request('GET', Uri.parse(url));
var req = Request(postBody == null ? 'GET' : 'POST', Uri.parse(url));
req.followRedirects = followRedirects;
if (requestHeaders != null) {
req.headers.addAll(requestHeaders);
}
if (postBody != null) {
req.headers[HttpHeaders.contentTypeHeader] = 'application/json';
req.body = jsonEncode(postBody);
}
return Response.fromStream(await IOClient(
createHttpClient(additionalSettings['allowInsecure'] == true))
.send(req));
} else {
return get(Uri.parse(url));
return postBody == null
? get(Uri.parse(url))
: post(Uri.parse(url), body: jsonEncode(postBody));
}
}

Expand Down Expand Up @@ -782,6 +789,7 @@ class SourceProvider {
Aptoide(),
Uptodown(),
HuaweiAppGallery(),
Tencent(),
Jenkins(),
APKMirror(),
Signal(),
Expand Down
64 changes: 32 additions & 32 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ packages:
dependency: "direct main"
description:
name: background_fetch
sha256: f910c1c7c67a55f242daf78e9e9835d26eb01d39fc7f5d77f57dd84d009a6bab
sha256: e9f26ae54d88310b7ac2a68f2f9fcee0081a4d5f11100f233a70702021e7ac4f
url: "https://pub.dev"
source: hosted
version: "1.3.6"
version: "1.3.7"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -303,18 +303,18 @@ packages:
dependency: "direct main"
description:
name: flex_color_picker
sha256: "809af4ec82ede3b140ed0219b97d548de99e47aa4b99b14a10f705a2dbbcba5e"
sha256: "12dc855ae8ef5491f529b1fc52c655f06dcdf4114f1f7fdecafa41eec2ec8d79"
url: "https://pub.dev"
source: hosted
version: "3.5.1"
version: "3.6.0"
flex_seed_scheme:
dependency: transitive
description:
name: flex_seed_scheme
sha256: "7d97ba5c20f0e5cb1e3e2c17c865e1f797d129de31fc1f75d2dcce9470d6373c"
sha256: "7639d2c86268eff84a909026eb169f008064af0fb3696a651b24b0fa24a40334"
url: "https://pub.dev"
source: hosted
version: "3.3.0"
version: "3.4.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -388,26 +388,26 @@ packages:
dependency: "direct dev"
description:
name: flutter_launcher_icons
sha256: "526faf84284b86a4cb36d20a5e45147747b7563d921373d4ee0559c54fcdbcea"
sha256: "619817c4b65b322b5104b6bb6dfe6cda62d9729bd7ad4303ecc8b4e690a67a77"
url: "https://pub.dev"
source: hosted
version: "0.13.1"
version: "0.14.1"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: c500d5d9e7e553f06b61877ca6b9c8b92c570a4c8db371038702e8ce57f8a50f
sha256: "49eeef364fddb71515bc78d5a8c51435a68bccd6e4d68e25a942c5e47761ae71"
url: "https://pub.dev"
source: hosted
version: "17.2.2"
version: "17.2.3"
flutter_local_notifications_linux:
dependency: transitive
description:
Expand All @@ -433,10 +433,10 @@ packages:
dependency: "direct main"
description:
name: flutter_markdown
sha256: a23c41ee57573e62fc2190a1f36a0480c4d90bde3a8a8d7126e5d5992fb53fb7
sha256: e17575ca576a34b46c58c91f9948891117a1bd97815d2e661813c7f90c647a78
url: "https://pub.dev"
source: hosted
version: "0.7.3+1"
version: "0.7.3+2"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
Expand Down Expand Up @@ -571,10 +571,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
markdown:
dependency: "direct main"
description:
Expand Down Expand Up @@ -723,10 +723,10 @@ packages:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: fe0ffe274d665be8e34f9c59705441a7d248edebbe5d9e3ec2665f88b79358ea
sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9
url: "https://pub.dev"
source: hosted
version: "4.2.2"
version: "4.2.3"
permission_handler_windows:
dependency: transitive
description:
Expand Down Expand Up @@ -913,18 +913,18 @@ packages:
dependency: "direct main"
description:
name: sqflite
sha256: a43e5a27235518c03ca238e7b4732cf35eabe863a369ceba6cbefa537a66f16d
sha256: ff5a2436ef8ebdfda748fbfe957f9981524cb5ff11e7bafa8c42771840e8a788
url: "https://pub.dev"
source: hosted
version: "2.3.3+1"
version: "2.3.3+2"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
sha256: "7b41b6c3507854a159e24ae90a8e3e9cc01eb26a477c118d6dca065b5f55453e"
sha256: "2d8e607db72e9cb7748c9c6e739e2c9618320a5517de693d5a24609c4671b1a4"
url: "https://pub.dev"
source: hosted
version: "2.5.4+2"
version: "2.5.4+4"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -953,10 +953,10 @@ packages:
dependency: transitive
description:
name: synchronized
sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255
sha256: "69fe30f3a8b04a0be0c15ae6490fc859a78ef4c43ae2dd5e8a623d45bfcf9225"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.3.0+3"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -1025,10 +1025,10 @@ packages:
dependency: transitive
description:
name: url_launcher_macos
sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de"
sha256: "769549c999acdb42b8bcfa7c43d72bf79a382ca7441ab18a808e101149daf672"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.2.1"
url_launcher_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -1057,10 +1057,10 @@ packages:
dependency: transitive
description:
name: uuid
sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
url: "https://pub.dev"
source: hosted
version: "4.5.0"
version: "4.5.1"
vector_math:
dependency: transitive
description:
Expand All @@ -1081,10 +1081,10 @@ packages:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
url: "https://pub.dev"
source: hosted
version: "1.0.0"
version: "1.1.0"
webview_flutter:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1129,10 +1129,10 @@ packages:
dependency: transitive
description:
name: win32_registry
sha256: "723b7f851e5724c55409bb3d5a32b203b3afe8587eaf5dafb93a5fed8ecda0d6"
sha256: "21ec76dfc731550fd3e2ce7a33a9ea90b828fdf19a5c3bcf556fa992cfa99852"
url: "https://pub.dev"
source: hosted
version: "1.1.4"
version: "1.1.5"
xdg_directories:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit 1e03194

Please sign in to comment.