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