From ceb70aea3b3e63573bce0c7647bb02dd9e8f2bcf Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 23 Feb 2021 08:43:08 +0800 Subject: [PATCH] [app] Temporarily fix #169 --- .../lsposed/manager/repo/RepoLoader.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/github/lsposed/manager/repo/RepoLoader.java b/app/src/main/java/io/github/lsposed/manager/repo/RepoLoader.java index 43eb0b53..1c2b25cc 100644 --- a/app/src/main/java/io/github/lsposed/manager/repo/RepoLoader.java +++ b/app/src/main/java/io/github/lsposed/manager/repo/RepoLoader.java @@ -25,6 +25,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -86,22 +87,29 @@ public class RepoLoader { @Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { - ResponseBody body = response.body(); - if (body != null) { - String bodyString = body.string(); - Gson gson = new Gson(); - Map modules = new HashMap<>(); - OnlineModule[] repoModules = gson.fromJson(bodyString, OnlineModule[].class); - Arrays.stream(repoModules).forEach(onlineModule -> modules.put(onlineModule.getName(), onlineModule)); - onlineModules = modules; - Files.write(repoFile, bodyString.getBytes(StandardCharsets.UTF_8)); - } - for (Listener listener : listeners) { - listener.repoLoaded(); - } - synchronized (this) { - isLoading = false; - repoLoaded = true; + try { + ResponseBody body = response.body(); + if (body != null) { + String bodyString = body.string(); + Gson gson = new Gson(); + Map modules = new HashMap<>(); + OnlineModule[] repoModules = gson.fromJson(bodyString, OnlineModule[].class); + Arrays.stream(repoModules).forEach(onlineModule -> modules.put(onlineModule.getName(), onlineModule)); + onlineModules = modules; + Files.write(repoFile, bodyString.getBytes(StandardCharsets.UTF_8)); + } + for (Listener listener : listeners) { + listener.repoLoaded(); + } + synchronized (this) { + isLoading = false; + repoLoaded = true; + } + } catch (Throwable e) { + if (e instanceof IOException) + throw e; + else + throw new IOException(e.getMessage(), e.getCause()); } } });