Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Sep 3, 2024
1 parent 68b101d commit 685464c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/happyx_native/android/autils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ jClass android.app.AlertDialog$Builder as AlertDialogBuilder* of Dialog:
proc show*: AlertDialog


jClass android.content.Window* of Object:
proc new*
proc setStatusBarColor*(var1: jint)


jClass android.content.ContextWrapper* of Context:
proc new*


jClass android.content.ContextThemeWrapper* of ContextWrapper:
proc new*


jClass android.content.Activity* of ContextThemeWrapper:
proc new*
proc getWindow*(): Window


var
runOnUiThreadEvents {.compileTime.}: seq[NimNode] = @[]
argumentNames {.compileTime.} = newTable[int, seq[NimNode]]()
Expand Down
16 changes: 8 additions & 8 deletions src/happyx_native/app/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ when defined(webview):

proc optimizeJs*(filepath: string) {.compileTime.} =
discard staticExec(
fmt"""uglifyjs "{filepath}" -c -m toplevel --mangle-props regex=/N[ST]I\w+/ -O semicolons -o "{filepath}" """
fmt"""uglifyjs "{filepath}" -c --mangle-props regex=/N[ST]I\w+/ -O semicolons -o "{filepath}" """
)
discard staticExec(
fmt"""terser "{filepath}" -c -m -o "{filepath}" """
)
discard staticExec(
fmt"""cmd /c uglifyjs "{filepath}" -c -m toplevel --mangle-props regex=/N[ST]I\w+/ -O semicolons -o "{filepath}" """
fmt"""cmd /c uglifyjs "{filepath}" -c --mangle-props regex=/N[ST]I\w+/ -O semicolons -o "{filepath}" """
)
discard staticExec(
fmt"""cmd /c terser "{filepath}" -c -m -o "{filepath}" """
Expand Down Expand Up @@ -338,12 +338,12 @@ template nativeAppImpl*(appDirectory: string = "/assets", port: int = 5123,
data = data.replace(
"</head>", (
when defined(export2android):
"""<script>var ws = new WebSocket("ws://127.0.0.1:""" & $port & """/ws");"""
"""<script>var wsHpxNim = new WebSocket("ws://127.0.0.1:""" & $port & """/ws");"""
else:
"""<script>
window.moveTo(""" & $x & """,""" & $y & """);
window.resizeTo(""" & $w & """, """ & $h & """);
var ws = new WebSocket("ws://127.0.0.1:""" & $port & """/ws");""" & (
var wsHpxNim = new WebSocket("ws://127.0.0.1:""" & $port & """/ws");""" & (
when not resizeable:
"""
window.addEventListener('resize', () => {
Expand All @@ -354,29 +354,29 @@ template nativeAppImpl*(appDirectory: string = "/assets", port: int = 5123,
)
) & """
var connected = false;
ws.onmessage = (data) => {
wsHpxNim.onmessage = (data) => {
let v = Object.values(
data.data !== undefined ? JSON.parse(data.data) : x = JSON.parse(data)
);
hpxNative.callJs(v[0], v[1]);
}
ws.onopen = () => {connected = true};
wsHpxNim.onopen = () => {connected = true};
var hpxNative = {
callJs: function (func, arr) {
window[func].apply(null, arr);
},
callNim: function (func, ...args) {
if (!connected) {
function check(func, ...args) {
if (ws.readyState === 1) {
if (wsHpxNim.readyState === 1) {
connected = true;
hpxNative.callNim(func, ...args);
clearInterval(myInterval);
}
}
var myInterval = setInterval(check, 15, func, ...args);
} else {
ws.send(JSON.stringify({
wsHpxNim.send(JSON.stringify({
"procedure": func,
"params": [...args]
}));
Expand Down

0 comments on commit 685464c

Please sign in to comment.