diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 17072b0417..c4a7ccd514 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -15,6 +15,7 @@ import 'package:revanced_manager/services/github_api.dart'; import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/revanced_api.dart'; import 'package:revanced_manager/services/root_api.dart'; +import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/utils/check_for_supported_patch.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:timeago/timeago.dart'; @@ -23,6 +24,7 @@ import 'package:timeago/timeago.dart'; class ManagerAPI { final RevancedAPI _revancedAPI = locator(); final GithubAPI _githubAPI = locator(); + final Toast _toast = locator(); final RootAPI _rootAPI = RootAPI(); final String patcherRepo = 'revanced-patcher'; final String cliRepo = 'revanced-cli'; @@ -65,6 +67,16 @@ class ManagerAPI { (await getSdkVersion()) >= 31; // ANDROID_12_SDK_VERSION = 31 storedPatchesFile = (await getApplicationDocumentsDirectory()).path + storedPatchesFile; + + // Migrate to new API URL if not done yet as the old one is sunset. + final bool hasMigrated = _prefs.getBool('migratedToNewApiUrl') ?? false; + if (!hasMigrated) { + final String apiUrl = getApiUrl().toLowerCase(); + if (apiUrl.contains('releases.revanced.app')) { + await setApiUrl(''); // Reset to default. + _prefs.setBool('migratedToNewApiUrl', true); + } + } } Future getSdkVersion() async { @@ -82,6 +94,7 @@ class ManagerAPI { } await _revancedAPI.clearAllCache(); await _prefs.setString('apiUrl', url); + _toast.showBottom('settingsView.restartAppForChanges'); } String getRepoUrl() { diff --git a/lib/ui/views/settings/settingsFragment/settings_manage_api_url.dart b/lib/ui/views/settings/settingsFragment/settings_manage_api_url.dart index 899f49bc1e..20d2ef2b64 100644 --- a/lib/ui/views/settings/settingsFragment/settings_manage_api_url.dart +++ b/lib/ui/views/settings/settingsFragment/settings_manage_api_url.dart @@ -10,7 +10,6 @@ import 'package:stacked/stacked.dart'; class SManageApiUrl extends BaseViewModel { final ManagerAPI _managerAPI = locator(); - final Toast _toast = locator(); final TextEditingController _apiUrlController = TextEditingController(); @@ -66,7 +65,6 @@ class SManageApiUrl extends BaseViewModel { apiUrl = 'https://$apiUrl'; } _managerAPI.setApiUrl(apiUrl); - _toast.showBottom('settingsView.restartAppForChanges'); Navigator.of(context).pop(); }, child: I18nText('okButton'), @@ -90,7 +88,6 @@ class SManageApiUrl extends BaseViewModel { FilledButton( onPressed: () { _managerAPI.setApiUrl(''); - _toast.showBottom('settingsView.restartAppForChanges'); Navigator.of(context) ..pop() ..pop();