Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/HapticX/happyx-native
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Jun 30, 2024
2 parents 3def2e2 + ede301b commit b26f601
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 27 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ nimble install https://github.com/HapticX/happyx-native

## Features

- Support for Chrome/Yandex/Edge browsers;
- Support for Android;
- Support for Chrome/Yandex/Edge browsers & Webview
- Support for Android


## Project Initialization
Expand Down Expand Up @@ -88,12 +88,11 @@ Possible architectures
| arm64-v8a | `--no-arm64-v8a` |

If you doesn't want to use gradle building then use
```shel
```shell
hpx-native build --target android --no-gradle
```
This command will build only `.so` libraries.


### Building Assets

HappyX Native supports "building" assets - all resources from app directory (by default `/assets`) and all subdirectories are "sewn" into executable file.
Expand All @@ -102,6 +101,17 @@ This way you can distribute your application over the network with only one exec

> This option can be disabled via `--no-build-assets`
### Webview Notes

When building with `-d:webview`, on Windows, you may notice that the window icon is not set
for you. This is due to a limitation within Happyx Native, that will be resolved in the
future. Currently, you may manually link in your desired window icon, like how is done in
<https://github.com/neroist/webview/tree/main/examples/example_application/windows>.

In addition, Webview does not currently support window positioning
(see <https://github.com/webview/webview/issues/642>), so the `x` and `y` arguments passed to
`nativeApp` will be ignored.

## Browsers

If you want choose other browser instead of default - use these flags:
Expand All @@ -112,3 +122,4 @@ If you want choose other browser instead of default - use these flags:
| Chrome | `-d:chrome` |
| Edge | `-d:edge` |
| Yandex | `-d:yandex` |
| Webview | `-d:webview` |
2 changes: 2 additions & 0 deletions happyx_native.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ requires "happyx#head"
requires "jnim#head"
# windows executable
requires "rcedit"
# Webview, updated bindings
requires "https://github.com/neroist/webview"
24 changes: 18 additions & 6 deletions src/happyx_native/app/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import
jsonutils
],
happyx,
../cli/utils
../cli/utils,
webview

when defined(export2android):
import
Expand Down Expand Up @@ -67,9 +68,6 @@ macro callback*(body: untyped) =
var params: seq[NimNode] = @[]
for param in statement.params:
params.add(param)
dumpTree:
{.gcsafe.}:
echo 1
var prc = newProc(
statement.name,
params,
Expand Down Expand Up @@ -116,8 +114,6 @@ macro callback*(body: untyped) =
nnkTemplateDef
)
)
echo result.toStrLit


macro callJsAsync*(funcName: string, params: varargs[untyped]) =
quote do:
Expand Down Expand Up @@ -179,6 +175,20 @@ 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

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

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 @@ -240,6 +250,8 @@ template nativeAppImpl*(appDirectory: string = "/assets", port: int = 5123,
spawn openEdge(port, arguments)
elif defined(chrome):
spawn openChrome(port, arguments)
elif defined(webview):
spawn createHpxWebview(w, h, port, resizeable)
else:
spawn openDefault(port, arguments)
else:
Expand Down
9 changes: 6 additions & 3 deletions src/happyx_native/cli/build.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ when defined(windows):
proc buildCommandAux*(target: string = OS, release: bool = false, opt: string = "size",
no_x86_64: bool = false, no_x86: bool = false, no_armeabi_v7a: bool = false,
no_arm64_v8a: bool = false, no_gradle: bool = false, no_build_assets: bool = false,
chrome: bool = true, yandex: bool = false, edge: bool = false,
chrome: bool = false, yandex: bool = false, edge: bool = false,
webview: bool = false,
app: string = "gui"): int =
if int(chrome) + int(yandex) + int(edge) > 1:
if int(chrome) + int(yandex) + int(edge) + int(webview) > 1:
styledEcho fgRed, "You should choose only one browser!"
return QuitFailure
let
Expand Down Expand Up @@ -51,6 +52,8 @@ proc buildCommandAux*(target: string = OS, release: bool = false, opt: string =
"-d:yandex"
elif edge:
"-d:edge"
elif webview:
"-d:webview"
else:
""
assets =
Expand Down Expand Up @@ -207,5 +210,5 @@ proc buildCommandAux*(target: string = OS, release: bool = false, opt: string =
else:
styledEcho fgRed, "unsupported target platform for building"
return QuitFailure
styledEcho fgGreen, "builded!"
styledEcho fgGreen, "built!"
QuitSuccess
29 changes: 15 additions & 14 deletions src/happyx_native/hpxnative.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ proc mainCommand(version = false): int =
proc buildCommand(target: string = OS, release: bool = false, opt: string = "size",
no_x86_64: bool = false, no_x86: bool = false, no_armeabi_v7a: bool = false,
no_arm64_v8a: bool = false, no_gradle: bool = false, no_build_assets: bool = false,
chrome: bool = true, yandex: bool = false, edge: bool = false,
chrome: bool = false, yandex: bool = false, edge: bool = false,
webview: bool = false,
app: string = "gui"): int =
buildCommandAux(
target, release, opt, no_x86_64, no_x86, no_armeabi_v7a, no_arm64_v8a,
no_gradle, no_build_assets, chrome, yandex, edge, app
no_gradle, no_build_assets, chrome, yandex, edge, webview, app
)

proc initCommand(name: string, kind: string = "SPA"): int =
Expand Down Expand Up @@ -69,37 +70,37 @@ when isMainModule:
of "":
quit(helpMessage())
of "init":
styledEcho fgBlue, "HappyX Native", fgMagenta, " init ", fgWhite, " command creates app project."
styledEcho fgBlue, "HappyX Native", fgMagenta, " init ", fgWhite, "~ ", fgGreen, "Create new Happyx Native project."
styledEcho "\nUsage:"
styledEcho fgMagenta, " hpx-native init\n"
styledEcho "Arguments:"
styledEcho fgBlue, align("name", 4), fgWhite, " - project name."
styledEcho fgBlue, align("name", 6), fgWhite, " - project name."
of "build":
styledEcho fgBlue, "HappyX Native", fgMagenta, " build ", fgWhite, " command builds app."
styledEcho fgBlue, "HappyX Native", fgMagenta, " build ", fgWhite, "~ ", fgGreen, "Build & compile Happyx Native app."
styledEcho "\nUsage:"
styledEcho fgMagenta, " hpx-native build\n"
styledEcho "Optional arguments:"
styledEcho fgBlue, align("target", 14), fgWhite, " - build target. By default target is your OS."
styledEcho fgBlue, align("target", 14), fgWhite, " - build target. Defaults to the current OS."
styledEcho align("", 14), " Possible targets:"
styledEcho align("", 14), " - windows (win);"
styledEcho align("", 14), " - linux (unix);"
styledEcho align("", 14), " - macosx (mac, macos);"
styledEcho align("", 14), " - android."
styledEcho align("", 14), " - windows (win)"
styledEcho align("", 14), " - linux (unix)"
styledEcho align("", 14), " - macosx (mac, macos)"
styledEcho align("", 14), " - android"
styledEcho fgBlue, align("no-x86_64", 14), fgWhite, " - disable building for x86_64 arch (android only)"
styledEcho fgBlue, align("no-x86", 14), fgWhite, " - disable building for x86 arch (android only)"
styledEcho fgBlue, align("no-armeabi-v7a", 14), fgWhite, " - disable building for armeabi-v7a arch (android only)"
styledEcho fgBlue, align("no-arm64-v8a", 14), fgWhite, " - disable building for arm64-v8a arch (android only)"
styledEcho fgBlue, align("release", 14), fgWhite, " - enable release build"
styledEcho fgBlue, align("opt", 14), fgWhite, " - Nim compilation option"
styledEcho fgBlue, align("", 14), fgWhite, " Possible values:"
styledEcho fgBlue, align("", 14), fgWhite, " - size (optimize build size);"
styledEcho fgBlue, align("", 14), fgWhite, " - speed (optimize app speed);"
styledEcho fgBlue, align("", 14), fgWhite, " - none (no optimizations, by default)."
styledEcho fgBlue, align("", 14), fgWhite, " - size (optimize build size)"
styledEcho fgBlue, align("", 14), fgWhite, " - speed (optimize app speed)"
styledEcho fgBlue, align("", 14), fgWhite, " - none (no optimizations, by default)"
else:
styledEcho fgRed, "Unknown subcommand: ", fgWhite, subcmdHelp
quit(QuitSuccess)
of "":
quit(dispatchmainCommand(cmdline = pars[0..^1]))
quit(mainCommand(pars[0] in ["-v", "--version"]))
else:
styledEcho fgRed, styleBright, "Unknown subcommand: ", fgWhite, subcmd
styledEcho fgYellow, "Use ", fgMagenta, "hpx_native help ", fgYellow, "to get all commands"
Expand Down

0 comments on commit b26f601

Please sign in to comment.