Skip to content

Commit

Permalink
feat: Add API migration code (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jan 9, 2024
1 parent edd8602 commit 28ae276
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,6 +24,7 @@ import 'package:timeago/timeago.dart';
class ManagerAPI {
final RevancedAPI _revancedAPI = locator<RevancedAPI>();
final GithubAPI _githubAPI = locator<GithubAPI>();
final Toast _toast = locator<Toast>();
final RootAPI _rootAPI = RootAPI();
final String patcherRepo = 'revanced-patcher';
final String cliRepo = 'revanced-cli';
Expand Down Expand Up @@ -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<int> getSdkVersion() async {
Expand All @@ -82,6 +94,7 @@ class ManagerAPI {
}
await _revancedAPI.clearAllCache();
await _prefs.setString('apiUrl', url);
_toast.showBottom('settingsView.restartAppForChanges');
}

String getRepoUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:stacked/stacked.dart';

class SManageApiUrl extends BaseViewModel {
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final Toast _toast = locator<Toast>();

final TextEditingController _apiUrlController = TextEditingController();

Expand Down Expand Up @@ -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'),
Expand All @@ -90,7 +88,6 @@ class SManageApiUrl extends BaseViewModel {
FilledButton(
onPressed: () {
_managerAPI.setApiUrl('');
_toast.showBottom('settingsView.restartAppForChanges');
Navigator.of(context)
..pop()
..pop();
Expand Down

0 comments on commit 28ae276

Please sign in to comment.