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 Path repoFile = Paths.get(App.getInstance().getFilesDir().getAbsolutePath(), "repo.json");
|
||||||
private final Set<RepoListener> listeners = ConcurrentHashMap.newKeySet();
|
private final Set<RepoListener> listeners = ConcurrentHashMap.newKeySet();
|
||||||
private boolean repoLoaded = false;
|
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 Resources resources = App.getInstance().getResources();
|
||||||
private final String[] channels = resources.getStringArray(R.array.update_channel_values);
|
private final String[] channels = resources.getStringArray(R.array.update_channel_values);
|
||||||
|
|
||||||
|
|
@ -94,8 +98,8 @@ public class RepoLoader {
|
||||||
|
|
||||||
synchronized public void loadRemoteData() {
|
synchronized public void loadRemoteData() {
|
||||||
repoLoaded = false;
|
repoLoaded = false;
|
||||||
var request = new Request.Builder().url(repoUrl + "modules.json").build();
|
try {
|
||||||
try (var response = App.getOkHttpClient().newCall(request).execute()) {
|
var response = App.getOkHttpClient().newCall(new Request.Builder().url(repoUrl + "modules.json").build()).execute();
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
ResponseBody body = response.body();
|
ResponseBody body = response.body();
|
||||||
|
|
@ -117,6 +121,13 @@ public class RepoLoader {
|
||||||
for (RepoListener listener : listeners) {
|
for (RepoListener listener : listeners) {
|
||||||
listener.onThrowable(e);
|
listener.onThrowable(e);
|
||||||
}
|
}
|
||||||
|
if (repoUrl.equals(originRepoUrl)) {
|
||||||
|
repoUrl = backupRepoUrl;
|
||||||
|
loadRemoteData();
|
||||||
|
} else if (repoUrl.equals(backupRepoUrl)) {
|
||||||
|
repoUrl = secondBackupRepoUrl;
|
||||||
|
loadRemoteData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,8 +251,16 @@ public class RepoLoader {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||||
Log.e(App.TAG, call.request().url() + e.getMessage());
|
Log.e(App.TAG, call.request().url() + e.getMessage());
|
||||||
for (RepoListener listener : listeners) {
|
if (repoUrl.equals(originRepoUrl)) {
|
||||||
listener.onThrowable(e);
|
repoUrl = backupRepoUrl;
|
||||||
|
loadRemoteReleases(packageName);
|
||||||
|
} else if (repoUrl.equals(backupRepoUrl)) {
|
||||||
|
repoUrl = secondBackupRepoUrl;
|
||||||
|
loadRemoteReleases(packageName);
|
||||||
|
} else {
|
||||||
|
for (RepoListener listener : listeners) {
|
||||||
|
listener.onThrowable(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue