diff --git a/README.md b/README.md index 6b93485..6239bc3 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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 +. + +In addition, Webview does not currently support window positioning +(see ), 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: @@ -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` | diff --git a/happyx_native.nimble b/happyx_native.nimble index 973660d..94b75d0 100644 --- a/happyx_native.nimble +++ b/happyx_native.nimble @@ -24,3 +24,5 @@ requires "happyx#head" requires "jnim#head" # windows executable requires "rcedit" +# Webview, updated bindings +requires "https://github.com/neroist/webview" diff --git a/src/happyx_native/app/app.nim b/src/happyx_native/app/app.nim index 08fde2b..d7a0130 100644 --- a/src/happyx_native/app/app.nim +++ b/src/happyx_native/app/app.nim @@ -10,7 +10,8 @@ import jsonutils ], happyx, - ../cli/utils + ../cli/utils, + webview when defined(export2android): import @@ -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, @@ -116,8 +114,6 @@ macro callback*(body: untyped) = nnkTemplateDef ) ) - echo result.toStrLit - macro callJsAsync*(funcName: string, params: varargs[untyped]) = quote do: @@ -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, @@ -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: diff --git a/src/happyx_native/cli/build.nim b/src/happyx_native/cli/build.nim index 7c937db..68663ee 100644 --- a/src/happyx_native/cli/build.nim +++ b/src/happyx_native/cli/build.nim @@ -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 @@ -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 = @@ -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 diff --git a/src/happyx_native/hpxnative.nim b/src/happyx_native/hpxnative.nim index 8adfbed..a86496f 100644 --- a/src/happyx_native/hpxnative.nim +++ b/src/happyx_native/hpxnative.nim @@ -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 = @@ -69,22 +70,22 @@ 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)" @@ -92,14 +93,14 @@ when isMainModule: 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"