mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-04-30 05:54:26 +02:00
feat: Custom api endpoints. (#216)
Co-authored-by: Alberto Ponces <ponces26@gmail.com>
This commit is contained in:
parent
a9f64e449b
commit
c5ad337daa
@ -97,6 +97,7 @@
|
|||||||
"patcherSectionTitle": "Patcher",
|
"patcherSectionTitle": "Patcher",
|
||||||
"teamSectionTitle": "Team",
|
"teamSectionTitle": "Team",
|
||||||
"infoSectionTitle": "Info",
|
"infoSectionTitle": "Info",
|
||||||
|
"advancedSectionTitle": "Advanced",
|
||||||
"darkThemeLabel": "Dark Mode",
|
"darkThemeLabel": "Dark Mode",
|
||||||
"darkThemeHint": "Welcome to the Dark Side",
|
"darkThemeHint": "Welcome to the Dark Side",
|
||||||
"dynamicThemeLabel": "Material You",
|
"dynamicThemeLabel": "Material You",
|
||||||
@ -112,10 +113,14 @@
|
|||||||
"sourcesIntegrationsLabel": "Integrations Source",
|
"sourcesIntegrationsLabel": "Integrations Source",
|
||||||
"sourcesResetDialogTitle": "Reset",
|
"sourcesResetDialogTitle": "Reset",
|
||||||
"sourcesResetDialogText": "Are you sure you want to reset custom sources to their default values?",
|
"sourcesResetDialogText": "Are you sure you want to reset custom sources to their default values?",
|
||||||
|
"apiURLResetDialogText": "Are you sure you want to reset API URL to their default values?",
|
||||||
"contributorsLabel": "Contributors",
|
"contributorsLabel": "Contributors",
|
||||||
"contributorsHint": "A list of contributors of ReVanced",
|
"contributorsHint": "A list of contributors of ReVanced",
|
||||||
"logsLabel": "Logs",
|
"logsLabel": "Logs",
|
||||||
"logsHint": "Share device debug logs",
|
"logsHint": "Share device debug logs",
|
||||||
|
"apiURLLabel": "API URL",
|
||||||
|
"apiURLHint": "Configure your custom API URL",
|
||||||
|
"selectApiURL": "Select URL",
|
||||||
"aboutLabel": "About",
|
"aboutLabel": "About",
|
||||||
"snackbarMessage": "Copied to clipboard"
|
"snackbarMessage": "Copied to clipboard"
|
||||||
},
|
},
|
||||||
|
@ -19,6 +19,7 @@ class ManagerAPI {
|
|||||||
final String patcherRepo = 'revanced-patcher';
|
final String patcherRepo = 'revanced-patcher';
|
||||||
final String cliRepo = 'revanced-cli';
|
final String cliRepo = 'revanced-cli';
|
||||||
late SharedPreferences _prefs;
|
late SharedPreferences _prefs;
|
||||||
|
String defaultApiUrl = 'https://revanced-releases-api.afterst0rm.xyz';
|
||||||
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';
|
||||||
@ -29,6 +30,17 @@ class ManagerAPI {
|
|||||||
_prefs = await SharedPreferences.getInstance();
|
_prefs = await SharedPreferences.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getApiUrl() {
|
||||||
|
return _prefs.getString('apiUrl') ?? defaultApiUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setApiUrl(String url) async {
|
||||||
|
if (url.isEmpty || url == ' ') {
|
||||||
|
url = defaultApiUrl;
|
||||||
|
}
|
||||||
|
await _prefs.setString('apiUrl', url);
|
||||||
|
}
|
||||||
|
|
||||||
String getPatchesRepo() {
|
String getPatchesRepo() {
|
||||||
return _prefs.getString('patchesRepo') ?? defaultPatchesRepo;
|
return _prefs.getString('patchesRepo') ?? defaultPatchesRepo;
|
||||||
}
|
}
|
||||||
@ -106,21 +118,26 @@ class ManagerAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, List<dynamic>>> getContributors() async {
|
Future<Map<String, List<dynamic>>> getContributors() async {
|
||||||
return await _revancedAPI.getContributors();
|
String apiUrl = getApiUrl();
|
||||||
|
return await _revancedAPI.getContributors(apiUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Patch>> getPatches() async {
|
Future<List<Patch>> getPatches() async {
|
||||||
if (getPatchesRepo() == defaultPatchesRepo) {
|
String repoName = getPatchesRepo();
|
||||||
return await _revancedAPI.getPatches();
|
if (repoName == defaultPatchesRepo) {
|
||||||
|
String apiUrl = getApiUrl();
|
||||||
|
return await _revancedAPI.getPatches(apiUrl);
|
||||||
} else {
|
} else {
|
||||||
return await _githubAPI.getPatches(getPatchesRepo());
|
return await _githubAPI.getPatches(repoName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File?> downloadPatches() async {
|
Future<File?> downloadPatches() async {
|
||||||
String repoName = getPatchesRepo();
|
String repoName = getPatchesRepo();
|
||||||
if (repoName == defaultPatchesRepo) {
|
if (repoName == defaultPatchesRepo) {
|
||||||
|
String apiUrl = getApiUrl();
|
||||||
return await _revancedAPI.getLatestReleaseFile(
|
return await _revancedAPI.getLatestReleaseFile(
|
||||||
|
apiUrl,
|
||||||
'.jar',
|
'.jar',
|
||||||
defaultPatchesRepo,
|
defaultPatchesRepo,
|
||||||
);
|
);
|
||||||
@ -132,7 +149,9 @@ class ManagerAPI {
|
|||||||
Future<File?> downloadIntegrations() async {
|
Future<File?> downloadIntegrations() async {
|
||||||
String repoName = getIntegrationsRepo();
|
String repoName = getIntegrationsRepo();
|
||||||
if (repoName == defaultIntegrationsRepo) {
|
if (repoName == defaultIntegrationsRepo) {
|
||||||
|
String apiUrl = getApiUrl();
|
||||||
return await _revancedAPI.getLatestReleaseFile(
|
return await _revancedAPI.getLatestReleaseFile(
|
||||||
|
apiUrl,
|
||||||
'.apk',
|
'.apk',
|
||||||
defaultIntegrationsRepo,
|
defaultIntegrationsRepo,
|
||||||
);
|
);
|
||||||
@ -142,19 +161,36 @@ class ManagerAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<File?> downloadManager() async {
|
Future<File?> downloadManager() async {
|
||||||
return await _revancedAPI.getLatestReleaseFile('.apk', defaultManagerRepo);
|
String apiUrl = getApiUrl();
|
||||||
|
return await _revancedAPI.getLatestReleaseFile(
|
||||||
|
apiUrl,
|
||||||
|
'.apk',
|
||||||
|
defaultManagerRepo,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getLatestPatcherReleaseTime() async {
|
Future<String?> getLatestPatcherReleaseTime() async {
|
||||||
return await _revancedAPI.getLatestReleaseTime('.gz', defaultPatcherRepo);
|
String apiUrl = getApiUrl();
|
||||||
|
return await _revancedAPI.getLatestReleaseTime(
|
||||||
|
apiUrl,
|
||||||
|
'.gz',
|
||||||
|
defaultPatcherRepo,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getLatestManagerReleaseTime() async {
|
Future<String?> getLatestManagerReleaseTime() async {
|
||||||
return await _revancedAPI.getLatestReleaseTime('.apk', defaultManagerRepo);
|
String apiUrl = getApiUrl();
|
||||||
|
return await _revancedAPI.getLatestReleaseTime(
|
||||||
|
apiUrl,
|
||||||
|
'.apk',
|
||||||
|
defaultManagerRepo,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getLatestManagerVersion() async {
|
Future<String?> getLatestManagerVersion() async {
|
||||||
|
String apiUrl = getApiUrl();
|
||||||
return await _revancedAPI.getLatestReleaseVersion(
|
return await _revancedAPI.getLatestReleaseVersion(
|
||||||
|
apiUrl,
|
||||||
'.apk',
|
'.apk',
|
||||||
defaultManagerRepo,
|
defaultManagerRepo,
|
||||||
);
|
);
|
||||||
|
@ -9,7 +9,6 @@ import 'package:timeago/timeago.dart';
|
|||||||
|
|
||||||
@lazySingleton
|
@lazySingleton
|
||||||
class RevancedAPI {
|
class RevancedAPI {
|
||||||
final String apiUrl = 'https://revanced-releases-api.afterst0rm.xyz';
|
|
||||||
final Dio _dio = Dio();
|
final Dio _dio = Dio();
|
||||||
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
|
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
|
||||||
final Options _cacheOptions = buildCacheOptions(
|
final Options _cacheOptions = buildCacheOptions(
|
||||||
@ -17,7 +16,7 @@ class RevancedAPI {
|
|||||||
maxStale: const Duration(days: 7),
|
maxStale: const Duration(days: 7),
|
||||||
);
|
);
|
||||||
|
|
||||||
void initialize() {
|
Future<void> initialize() async {
|
||||||
_dio.interceptors.add(_dioCacheManager.interceptor);
|
_dio.interceptors.add(_dioCacheManager.interceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ class RevancedAPI {
|
|||||||
await _dioCacheManager.clearAll();
|
await _dioCacheManager.clearAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, List<dynamic>>> getContributors() async {
|
Future<Map<String, List<dynamic>>> getContributors(String apiUrl) async {
|
||||||
Map<String, List<dynamic>> contributors = {};
|
Map<String, List<dynamic>> contributors = {};
|
||||||
try {
|
try {
|
||||||
var response = await _dio.get(
|
var response = await _dio.get(
|
||||||
@ -43,7 +42,7 @@ class RevancedAPI {
|
|||||||
return contributors;
|
return contributors;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Patch>> getPatches() async {
|
Future<List<Patch>> getPatches(String apiUrl) async {
|
||||||
try {
|
try {
|
||||||
var response = await _dio.get('$apiUrl/patches', options: _cacheOptions);
|
var response = await _dio.get('$apiUrl/patches', options: _cacheOptions);
|
||||||
List<dynamic> patches = response.data;
|
List<dynamic> patches = response.data;
|
||||||
@ -54,6 +53,7 @@ class RevancedAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>?> _getLatestRelease(
|
Future<Map<String, dynamic>?> _getLatestRelease(
|
||||||
|
String apiUrl,
|
||||||
String extension,
|
String extension,
|
||||||
String repoName,
|
String repoName,
|
||||||
) async {
|
) async {
|
||||||
@ -71,10 +71,13 @@ class RevancedAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getLatestReleaseVersion(
|
Future<String?> getLatestReleaseVersion(
|
||||||
String extension, String repoName) async {
|
String apiUrl,
|
||||||
|
String extension,
|
||||||
|
String repoName,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic>? release =
|
Map<String, dynamic>? release =
|
||||||
await _getLatestRelease(extension, repoName);
|
await _getLatestRelease(apiUrl, extension, repoName);
|
||||||
if (release != null) {
|
if (release != null) {
|
||||||
return release['version'];
|
return release['version'];
|
||||||
}
|
}
|
||||||
@ -84,9 +87,14 @@ class RevancedAPI {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File?> getLatestReleaseFile(String extension, String repoName) async {
|
Future<File?> getLatestReleaseFile(
|
||||||
|
String apiUrl,
|
||||||
|
String extension,
|
||||||
|
String repoName,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic>? release = await _getLatestRelease(
|
Map<String, dynamic>? release = await _getLatestRelease(
|
||||||
|
apiUrl,
|
||||||
extension,
|
extension,
|
||||||
repoName,
|
repoName,
|
||||||
);
|
);
|
||||||
@ -101,11 +109,13 @@ class RevancedAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getLatestReleaseTime(
|
Future<String?> getLatestReleaseTime(
|
||||||
|
String apiUrl,
|
||||||
String extension,
|
String extension,
|
||||||
String repoName,
|
String repoName,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic>? release = await _getLatestRelease(
|
Map<String, dynamic>? release = await _getLatestRelease(
|
||||||
|
apiUrl,
|
||||||
extension,
|
extension,
|
||||||
repoName,
|
repoName,
|
||||||
);
|
);
|
||||||
|
@ -145,6 +145,17 @@ class SettingsView extends StatelessWidget {
|
|||||||
const AboutWidget(),
|
const AboutWidget(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
const Divider(thickness: 1.0),
|
||||||
|
SettingsSection(
|
||||||
|
title: 'settingsView.advancedSectionTitle',
|
||||||
|
children: <Widget>[
|
||||||
|
SettingsTileDialog(
|
||||||
|
title: 'settingsView.apiURLLabel',
|
||||||
|
subtitle: 'settingsView.apiURLHint',
|
||||||
|
onTap: () => model.showApiUrlDialog(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -27,6 +27,7 @@ class SettingsViewModel extends BaseViewModel {
|
|||||||
final TextEditingController _patSourceController = TextEditingController();
|
final TextEditingController _patSourceController = TextEditingController();
|
||||||
final TextEditingController _orgIntSourceController = TextEditingController();
|
final TextEditingController _orgIntSourceController = TextEditingController();
|
||||||
final TextEditingController _intSourceController = TextEditingController();
|
final TextEditingController _intSourceController = TextEditingController();
|
||||||
|
final TextEditingController _apiUrlController = TextEditingController();
|
||||||
|
|
||||||
void setLanguage(String language) {
|
void setLanguage(String language) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -208,6 +209,65 @@ class SettingsViewModel extends BaseViewModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> showApiUrlDialog(BuildContext context) async {
|
||||||
|
String apiUrl = _managerAPI.getApiUrl();
|
||||||
|
_apiUrlController.text = apiUrl.replaceAll('https://', '');
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
I18nText('settingsView.apiURLLabel'),
|
||||||
|
const Spacer(),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.manage_history_outlined),
|
||||||
|
onPressed: () => showApiUrlResetDialog(context),
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
CustomTextField(
|
||||||
|
leadingIcon: Icon(
|
||||||
|
Icons.api_outlined,
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
),
|
||||||
|
inputController: _apiUrlController,
|
||||||
|
label: I18nText('settingsView.selectApiURL'),
|
||||||
|
hint: apiUrl.split('/')[0],
|
||||||
|
onChanged: (value) => notifyListeners(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
CustomMaterialButton(
|
||||||
|
isFilled: false,
|
||||||
|
label: I18nText('cancelButton'),
|
||||||
|
onPressed: () {
|
||||||
|
_apiUrlController.clear();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
CustomMaterialButton(
|
||||||
|
label: I18nText('okButton'),
|
||||||
|
onPressed: () {
|
||||||
|
String apiUrl = _apiUrlController.text;
|
||||||
|
if (!apiUrl.startsWith('https')) {
|
||||||
|
apiUrl = 'https://$apiUrl';
|
||||||
|
}
|
||||||
|
_managerAPI.setApiUrl(apiUrl);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> showResetConfirmationDialog(BuildContext context) async {
|
Future<void> showResetConfirmationDialog(BuildContext context) async {
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -235,6 +295,32 @@ class SettingsViewModel extends BaseViewModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> showApiUrlResetDialog(BuildContext context) async {
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: I18nText('settingsView.sourcesResetDialogTitle'),
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
|
content: I18nText('settingsView.apiURLResetDialogText'),
|
||||||
|
actions: <Widget>[
|
||||||
|
CustomMaterialButton(
|
||||||
|
isFilled: false,
|
||||||
|
label: I18nText('cancelButton'),
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
),
|
||||||
|
CustomMaterialButton(
|
||||||
|
label: I18nText('okButton'),
|
||||||
|
onPressed: () {
|
||||||
|
_managerAPI.setApiUrl('');
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<int> getSdkVersion() async {
|
Future<int> getSdkVersion() async {
|
||||||
AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo;
|
AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo;
|
||||||
return info.version.sdkInt ?? -1;
|
return info.version.sdkInt ?? -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user