Support Gitea repositories (#570)

This commit is contained in:
Logykk 2022-12-10 01:10:43 +13:00 committed by GitHub
parent e300c92215
commit 3bab1940c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 5 deletions

View file

@ -122,6 +122,7 @@
"englishOption": "English", "englishOption": "English",
"sourcesLabel": "Sources", "sourcesLabel": "Sources",
"sourcesLabelHint": "Configure your custom sources", "sourcesLabelHint": "Configure your custom sources",
"hostRepositoryLabel": "Repository API",
"orgPatchesLabel": "Patches organization", "orgPatchesLabel": "Patches organization",
"sourcesPatchesLabel": "Patches source", "sourcesPatchesLabel": "Patches source",
"orgIntegrationsLabel": "Integrations organization", "orgIntegrationsLabel": "Integrations organization",

View file

@ -25,7 +25,8 @@ Future main() async {
await locator<RevancedAPI>().initialize(apiUrl); await locator<RevancedAPI>().initialize(apiUrl);
await locator<CrowdinAPI>().initialize(); await locator<CrowdinAPI>().initialize();
bool isSentryEnabled = locator<ManagerAPI>().isSentryEnabled(); bool isSentryEnabled = locator<ManagerAPI>().isSentryEnabled();
locator<GithubAPI>().initialize(); String repoUrl = locator<ManagerAPI>().getRepoUrl();
locator<GithubAPI>().initialize(repoUrl);
await locator<PatcherAPI>().initialize(); await locator<PatcherAPI>().initialize();
tz.initializeTimeZones(); tz.initializeTimeZones();
prefs = await SharedPreferences.getInstance(); prefs = await SharedPreferences.getInstance();

View file

@ -28,10 +28,10 @@ class GithubAPI {
'com.spotify.music': 'spotify', 'com.spotify.music': 'spotify',
}; };
void initialize() async { void initialize(String repoUrl) async {
try { try {
_dio = Dio(BaseOptions( _dio = Dio(BaseOptions(
baseUrl: 'https://api.github.com', baseUrl: repoUrl,
)); ));
_dio.interceptors.add(_dioCacheManager.interceptor); _dio.interceptors.add(_dioCacheManager.interceptor);
@ -54,10 +54,10 @@ class GithubAPI {
Future<Map<String, dynamic>?> getLatestRelease(String repoName) async { Future<Map<String, dynamic>?> getLatestRelease(String repoName) async {
try { try {
var response = await _dio.get( var response = await _dio.get(
'/repos/$repoName/releases/latest', '/repos/$repoName/releases',
options: _cacheOptions, options: _cacheOptions,
); );
return response.data; return response.data[0];
} on Exception catch (e, s) { } on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s); await Sentry.captureException(e, stackTrace: s);
return null; return null;

View file

@ -23,6 +23,7 @@ class ManagerAPI {
late String storedPatchesFile = '/selected-patches.json'; late String storedPatchesFile = '/selected-patches.json';
late SharedPreferences _prefs; late SharedPreferences _prefs;
String defaultApiUrl = 'https://releases.revanced.app/'; String defaultApiUrl = 'https://releases.revanced.app/';
String defaultRepoUrl = 'https://api.github.com';
String defaultPatcherRepo = 'revanced/revanced-patcher'; String defaultPatcherRepo = 'revanced/revanced-patcher';
String defaultPatchesRepo = 'revanced/revanced-patches'; String defaultPatchesRepo = 'revanced/revanced-patches';
String defaultIntegrationsRepo = 'revanced/revanced-integrations'; String defaultIntegrationsRepo = 'revanced/revanced-integrations';
@ -48,6 +49,17 @@ class ManagerAPI {
await _prefs.setString('apiUrl', url); await _prefs.setString('apiUrl', url);
} }
String getRepoUrl() {
return _prefs.getString('repoUrl') ?? defaultRepoUrl;
}
Future<void> setRepoUrl(String url) async {
if (url.isEmpty || url == ' ') {
url = defaultRepoUrl;
}
await _prefs.setString('repoUrl', url);
}
String getPatchesRepo() { String getPatchesRepo() {
return _prefs.getString('patchesRepo') ?? defaultPatchesRepo; return _prefs.getString('patchesRepo') ?? defaultPatchesRepo;
} }

View file

@ -12,14 +12,17 @@ import 'package:stacked/stacked.dart';
class SManageSources extends BaseViewModel { class SManageSources extends BaseViewModel {
final ManagerAPI _managerAPI = locator<ManagerAPI>(); final ManagerAPI _managerAPI = locator<ManagerAPI>();
final TextEditingController _hostSourceController = TextEditingController();
final TextEditingController _orgPatSourceController = TextEditingController(); final TextEditingController _orgPatSourceController = TextEditingController();
final TextEditingController _patSourceController = TextEditingController(); final TextEditingController _patSourceController = TextEditingController();
final TextEditingController _orgIntSourceController = TextEditingController(); final TextEditingController _orgIntSourceController = TextEditingController();
final TextEditingController _intSourceController = TextEditingController(); final TextEditingController _intSourceController = TextEditingController();
Future<void> showSourcesDialog(BuildContext context) async { Future<void> showSourcesDialog(BuildContext context) async {
String hostRepository = _managerAPI.getRepoUrl();
String patchesRepo = _managerAPI.getPatchesRepo(); String patchesRepo = _managerAPI.getPatchesRepo();
String integrationsRepo = _managerAPI.getIntegrationsRepo(); String integrationsRepo = _managerAPI.getIntegrationsRepo();
_hostSourceController.text = hostRepository;
_orgPatSourceController.text = patchesRepo.split('/')[0]; _orgPatSourceController.text = patchesRepo.split('/')[0];
_patSourceController.text = patchesRepo.split('/')[1]; _patSourceController.text = patchesRepo.split('/')[1];
_orgIntSourceController.text = integrationsRepo.split('/')[0]; _orgIntSourceController.text = integrationsRepo.split('/')[0];
@ -42,6 +45,17 @@ class SManageSources extends BaseViewModel {
content: SingleChildScrollView( content: SingleChildScrollView(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
CustomTextField(
leadingIcon: const Icon(
Icons.extension_outlined,
color: Colors.transparent,
),
inputController: _hostSourceController,
label: I18nText('settingsView.hostRepositoryLabel'),
hint: hostRepository,
onChanged: (value) => notifyListeners(),
),
const SizedBox(height: 20),
CustomTextField( CustomTextField(
leadingIcon: Icon( leadingIcon: Icon(
Icons.extension_outlined, Icons.extension_outlined,
@ -103,6 +117,7 @@ class SManageSources extends BaseViewModel {
CustomMaterialButton( CustomMaterialButton(
label: I18nText('okButton'), label: I18nText('okButton'),
onPressed: () { onPressed: () {
_managerAPI.setRepoUrl(_hostSourceController.text);
_managerAPI.setPatchesRepo( _managerAPI.setPatchesRepo(
'${_orgPatSourceController.text}/${_patSourceController.text}', '${_orgPatSourceController.text}/${_patSourceController.text}',
); );
@ -133,10 +148,12 @@ class SManageSources extends BaseViewModel {
CustomMaterialButton( CustomMaterialButton(
label: I18nText('yesButton'), label: I18nText('yesButton'),
onPressed: () { onPressed: () {
_managerAPI.setRepoUrl('');
_managerAPI.setPatchesRepo(''); _managerAPI.setPatchesRepo('');
_managerAPI.setIntegrationsRepo(''); _managerAPI.setIntegrationsRepo('');
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pop();
}, },
) )
], ],