Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Sep 4, 2024
1 parent decd7b7 commit eedc5af
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/happyx_native/abstract/saving.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ template loadImpl[T](filename: string, parseFunc: untyped): untyped =
when T is string:
return data
else:
if $data.len == 0:
if ($data).len == 0:
return T.default
return `parseFunc`($data)

Expand Down
70 changes: 15 additions & 55 deletions src/happyx_native/android/autils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ jClass android.app.AlertDialog$Builder as AlertDialogBuilder* of Dialog:
jClass android.content.Window* of Object:
proc new*
proc setStatusBarColor*(var1: jint)
proc getStatusBarColor*(): jint
proc setNavigationBarColor*(var1: jint)
proc getNavigationBarColor*(): jint


jClass android.content.ContextWrapper* of Context:
Expand All @@ -367,83 +370,40 @@ jClass android.content.Activity* of ContextThemeWrapper:
proc getWindow*(): Window


jClass android.graphics.Color as AndroidColor* of Object:
proc new*
proc parseColor*(clr: string): jint {.`static`.}


var
runOnUiThreadEvents {.compileTime.}: seq[NimNode] = @[]
argumentNames {.compileTime.} = newTable[int, seq[NimNode]]()


proc fetchAllIdents(node: var NimNode, list: var seq[NimNode], reserved: var seq[NimNode], root: NimNode = nil) =
for i in 0..<node.len:
var child = node[i]
if child.kind in AtomicNodes:
if child.kind == nnkIdent and ($child)[0] in ({'a'..'z'} + {'A'..'Z'}):
if root.kind notin [nnkVarSection, nnkLetSection, nnkProcDef, nnkConstSection] and child notin list:
if child notin reserved:
list.add(child)
else:
reserved.add(child)
if child.kind == nnkSym and $child in ["params"]:
if root.kind notin [nnkVarSection, nnkLetSection, nnkProcDef, nnkConstSection]:
if child notin reserved:
if child notin list:
list.add(child.copy())
node[i] = ident($child & "___")
else:
reserved.add(child)
else:
fetchAllIdents(child, list, reserved, node)


macro runOnUiThread*(body: untyped) =
var
statements = body
# list: seq[NimNode] = @[]
# reserved: seq[NimNode] = @[]
index = runOnUiThreadEvents.len
# codeBlocksTable = newCall(
# "[]=",
# ident"argumentsCodeBlocks",
# newLit(index),
# newCall("@", newNimNode(nnkBracket))
# )
# argumentNames[index] = newSeq[NimNode]()
# fetchAllIdents(statements, list, reserved)
runOnUiThreadEvents.add(statements)
result = newStmtList()
# for i in list:
# codeBlocksTable[^1][^1].add(newNimNode(nnkCast).add(ident"pointer", newCall("addr", i)))
# argumentNames[index].add(ident($i & "___"))
result.add(
# codeBlocksTable,
newCall("inc", newCall("[]", ident"uniqueCodeBlocks", newLit(runOnUiThreadEvents.len - 1)))
)
runOnUiThreadEvents.add(body)
newCall("inc", newCall("[]", ident"uniqueCodeBlocks", newLit(runOnUiThreadEvents.len - 1)))


macro runOnUiThreadAll*() =
result = newStmtList()
for i in runOnUiThreadEvents.low..runOnUiThreadEvents.high:
# var variables = newNimNode(nnkVarSection)
# for j in 0..<argumentNames[i].len:
# variables.add(newIdentDefs(
# argumentNames[i][j],
# newEmptyNode(),
# newNimNode(nnkBracketExpr).add(ident"argumentsCodeBlocks", newLit(j))
# ))
result.add(newNimNode(nnkWhileStmt).add(
newCall(">", newNimNode(nnkBracketExpr).add(ident"uniqueCodeBlocks", newLit(i)), newLit(0)),
newStmtList(
# variables,
runOnUiThreadEvents[i],
runOnUiThreadEvents[i].copy(),
newCall("dec", newNimNode(nnkBracketExpr).add(ident"uniqueCodeBlocks", newLit(i)))
)
))


macro declareRunOnUiAll*() =
result = newStmtList()
result = newAssignment(
ident"uniqueCodeBlocks", newCall("@", newNimNode(nnkBracket))
)

for i in runOnUiThreadEvents.low..runOnUiThreadEvents.high:
result.add(newCall("add", ident"uniqueCodeBlocks", newLit(0)))
result[^1][^1].add(newLit(0))


type Log* = object
Expand Down
7 changes: 3 additions & 4 deletions src/happyx_native/app/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var websocketClient*: WebSocket

when defined(export2android):
var
appContext*: Context
appContext*: Activity


macro callback*(body: untyped) =
Expand Down Expand Up @@ -460,11 +460,10 @@ template nativeApp*(appDirectory: string = "/assets", port: int = 5123,
when defined(export2android):
nativeMethodsFor cfgAndroidPackageId(), "Native":
proc start(ctx: jobject) =
appContext = cast[Context](newJVMObject(ctx))
appContext = cast[Activity](newJVMObject(ctx))
nativeAppImpl(appDirectory, cfgPort(), x, y, w, h, appMode, title, resizeable, establish)

proc runOnUi(ctx: jobject) =
appContext = cast[Context](newJVMObject(ctx))
appContext = cast[Activity](newJVMObject(ctx))
runOnUiThreadAll()
declareRunOnUiAll()
else:
Expand Down
2 changes: 1 addition & 1 deletion src/happyx_native/cli/build.nim
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ proc buildCommandAux*(target: string = OS, release: bool = false, opt: string =
let (arch, cpu, linker) = data
discard execCmd(
fmt"""nim c {mode} {opt} {assets} -d:export2android -d:noSignalHandler --app:lib """ &
fmt"""--os:android --cpu:{cpu} --hint[CC]:on -d:httpxSendServerDate=false -d:httpx """ &
fmt"""--os:android --cpu:{cpu} --hint[CC]:on -d:httpxSendServerDate=false --threads:on -d:httpx """ &
fmt"""--clang.path:"{clangPath}" --clang.exe:"{linker}" --clang.linkerexe:"{linker}" """ &
fmt"""--passL:"-llog" """ &
fmt"""-o:android/app/src/main/jniLibs/{arch}/libhpx-native.so app.nim"""
Expand Down

0 comments on commit eedc5af

Please sign in to comment.