-
-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EXPERIMENTAL language switching.
- Loading branch information
Showing
6 changed files
with
135 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,3 +136,4 @@ app.*.map.json | |
|
||
Firebase related | ||
.firebase | ||
/lib/utils/environment.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:dio_http_cache_lts/dio_http_cache_lts.dart'; | ||
import 'package:injectable/injectable.dart' hide Environment; | ||
import 'package:revanced_manager/utils/environment.dart'; | ||
import 'package:sentry_dio/sentry_dio.dart'; | ||
import 'package:sentry_flutter/sentry_flutter.dart'; | ||
|
||
@lazySingleton | ||
class CrowdinAPI { | ||
late Dio _dio = Dio(); | ||
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig()); | ||
final apiKey = Environment.crowdinKEY; | ||
|
||
Future<void> initialize() async { | ||
try { | ||
_dio = Dio(BaseOptions( | ||
baseUrl: 'https://api.crowdin.com/api/v2', | ||
)); | ||
|
||
_dio.interceptors.add(_dioCacheManager.interceptor); | ||
_dio.addSentry( | ||
captureFailedRequests: true, | ||
); | ||
} on Exception catch (e, s) { | ||
await Sentry.captureException(e, stackTrace: s); | ||
} | ||
} | ||
|
||
Future<void> clearAllCache() async { | ||
try { | ||
await _dioCacheManager.clearAll(); | ||
} on Exception catch (e, s) { | ||
await Sentry.captureException(e, stackTrace: s); | ||
} | ||
} | ||
|
||
Future<List> getLanguages() async { | ||
try { | ||
var response = await _dio.get( | ||
'/projects', | ||
options: buildCacheOptions( | ||
const Duration(hours: 6), | ||
maxStale: const Duration(days: 1), | ||
options: Options( | ||
headers: { | ||
'Authorization': 'Bearer $apiKey', | ||
}, | ||
contentType: 'application/json', | ||
), | ||
), | ||
); | ||
List targetLanguages = | ||
await response.data['data'][0]['data']['targetLanguages']; | ||
|
||
return targetLanguages; | ||
} on Exception catch (e, s) { | ||
await Sentry.captureException(e, stackTrace: s); | ||
return []; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
be77a18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)