Make http request async

This commit is contained in:
Lubos Lenco
2021-07-13 13:47:56 +02:00
parent 67c8065f1d
commit 134ab6f0fd
3 changed files with 54 additions and 42 deletions
+5 -3
View File
@@ -11,9 +11,11 @@ class ImportAsset {
public static function run(path: String, dropX = -1.0, dropY = -1.0, showBox = true, hdrAsEnvmap = true) {
if (path.startsWith("cloud")) {
var abs = File.cacheCloud(path);
if (abs == null) return;
path = abs;
File.cacheCloud(path, function(abs: String) {
if (abs == null) return;
run(abs, dropX, dropY, showBox, hdrAsEnvmap);
});
return;
}
if (Path.isMesh(path)) {
+30 -21
View File
@@ -96,6 +96,7 @@ class UIFiles {
}
@:access(zui.Zui)
@:access(arm.sys.File)
public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false, search = ""): String {
var icons = Res.get("icons.k");
@@ -103,6 +104,9 @@ class UIFiles {
var file = Res.tile50(icons, 3, 1);
var isCloud = handle.text.startsWith("cloud");
if (isCloud && File.cloud == null) File.initCloud();
if (isCloud && File.readDirectory("cloud", false).length == 0) return handle.text;
if (handle.text == "") handle.text = defaultPath;
if (handle.text != lastPath || search != lastSearch) {
files = [];
@@ -164,28 +168,33 @@ class UIFiles {
var filesAll = File.readDirectory(handle.text);
var iconFile = f.substr(0, f.lastIndexOf(".")) + "_icon.jpg";
if (filesAll.indexOf(iconFile) >= 0) {
var abs = File.cacheCloud(handle.text + Path.sep + iconFile);
if (abs != null) {
iron.data.Data.getImage(abs, function(image: kha.Image) {
iron.App.notifyOnInit(function() {
if (Layers.pipeCopyRGB == null) Layers.makePipeCopyRGB();
icon = kha.Image.createRenderTarget(image.width, image.height);
if (f.endsWith(".arm")) { // Used for material sphere alpha cutout
icon.g2.begin(false);
icon.g2.drawImage(Project.materials[0].image, 0, 0);
}
else {
icon.g2.begin(true, 0xffffffff);
}
icon.g2.pipeline = Layers.pipeCopyRGB;
icon.g2.drawImage(image, 0, 0);
icon.g2.pipeline = null;
icon.g2.end();
iconMap.set(handle.text + Path.sep + f, icon);
var empty = iron.RenderPath.active.renderTargets.get("empty_black").image;
iconMap.set(handle.text + Path.sep + f, empty);
File.cacheCloud(handle.text + Path.sep + iconFile, function(abs: String) {
if (abs != null) {
iron.data.Data.getImage(abs, function(image: kha.Image) {
iron.App.notifyOnInit(function() {
if (Layers.pipeCopyRGB == null) Layers.makePipeCopyRGB();
icon = kha.Image.createRenderTarget(image.width, image.height);
if (f.endsWith(".arm")) { // Used for material sphere alpha cutout
icon.g2.begin(false);
icon.g2.drawImage(Project.materials[0].image, 0, 0);
}
else {
icon.g2.begin(true, 0xffffffff);
}
icon.g2.pipeline = Layers.pipeCopyRGB;
icon.g2.drawImage(image, 0, 0);
icon.g2.pipeline = null;
icon.g2.end();
iconMap.set(handle.text + Path.sep + f, icon);
});
});
});
}
else offline = true;
}
else offline = true;
});
}
}
if (icon != null) {
+19 -18
View File
@@ -352,26 +352,27 @@ class UIMenu {
#if !(krom_android || krom_ios)
if (menuButton(ui, tr("Check for Updates..."))) {
// Retrieve latest version number
var url = "'https://luboslenco.gitlab.io/armorpaint/index.html'";
var blob = File.downloadBytes(url);
if (blob != null) {
// Compare versions
var update = Json.parse(blob.toString());
var updateVersion = Std.int(update.version);
if (updateVersion > 0) {
var date = BuildMacros.date().split(" ")[0].substr(2); // 2019 -> 19
var dateInt = Std.parseInt(date.replace("-", ""));
if (updateVersion > dateInt) {
UIBox.showMessage(tr("Update"), tr("Update is available!\nPlease visit armorpaint.org to download."));
}
else {
UIBox.showMessage(tr("Update"), tr("You are up to date!"));
var url = "https://luboslenco.gitlab.io/armorpaint/index.html";
File.downloadBytes(url, function(bytes: Bytes) {
if (bytes != null) {
// Compare versions
var update = Json.parse(bytes.toString());
var updateVersion = Std.int(update.version);
if (updateVersion > 0) {
var date = BuildMacros.date().split(" ")[0].substr(2); // 2019 -> 19
var dateInt = Std.parseInt(date.replace("-", ""));
if (updateVersion > dateInt) {
UIBox.showMessage(tr("Update"), tr("Update is available!\nPlease visit armorpaint.org to download."));
}
else {
UIBox.showMessage(tr("Update"), tr("You are up to date!"));
}
}
}
}
else {
UIBox.showMessage(tr("Update"), tr("Unable to check for updates.\nPlease visit armorpaint.org."));
}
else {
UIBox.showMessage(tr("Update"), tr("Unable to check for updates.\nPlease visit armorpaint.org."));
}
});
}
#end