Webview for RunT/Krom

This commit is contained in:
Gorochu
2026-07-13 15:44:52 -07:00
parent 7b2f21c499
commit 31a6a9d7ec
75 changed files with 1488 additions and 46 deletions

View File

@ -8,7 +8,7 @@ class AlertNode extends LogicNode {
override function run(from: Int) {
#if kha_html5
#if js
js.Browser.window.alert(inputs[1].get());
#end

View File

@ -2,19 +2,31 @@ package leenkx.logicnode;
class ConfirmNode extends LogicNode {
var result: Dynamic;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_html5
var answer: Bool = js.Browser.window.confirm(inputs[1].get());
if(answer)
return runOutput(0);
else
return runOutput(1);
#if js
result = js.Browser.window.confirm(inputs[1].get());
if (Reflect.field(result, "loaded") != null) {
tree.notifyOnUpdate(poll);
} else {
if (result) runOutput(0);
else runOutput(1);
}
#end
}
function poll() {
#if js
if (result.loaded) {
tree.removeUpdate(poll);
if (result.data) runOutput(0);
else runOutput(1);
}
#end
}
}

View File

@ -11,12 +11,11 @@ class GetElementPropertyNode extends LogicNode {
override function get(from: Int): Dynamic {
return switch (from) {
case 0:
var object: Dynamic = inputs[0].get();
var property = inputs[1].get();
value = Reflect.field(object, property);
//value = object.getAttribute(property.toString());
#if js
var element: Dynamic = inputs[0].get();
var property = inputs[1].get();
value = Reflect.field(element, property);
#end
default: throw "Unreachable";
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromCopyToClipboardNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var text: String = inputs[1].get();
js.Syntax.code("Krom.copyToClipboard({0})", text);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,15 @@
package leenkx.logicnode;
class KromDelayIdleSleepNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
js.Syntax.code("Krom.delayIdleSleep()");
#end
runOutput(0);
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromDeleteFileNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var path: String = inputs[1].get();
js.Syntax.code("Krom.deleteFile({0})", path);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class KromFileExistsNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var path: String = inputs[0].get();
return js.Syntax.code("Krom.fileExists({0})", path);
#else
return false;
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromGetArgCountNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.getArgCount();
#else
return 0;
#end
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class KromGetArgNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var index: Int = inputs[0].get();
return Krom.getArg(index);
#else
return "";
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromGetFilesLocationNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.getFilesLocation();
#else
return "";
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromSavePathNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.savePath();
#else
return "";
#end
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromSetApplicationNameNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var name: String = inputs[1].get();
js.Syntax.code("Krom.setApplicationName({0})", name);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class KromShowKeyboardNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var show: Bool = inputs[1].get();
js.Syntax.code("Krom.showKeyboard({0})", show);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,28 @@
package leenkx.logicnode;
class KromSysCommandNode extends LogicNode {
var exitCode: Int = 0;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var cmd: String = inputs[1].get();
var args: Dynamic = inputs[2].get();
if (args != null) {
exitCode = Krom.sysCommand(cmd, args);
} else {
exitCode = Krom.sysCommand(cmd);
}
#end
runOutput(0);
}
override function get(from: Int): Dynamic {
if (from == 1) return exitCode;
return null;
}
}

View File

@ -13,7 +13,7 @@ class LoadUrlNode extends LogicNode {
override function run(from: Int) {
//System.loadUrl(inputs[1].get());
#if kha_html5
#if js
if (inputs[2].get()){
var window = inputs[3].get() ? js.Browser.window.open(inputs[1].get(), "_blank", "width="+inputs[4].get()+",height="+inputs[5].get()+",left="+inputs[6].get()+",top="+inputs[7].get())
: js.Browser.window.open(inputs[1].get(), "_blank");

View File

@ -3,18 +3,32 @@ package leenkx.logicnode;
class PromptNode extends LogicNode {
var input: String = null;
var result: Dynamic;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_html5
input = js.Browser.window.prompt(inputs[1].get(), inputs[2].get());
runOutput(0);
#if js
result = js.Browser.window.prompt(inputs[1].get(), inputs[2].get());
if (Reflect.field(result, "loaded") != null) {
tree.notifyOnUpdate(poll);
} else {
input = result;
runOutput(0);
}
#end
}
function poll() {
#if js
if (result.loaded) {
tree.removeUpdate(poll);
input = result.data;
runOutput(0);
}
#end
}
override function get(from: Int): Dynamic {

View File

@ -40,12 +40,14 @@ class RenderElementNode extends LogicNode {
tarElem.prepend(element);
runOutput(0);
case "innerHTML":
var tarElem = js.Browser.document.querySelector(selector);
tarElem.innerHTML = element.innerHTML;
var html: String = inputs[2].get();
if (html == null) { return; }
element.innerHTML = html;
runOutput(0);
case "innerText":
var tarElem = js.Browser.document.querySelector(selector);
tarElem.innerText = element.innerText;
var html: String = inputs[2].get();
if (html == null){ return; }
element.innerText = html;
runOutput(0);
case "insertAdjacentHTML":
var tarElem = js.Browser.document.querySelector(selector);

View File

@ -12,28 +12,7 @@ class RunJavascriptNode extends LogicNode {
#if js
var script = inputs[1].get();
js.Syntax.code('(1, eval)({0})', script.toString());
var promise:Dynamic = null;//js.Syntax.code('(1, eval)({0})', script.toString());
if (promise != null) {
promise.then(
function(_) {
//if(leenkx.network.Leenkx.data.get(element) != 'undefined'){return}
haxe.Timer.delay(function () {
//promiseResult(element,html);
return;
}, 100);
return;
}).then(null, function(error) {
trace("JS SYNTAX ERROR:" + error.toString());
haxe.Timer.delay(function () {
//promiseResult(element,html);
return;
}, 100);
}
);
}
runOutput(0);
runOutput(0);
#end
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class WebviewCountNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
return Krom.webviewCount();
#else
return 0;
#end
}
}

View File

@ -0,0 +1,50 @@
package leenkx.logicnode;
class WebviewCreateNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
var parentWindow: Int = (property0 == "embedded") ? 0 : -1;
var x: Int = inputs[1].get();
var y: Int = inputs[2].get();
var width: Int = inputs[3].get();
var height: Int = inputs[4].get();
var transparent: Bool = inputs[5].get();
var title: String = inputs[6].get();
var html: String = inputs[7].get();
var url: String = inputs[8].get();
var show: Bool = inputs[9].get();
#if kha_krom
var options: Dynamic = {
parentWindow: parentWindow,
x: x,
y: y,
width: width,
height: height,
transparent: transparent,
title: title
};
var id: Int = Krom.webviewCreate(options);
if (html != null && html != "") Krom.webviewLoadHTML(id, html);
if (url != null && url != "") Krom.webviewLoadURL(id, url);
if (show) Krom.webviewShow(id);
#else
var id: Int = -1;
#end
this.id = id;
runOutput(0);
}
var id: Int = -1;
override function get(from: Int): Dynamic {
return id;
}
}

View File

@ -0,0 +1,31 @@
package leenkx.logicnode;
class WebviewDOMNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
if (property0 == "set") {
var id: Int = inputs[1].get();
Krom.webviewSetActiveDOM(id);
}
#end
runOutput(0);
}
override function get(from: Int): Dynamic {
#if kha_krom
if (property0 == "get") {
return Krom.webviewGetActiveDOM();
}
#else
return -1;
#end
return -1;
}
}

View File

@ -0,0 +1,16 @@
package leenkx.logicnode;
class WebviewDestroyNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
Krom.webviewDestroy(id);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,24 @@
package leenkx.logicnode;
class WebviewDevSettingsNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
var enabled: Bool = inputs[2].get();
if (property0 == "devtools") {
Krom.webviewEnableDevTools(id, enabled);
}
else {
Krom.webviewSetContextMenu(id, enabled);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class WebviewEvalJSNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
var jsCode: String = inputs[2].get();
Krom.webviewEvalJS(id, jsCode);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,31 @@
package leenkx.logicnode;
class WebviewFullscreenNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
if (property0 == "set") {
var id: Int = inputs[1].get();
var fullscreen: Bool = inputs[2].get();
Krom.webviewSetFullscreen(id, fullscreen);
}
#end
runOutput(0);
}
override function get(from: Int): Dynamic {
#if kha_krom
if (property0 == "get") {
var id: Int = inputs[0].get();
return Krom.webviewIsFullscreen(id);
}
#end
return false;
}
}

View File

@ -0,0 +1,26 @@
package leenkx.logicnode;
class WebviewGetDimensionsNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
if (property0 == "position") {
if (from == 0) return Krom.webviewGetX(id);
else return Krom.webviewGetY(id);
}
else {
if (from == 0) return Krom.webviewGetWidth(id);
else return Krom.webviewGetHeight(id);
}
#else
return 0;
#end
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class WebviewIsValidNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
return Krom.webviewIsValid(id);
#else
return false;
#end
}
}

