Provide script download suggestions async (#986)
This commit is contained in:
1 parent
7d4eeb464b
commit
cca9d2ec7e
2 files changed
+32
-12
No files matched your search
@@ -38,6 +38,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -81,6 +82,7 @@ public class AppStoreManager
|
||||
public Map<String, StoreNode> children;
|
||||
public boolean sealed;
|
||||
public String value;
|
||||
private CountDownLatch childrenProgress;
|
||||
public static StoreNode folder(StoreNode parent, String name)
|
||||
{
|
||||
StoreNode node = new StoreNode(parent, name);
|
||||
@@ -126,6 +128,20 @@ public class AppStoreManager
|
||||
{
|
||||
if (sealed) return;
|
||||
if (scarpetRepoLink == null) throw new IOException("Accessing scarpet app repo is disabled");
|
||||
try
|
||||
{
|
||||
if (childrenProgress != null)
|
||||
{
|
||||
childrenProgress.await();
|
||||
if (sealed) return;
|
||||
else throw new IOException("Problems fetching suggestions. Check more details in previous exceptions.");
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
throw new IOException("Suggestion provider thread was interrupted, unexpected!", e);
|
||||
}
|
||||
childrenProgress = new CountDownLatch(1);
|
||||
|
||||
String queryPath = scarpetRepoLink + getPath();
|
||||
String response;
|
||||
@@ -135,7 +151,9 @@ public class AppStoreManager
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new IOException("Problems fetching "+queryPath+": "+e);
|
||||
childrenProgress.countDown();
|
||||
childrenProgress = null; // Reset to allow retrying
|
||||
throw new IOException("Problems fetching " + queryPath, e);
|
||||
}
|
||||
JsonArray files = new JsonParser().parse(response).getAsJsonArray();
|
||||
for(JsonElement je : files)
|
||||
@@ -153,6 +171,7 @@ public class AppStoreManager
|
||||
}
|
||||
}
|
||||
sealed = true;
|
||||
childrenProgress.countDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user