feat: sentry integration.

This commit is contained in:
Aunali321
2022-10-14 23:35:33 +05:30
parent 007b518503
commit f1261398e9
12 changed files with 329 additions and 186 deletions

View File

@@ -8,6 +8,8 @@ import 'package:injectable/injectable.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/utils/check_for_gms.dart';
import 'package:timeago/timeago.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_dio/sentry_dio.dart';
@lazySingleton
class RevancedAPI {
@@ -19,25 +21,36 @@ class RevancedAPI {
);
Future<void> initialize(String apiUrl) async {
bool isGMSInstalled = await checkForGMS();
try {
bool isGMSInstalled = await checkForGMS();
if (!isGMSInstalled) {
_dio = Dio(BaseOptions(
baseUrl: apiUrl,
));
print('ReVanced API: Using default engine + $isGMSInstalled');
} else {
_dio = Dio(BaseOptions(
baseUrl: apiUrl,
))
..httpClientAdapter = NativeAdapter();
print('ReVanced API: Using CronetEngine + $isGMSInstalled');
if (!isGMSInstalled) {
_dio = Dio(BaseOptions(
baseUrl: apiUrl,
));
print('ReVanced API: Using default engine + $isGMSInstalled');
} else {
_dio = Dio(BaseOptions(
baseUrl: apiUrl,
))
..httpClientAdapter = NativeAdapter();
print('ReVanced API: Using CronetEngine + $isGMSInstalled');
}
_dio.interceptors.add(_dioCacheManager.interceptor);
_dio.addSentry(
captureFailedRequests: true,
);
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
}
_dio.interceptors.add(_dioCacheManager.interceptor);
}
Future<void> clearAllCache() async {
await _dioCacheManager.clearAll();
try {
await _dioCacheManager.clearAll();
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
}
}
Future<Map<String, List<dynamic>>> getContributors() async {
@@ -49,7 +62,8 @@ class RevancedAPI {
String name = repo['name'];
contributors[name] = repo['contributors'];
}
} on Exception {
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return {};
}
return contributors;
@@ -60,7 +74,8 @@ class RevancedAPI {
var response = await _dio.get('/patches', options: _cacheOptions);
List<dynamic> patches = response.data;
return patches.map((patch) => Patch.fromJson(patch)).toList();
} on Exception {
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return List.empty();
}
}
@@ -77,7 +92,8 @@ class RevancedAPI {
t['repository'] == repoName &&
(t['name'] as String).endsWith(extension),
);
} on Exception {
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
}
@@ -94,7 +110,8 @@ class RevancedAPI {
if (release != null) {
return release['version'];
}
} on Exception {
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
return null;
@@ -110,7 +127,8 @@ class RevancedAPI {
String url = release['browser_download_url'];
return await DefaultCacheManager().getSingleFile(url);
}
} on Exception {
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
return null;
@@ -129,7 +147,8 @@ class RevancedAPI {
DateTime timestamp = DateTime.parse(release['timestamp'] as String);
return format(timestamp, locale: 'en_short');
}
} on Exception {
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
return null;