├── tests ├── config.nims ├── test_terminate.nim ├── test_version.nim ├── test_nim_api.nim ├── test_go_test.nim └── test_sync_bind.nim ├── examples ├── nim.cfg ├── example_application │ ├── windows │ │ ├── nim.cfg │ │ ├── README │ │ ├── icons │ │ │ ├── window.ico │ │ │ └── application.ico │ │ ├── resources.rc │ │ ├── compile.bat │ │ └── main.nim │ └── macos │ │ └── README ├── basic.nim └── bind.nim ├── .gitmodules ├── nimdoc.cfg ├── .gitignore ├── .gitattributes ├── webview.nimble ├── LICENSE ├── libs └── webview2 │ ├── EventToken.h │ └── WebView2EnvironmentOptions.h ├── README.md ├── docs ├── webview.idx ├── nimdoc.out.css └── dochack.js └── webview.nim /tests/config.nims: -------------------------------------------------------------------------------- 1 | switch("path", "$projectDir") -------------------------------------------------------------------------------- /examples/nim.cfg: -------------------------------------------------------------------------------- 1 | --path:".." 2 | --mm:orc 3 | 4 | -d:release -------------------------------------------------------------------------------- /examples/example_application/windows/nim.cfg: -------------------------------------------------------------------------------- 1 | --outDir:build 2 | --app:gui 3 | --mm:orc 4 | 5 | -d:release -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/webview"] 2 | path = libs/webview 3 | url = https://github.com/webview/webview.git 4 | -------------------------------------------------------------------------------- /examples/example_application/windows/README: -------------------------------------------------------------------------------- 1 | Example application for Windows 2 | 3 | See https://github.com/webview/webview#windows-apps -------------------------------------------------------------------------------- /examples/example_application/macos/README: -------------------------------------------------------------------------------- 1 | MacOS example application 2 | 3 | TODO 4 | 5 | See https://github.com/webview/webview#macos-application-bundle -------------------------------------------------------------------------------- /examples/example_application/windows/icons/window.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neroist/webview/HEAD/examples/example_application/windows/icons/window.ico -------------------------------------------------------------------------------- /examples/example_application/windows/icons/application.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neroist/webview/HEAD/examples/example_application/windows/icons/application.ico -------------------------------------------------------------------------------- /examples/example_application/windows/resources.rc: -------------------------------------------------------------------------------- 1 | 100 ICON "icons\\application.ico" // Set executable file icon 2 | 32512 ICON "icons\\window.ico" // Set window icon -------------------------------------------------------------------------------- /nimdoc.cfg: -------------------------------------------------------------------------------- 1 | --out:"index.html" 2 | --docCmd:skip 3 | --outDir:docs 4 | --index 5 | 6 | --git.url:"https://github.com/neroist/webview" 7 | --git.devel:main 8 | --git.commit:main -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # execuable files/dlls 2 | *.exe 3 | *.dll 4 | *.lib 5 | 6 | # files generated by clang 7 | *.ilk 8 | *.pdb 9 | 10 | # vscode generated directory 11 | .vscode -------------------------------------------------------------------------------- /examples/basic.nim: -------------------------------------------------------------------------------- 1 | import webview 2 | 3 | let w = newWebview() # or you can use create() 4 | 5 | w.title = "Basic Example" 6 | w.size = (480, 320) 7 | w.html = "Thanks for using webview!" 8 | 9 | w.run() 10 | w.destroy() 11 | -------------------------------------------------------------------------------- /tests/test_terminate.nim: -------------------------------------------------------------------------------- 1 | import std/unittest 2 | 3 | import webview 4 | 5 | test "start app loop and terminate it.": 6 | let w = newWebview() 7 | 8 | w.dispatch() do (web: Webview; _: pointer) {.cdecl.}: 9 | web.terminate() 10 | 11 | w.run() 12 | w.destroy() -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.nimble linguist-detectable=true 2 | *.nims linguist-detectable=true 3 | *.nim linguist-detectable=true 4 | 5 | *.cpp linguist-detectable=false 6 | *.hpp linguist-detectable=false 7 | *.c linguist-detectable=false 8 | *.h linguist-detectable=false 9 | *.m linguist-detectable=false 10 | -------------------------------------------------------------------------------- /examples/example_application/windows/compile.bat: -------------------------------------------------------------------------------- 1 | mkdir build 2 | 3 | :: If below doesn't work for you 4 | :: NOTE: `rc.exe` may be found at "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\rc.exe" if not in PATH 5 | :: rc /r /fo build\resources.res resources.rc 6 | :: nim c -d:useRC --cc:vcc main.nim 7 | 8 | windres -o build/resources.res -i resources.rc 9 | nim c main.nim -------------------------------------------------------------------------------- /examples/example_application/windows/main.nim: -------------------------------------------------------------------------------- 1 | import webview 2 | 3 | when defined(useRC): 4 | {.link: "build/resources.res".} 5 | else: 6 | {.link: "build/resources.o".} 7 | 8 | proc main = 9 | let w = newWebview() 10 | 11 | w.title = "Youtube" 12 | w.size = (800, 800) 13 | 14 | w.navigate("https://www.youtube.com") 15 | 16 | w.run() 17 | w.destroy() 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /tests/test_version.nim: -------------------------------------------------------------------------------- 1 | import std/unittest 2 | import std/strutils 3 | 4 | import webview 5 | 6 | test "webviewVersion()": 7 | let ver = webviewVersion() 8 | 9 | check ver.version.major == WEBVIEW_VERSION_MAJOR 10 | check ver.version.minor == WEBVIEW_VERSION_MINOR 11 | check ver.version.patch == WEBVIEW_VERSION_PATCH 12 | check ver.versionNumber.join().replace("\0", "") == WEBVIEW_VERSION_NUMBER 13 | check ver.preRelease.join().replace("\0", "") == WEBVIEW_VERSION_PRE_RELEASE 14 | check ver.buildMetadata.join().replace("\0", "") == WEBVIEW_VERSION_BUILD_METADATA -------------------------------------------------------------------------------- /tests/test_nim_api.nim: -------------------------------------------------------------------------------- 1 | import std/unittest 2 | 3 | import webview 4 | 5 | test "create a window, run app and terminate it.": 6 | proc cbAssertArg(w: Webview, arg: pointer) {.cdecl.} = 7 | check w != nil 8 | check cast[cstring](arg) == "arg" 9 | 10 | proc cbTerminate(w: Webview, arg: pointer) {.cdecl.} = 11 | check arg == nil 12 | w.terminate() 13 | 14 | let w = newWebview() 15 | 16 | w.setSize(280, 320, WebviewHintNone) 17 | w.setTitle("Test") 18 | 19 | w.navigate("https://github.com/zserge/webview") 20 | w.dispatch(cbAssertArg, cast[pointer](cstring "arg")) 21 | w.dispatch(cbTerminate, nil) 22 | 23 | w.run() 24 | w.destroy() 25 | -------------------------------------------------------------------------------- /webview.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.4.0" 4 | author = "neroist" 5 | description = "Webview bindings for Nim" 6 | license = "MIT" 7 | installFiles = @["webview.nim"] 8 | installDirs = @["libs"] 9 | 10 | 11 | # Tasks 12 | 13 | after install: 14 | when defined(linux) or defined(bsd): 15 | echo "" 16 | echo "This package requires some external dependencies." 17 | echo "" 18 | echo "If you're on a Debian-based system, install" 19 | echo " libgtk-3-dev" 20 | echo " libwebkit2gtk-4.0-dev" 21 | echo "If you're on a Fedora-based system, install" 22 | echo " gtk3-devel" 23 | echo " webkit2gtk4.0-devel" 24 | echo "If you're using a BSD system, install" 25 | echo " webkit2-gtk3" 26 | 27 | # Dependencies 28 | 29 | requires "nim >= 1.0.0" 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2023 neroist 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the “Software”), to deal in the 5 | Software without restriction, including without limitation the rights to use, copy, 6 | modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 7 | and to permit persons to whom the Software is furnished to do so, subject to the 8 | following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /tests/test_go_test.nim: -------------------------------------------------------------------------------- 1 | # See https://github.com/webview/webview/blob/master/webview_test.go 2 | 3 | import std/unittest 4 | import std/json 5 | 6 | import webview 7 | 8 | proc example() = 9 | let w = newWebview(true) 10 | 11 | w.setTitle("Hello") 12 | 13 | w.bind("noop") do (seq: string, req: JsonNode) -> string: 14 | echo "hello" 15 | return "\"hello\"" # need quotes so JS thinks its a string, not an identifier 16 | 17 | w.bind("add") do (seq: string, req: JsonNode) -> string: 18 | return $(req[0].getInt() + req[1].getInt()) 19 | 20 | w.bind("quit") do (seq: string, req: JsonNode) -> string: 21 | discard w.terminate() 22 | 23 | w.setHtml(): 24 | cstring """ 25 | 26 | 27 |
hello 28 | 29 | 44 | 45 | """ 46 | 47 | w.run() 48 | w.destroy() 49 | 50 | test "Golang webview test": 51 | example() 52 | -------------------------------------------------------------------------------- /libs/webview2/EventToken.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 8.01.0622 */ 7 | /* @@MIDL_FILE_HEADING( ) */ 8 | 9 | 10 | 11 | /* verify that the