Skip to content

Commit

Permalink
android update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Sep 3, 2024
1 parent 800b511 commit 3f7f52f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion happyx_native.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

description = "Macro-oriented web-framework compiles to native written with ♥"
author = "HapticX"
version = "0.3.1"
version = "0.3.2"
license = "MIT"
srcDir = "src"
installExt = @["nim", "gradle", "properties"]
Expand Down
38 changes: 18 additions & 20 deletions src/happyx_native/app/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import
macros, os, sequtils, strformat,
osproc, json, threadpool, browsers,
uri, tables, terminal, parsecfg,
jsonutils
jsonutils, sugar
],
happyx,
../cli/utils,
../cli/utils


when defined(webview):
webview

when defined(export2android):
Expand Down Expand Up @@ -175,20 +178,21 @@ macro fetchFiles*(directory: static[string]): untyped =
))
result.add(ident"_files")

proc createHpxWebview*(w, h: int, port: int, resizeable: bool) =
let
wv = newWebview()
hint =
if resizeable: WebviewHintNone
else: WebviewHintFixed
when defined(webview):
proc createHpxWebview*(w, h: int, port: int, resizeable: bool) =
let
wv = newWebview()
hint =
if resizeable: WebviewHintNone
else: WebviewHintFixed

wv.setSize(w, h, hint)
wv.setTitle(cfgName())
# no positioning?
wv.navigate(cstring("http://127.0.0.1:" & $port))
wv.setSize(w, h, hint)
wv.setTitle(cfgName())
# no positioning?
wv.navigate(cstring("http://127.0.0.1:" & $port))

wv.run()
wv.destroy()
wv.run()
wv.destroy()

template nativeAppImpl*(appDirectory: string = "/assets", port: int = 5123,
x: int = 512, y: int = 128, w: int = 720, h: int = 320,
Expand Down Expand Up @@ -320,8 +324,6 @@ template nativeAppImpl*(appDirectory: string = "/assets", port: int = 5123,
window[func].apply(null, arr);
},
callNim: function (func, ...args) {
console.log(typeof(func), func);
console.log(typeof([...args]), [...args]);
if (!connected) {
function check(func, ...args) {
if (ws.readyState === 1) {
Expand All @@ -332,10 +334,6 @@ template nativeAppImpl*(appDirectory: string = "/assets", port: int = 5123,
}
var myInterval = setInterval(check, 15, func, ...args);
} else {
console.log(JSON.stringify({
"procedure": func,
"params": [...args]
}));
ws.send(JSON.stringify({
"procedure": func,
"params": [...args]
Expand Down
2 changes: 1 addition & 1 deletion src/happyx_native/core/constants.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

const
HpxNativeVersion* = "0.3.0"
HpxNativeVersion* = "0.3.2"
OS* =
when defined(windows) or hostOS == "windows":
"win"
Expand Down
2 changes: 2 additions & 0 deletions tests/hpx_tests/assets/native.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ import jsffi
export jsffi

var hpxNative* {.importc, nodecl.}: JsObject

hpxNative.callNim("helloWorld")
10 changes: 8 additions & 2 deletions tests/test/app.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Main native file
import happyx_native

var
lastPage = "/"
readedStories: JsonNode = newJArray()

callback:
# HappyX Native helloWorld callback
proc helloWorld() =
echo "Hello from Nim"

echo 1
lastPage = loadString("hapticx.ktc_hpx.lastPage")
echo 1
readedStories = loadJson("hapticx.ktc_hpx.readedStories")
echo 1

nativeApp("/assets", resizeable = false, title = "test")
2 changes: 2 additions & 0 deletions tests/test/assets/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ appRoutes "app":
"increase"
@click:
# Call HappyX Native callback named helloWorld without arguments
echo 1
hpxNative.callNim("helloWorld")
x->inc()
echo x
tStyle: """
body {
padding: 0;
Expand Down

0 comments on commit 3f7f52f

Please sign in to comment.