mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 20:57:36 +02:00
fix: use singletons to enable cache and remove debug messages
This commit is contained in:
@ -5,16 +5,17 @@ import 'package:collection/collection.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio_http_cache_lts/dio_http_cache_lts.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
|
||||
@lazySingleton
|
||||
class GithubAPI {
|
||||
final String apiUrl = 'https://api.github.com';
|
||||
final Dio _dio = Dio();
|
||||
final DioCacheManager _dioCacheManager = DioCacheManager(
|
||||
CacheConfig(
|
||||
defaultMaxAge: const Duration(hours: 1),
|
||||
defaultMaxStale: const Duration(days: 7),
|
||||
),
|
||||
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
|
||||
final Options _cacheOptions = buildCacheOptions(
|
||||
const Duration(hours: 1),
|
||||
maxStale: const Duration(days: 7),
|
||||
);
|
||||
final Map<String, String> repoAppPath = {
|
||||
'com.google.android.youtube': 'youtube',
|
||||
@ -38,13 +39,8 @@ class GithubAPI {
|
||||
try {
|
||||
var response = await _dio.get(
|
||||
'$apiUrl/repos/$repoName/releases/latest',
|
||||
options: buildCacheOptions(const Duration(hours: 1)),
|
||||
options: _cacheOptions,
|
||||
);
|
||||
if (response.headers.value(DIO_CACHE_HEADER_KEY_DATA_SOURCE) != null) {
|
||||
print('1 - From cache');
|
||||
} else {
|
||||
print('1 - From net');
|
||||
}
|
||||
return response.data;
|
||||
} on Exception {
|
||||
// ignore
|
||||
@ -67,13 +63,8 @@ class GithubAPI {
|
||||
'per_page': 3,
|
||||
'since': since.toIso8601String(),
|
||||
},
|
||||
options: buildCacheOptions(const Duration(hours: 1)),
|
||||
options: _cacheOptions,
|
||||
);
|
||||
if (response.headers.value(DIO_CACHE_HEADER_KEY_DATA_SOURCE) != null) {
|
||||
print('2 - From cache');
|
||||
} else {
|
||||
print('2 - From net');
|
||||
}
|
||||
List<dynamic> commits = response.data;
|
||||
return commits
|
||||
.map((commit) =>
|
||||
|
@ -3,6 +3,7 @@ import 'dart:io';
|
||||
import 'package:device_apps/device_apps.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
@ -12,8 +13,8 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ManagerAPI {
|
||||
final RevancedAPI _revancedAPI = RevancedAPI();
|
||||
final GithubAPI _githubAPI = GithubAPI();
|
||||
final RevancedAPI _revancedAPI = locator<RevancedAPI>();
|
||||
final GithubAPI _githubAPI = locator<GithubAPI>();
|
||||
final RootAPI _rootAPI = RootAPI();
|
||||
final String patcherRepo = 'revanced-patcher';
|
||||
final String cliRepo = 'revanced-cli';
|
||||
|
@ -14,7 +14,7 @@ class RevancedAPI {
|
||||
final Dio _dio = Dio();
|
||||
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
|
||||
final Options _cacheOptions = buildCacheOptions(
|
||||
const Duration(minutes: 10),
|
||||
const Duration(hours: 1),
|
||||
maxStale: const Duration(days: 7),
|
||||
);
|
||||
|
||||
@ -33,11 +33,6 @@ class RevancedAPI {
|
||||
'$apiUrl/contributors',
|
||||
options: _cacheOptions,
|
||||
);
|
||||
if (response.headers.value(DIO_CACHE_HEADER_KEY_DATA_SOURCE) != null) {
|
||||
print('3 - From cache');
|
||||
} else {
|
||||
print('3 - From net');
|
||||
}
|
||||
List<dynamic> repositories = response.data['repositories'];
|
||||
for (Map<String, dynamic> repo in repositories) {
|
||||
String name = repo['name'];
|
||||
@ -52,11 +47,6 @@ class RevancedAPI {
|
||||
Future<List<Patch>> getPatches() async {
|
||||
try {
|
||||
var response = await _dio.get('$apiUrl/patches', options: _cacheOptions);
|
||||
if (response.headers.value(DIO_CACHE_HEADER_KEY_DATA_SOURCE) != null) {
|
||||
print('4 - From cache');
|
||||
} else {
|
||||
print('4 - From net');
|
||||
}
|
||||
List<dynamic> patches = response.data;
|
||||
return patches.map((patch) => Patch.fromJson(patch)).toList();
|
||||
} on Exception {
|
||||
@ -71,11 +61,6 @@ class RevancedAPI {
|
||||
) async {
|
||||
try {
|
||||
var response = await _dio.get('$apiUrl/tools', options: _cacheOptions);
|
||||
if (response.headers.value(DIO_CACHE_HEADER_KEY_DATA_SOURCE) != null) {
|
||||
print('5 - From cache');
|
||||
} else {
|
||||
print('5 - From net');
|
||||
}
|
||||
List<dynamic> tools = response.data['tools'];
|
||||
return tools.firstWhereOrNull(
|
||||
(t) =>
|
||||
|
Reference in New Issue
Block a user