View File

@ -0,0 +1,25 @@
package leenkx.logicnode;
class WebviewLoadNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
if (property0 == "html") {
var html: String = inputs[2].get();
Krom.webviewLoadHTML(id, html);
}
else {
var url: String = inputs[2].get();
Krom.webviewLoadURL(id, url);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,22 @@
package leenkx.logicnode;
class WebviewNavigationNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
switch (property0) {
case "go_back": Krom.webviewGoBack(id);
case "go_forward": Krom.webviewGoForward(id);
case "reload": Krom.webviewReload(id);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,20 @@
package leenkx.logicnode;
class WebviewNavigationStateNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
if (property0 == "can_go_back") return Krom.webviewCanGoBack(id);
else return Krom.webviewCanGoForward(id);
#else
return false;
#end
}
}

View File

@ -0,0 +1,46 @@
package leenkx.logicnode;
class WebviewOnEventNode extends LogicNode {
public var property0: String;
var message: String = "";
var error: String = "";
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[0].get();
var self = this;
switch (property0) {
case "message":
Krom.webviewSetOnMessage(id, function(msg) { self.onEvent(msg); });
case "load":
Krom.webviewSetOnLoad(id, function() { self.onEvent(null); });
case "error":
Krom.webviewSetOnError(id, function(err) { self.onEvent(err); });
case "close":
Krom.webviewSetOnClose(id, function() { self.onEvent(null); });
}
#end
}
function onEvent(data: String) {
if (data != null) {
if (property0 == "message") this.message = data;
else if (property0 == "error") this.error = data;
}
runOutput(0);
}
override function get(from: Int): Dynamic {
if (from == 1) {
if (property0 == "message") return message;
if (property0 == "error") return error;
}
return null;
}
}

View File

@ -0,0 +1,20 @@
package leenkx.logicnode;
class WebviewPageInfoNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
#if kha_krom
var id: Int = inputs[0].get();
if (property0 == "url") return Krom.webviewGetURL(id);
else return Krom.webviewGetPageTitle(id);
#else
return "";
#end
}
}

View File

@ -0,0 +1,17 @@
package leenkx.logicnode;
class WebviewSendNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
var message: String = inputs[2].get();
Krom.webviewSend(id, message);
#end
runOutput(0);
}
}

View File

@ -0,0 +1,33 @@
package leenkx.logicnode;
class WebviewSetDimensionsNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
switch (property0) {
case "resize":
var width: Int = inputs[2].get();
var height: Int = inputs[3].get();
Krom.webviewResize(id, width, height);
case "move":
var x: Int = inputs[2].get();
var y: Int = inputs[3].get();
Krom.webviewMove(id, x, y);
case "set_bounds":
var x: Int = inputs[2].get();
var y: Int = inputs[3].get();
var width: Int = inputs[4].get();
var height: Int = inputs[5].get();
Krom.webviewSetBounds(id, x, y, width, height);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,28 @@
package leenkx.logicnode;
class WebviewSetPropertyNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
switch (property0) {
case "transparent":
var value: Bool = inputs[2].get();
Krom.webviewSetTransparent(id, value);
case "click_through":
var value: Bool = inputs[2].get();
Krom.webviewSetClickThrough(id, value);
case "title":
var value: String = inputs[2].get();
Krom.webviewSetTitle(id, value);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,23 @@
package leenkx.logicnode;
class WebviewVisibilityNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
if (property0 == "show") {
Krom.webviewShow(id);
}
else {
Krom.webviewHide(id);
}
#end
runOutput(0);
}
}

View File

@ -0,0 +1,22 @@
package leenkx.logicnode;
class WebviewWindowActionsNode extends LogicNode {
public var property0: String;
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if kha_krom
var id: Int = inputs[1].get();
switch (property0) {
case "minimize": Krom.webviewMinimize(id);
case "maximize": Krom.webviewMaximize(id);
case "restore": Krom.webviewRestore(id);
}
#end
runOutput(0);
}
}

View File

@ -48,6 +48,21 @@ class Starter {
mode: windowMode, windowFeatures: windowFeatures}, framebuffer: {samplesPerPixel: c.window_msaa, verticalSync: c.window_vsync}}, function(window: kha.Window) {
iron.App.init(function() {
// TODO: Currently breaks after a second
// TODO: Figure out why full width and height need a math operation like /2 or -1
//#if (lnx_webview && kha_krom)
//var wvOptions: Dynamic = {
// parentWindow: 0,
// x: 0,
// y: 0,
// width: c.window_w - 1,
// height: c.window_h - 1,
// transparent: true,
// title: Main.projectName
//};
//var wvId: Int = Krom.webviewCreate(wvOptions);
//Krom.webviewShow(wvId);
//#end
#if lnx_loadscreen
function load(g: kha.graphics2.Graphics) {
if (iron.Scene.active != null && iron.Scene.active.ready) iron.App.removeRender2D(load);