Add vercel fallback for module repository for China Mainland users (#2362)
This commit is contained in:
parent
ebf5bba4d8
commit
e5281678a3
|
|
@ -76,7 +76,11 @@ public class RepoLoader {
|
|||
private final Path repoFile = Paths.get(App.getInstance().getFilesDir().getAbsolutePath(), "repo.json");
|
||||
private final Set<RepoListener> listeners = ConcurrentHashMap.newKeySet();
|
||||
private boolean repoLoaded = false;
|
||||
private static final String repoUrl = "https://modules.lsposed.org/";
|
||||
private static final String originRepoUrl = "https://modules.lsposed.org/";
|
||||
private static final String backupRepoUrl = "https://modules-vercel.lsposed.org/";
|
||||
|
||||
private static final String secondBackupRepoUrl = "https://modules-cloudflare.lsposed.org/";
|
||||
private static String repoUrl = originRepoUrl;
|
||||
private final Resources resources = App.getInstance().getResources();
|
||||
private final String[] channels = resources.getStringArray(R.array.update_channel_values);
|
||||
|
||||
|
|
@ -94,8 +98,8 @@ public class RepoLoader {
|
|||
|
||||
synchronized public void loadRemoteData() {
|
||||
repoLoaded = false;
|
||||
var request = new Request.Builder().url(repoUrl + "modules.json").build();
|
||||
try (var response = App.getOkHttpClient().newCall(request).execute()) {
|
||||
try {
|
||||
var response = App.getOkHttpClient().newCall(new Request.Builder().url(repoUrl + "modules.json").build()).execute();
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
ResponseBody body = response.body();
|
||||
|
|
@ -117,6 +121,13 @@ public class RepoLoader {
|
|||
for (RepoListener listener : listeners) {
|
||||
listener.onThrowable(e);
|
||||
}
|
||||
if (repoUrl.equals(originRepoUrl)) {
|
||||
repoUrl = backupRepoUrl;
|
||||
loadRemoteData();
|
||||
} else if (repoUrl.equals(backupRepoUrl)) {
|
||||
repoUrl = secondBackupRepoUrl;
|
||||
loadRemoteData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -240,10 +251,18 @@ public class RepoLoader {
|
|||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
Log.e(App.TAG, call.request().url() + e.getMessage());
|
||||
if (repoUrl.equals(originRepoUrl)) {
|
||||
repoUrl = backupRepoUrl;
|
||||
loadRemoteReleases(packageName);
|
||||
} else if (repoUrl.equals(backupRepoUrl)) {
|
||||
repoUrl = secondBackupRepoUrl;
|
||||
loadRemoteReleases(packageName);
|
||||
} else {
|
||||
for (RepoListener listener : listeners) {
|
||||
listener.onThrowable(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call call, @NonNull Response response) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue