From 99e7bfa71c6ce8e261a6c2b5f499742316d452a9 Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Mon, 19 Dec 2022 12:45:35 +0200 Subject: [PATCH 1/5] Embedded go-webview-selector --- contrib/ui/mesh-ui/webview.go | 5 ++-- contrib/ui/mesh-ui/webview_other.go | 34 +++++++++++++++++++++++++++ contrib/ui/mesh-ui/webview_windows.go | 31 ++++++++++++++++++++++++ go.mod | 7 +++--- go.sum | 6 +++++ makefile | 2 +- 6 files changed, 78 insertions(+), 7 deletions(-) diff --git a/contrib/ui/mesh-ui/webview.go b/contrib/ui/mesh-ui/webview.go index 52baad28..eff6d442 100644 --- a/contrib/ui/mesh-ui/webview.go +++ b/contrib/ui/mesh-ui/webview.go @@ -5,7 +5,6 @@ import ( "os" "github.com/RiV-chain/RiV-mesh/src/defaults" - "github.com/jchv/go-webview-selector" "github.com/docopt/docopt-go" ) @@ -37,10 +36,10 @@ func main() { Console(false) } debug := true - w := webview.New(debug) + w := New(debug) defer w.Destroy() w.SetTitle("RiV-mesh") - w.SetSize(690, 920, webview.HintFixed) + w.SetSize(690, 920, HintFixed) if confui.IndexHtml == "" { confui.IndexHtml = defaults.GetHttpEndpoint("http://localhost:19019") diff --git a/contrib/ui/mesh-ui/webview_other.go b/contrib/ui/mesh-ui/webview_other.go index 313ad87f..818e98bd 100644 --- a/contrib/ui/mesh-ui/webview_other.go +++ b/contrib/ui/mesh-ui/webview_other.go @@ -3,5 +3,39 @@ package main +import ( + "unsafe" + + "github.com/webview/webview" +) + func Console(show bool) { } + +type WebView = webview.WebView + +type Hint = webview.Hint + +const ( + // HintNone specifies that width and height are default size + HintNone Hint = iota + + // HintFixed specifies that window size can not be changed by a user + HintFixed + + // HintMin specifies that width and height are minimum bounds + HintMin + + // HintMax specifies that width and height are maximum bounds + HintMax +) + +// New creates a new webview in a new window. +func New(debug bool) WebView { + return webview.New(debug) +} + +// NewWindow creates a new webview using an existing window. +func NewWindow(debug bool, window unsafe.Pointer) WebView { + return webview.NewWindow(debug, window) +} diff --git a/contrib/ui/mesh-ui/webview_windows.go b/contrib/ui/mesh-ui/webview_windows.go index 556afedd..518e0e09 100755 --- a/contrib/ui/mesh-ui/webview_windows.go +++ b/contrib/ui/mesh-ui/webview_windows.go @@ -5,6 +5,9 @@ package main import ( "syscall" + "unsafe" + + "github.com/jchv/go-webview2" ) func Console(show bool) { @@ -22,3 +25,31 @@ func Console(show bool) { showWin.Call(hwnd, SW_HIDE) } } + +type WebView = webview2.WebView + +type Hint = webview2.Hint + +const ( + // HintNone specifies that width and height are default size + HintNone Hint = iota + + // HintFixed specifies that window size can not be changed by a user + HintFixed + + // HintMin specifies that width and height are minimum bounds + HintMin + + // HintMax specifies that width and height are maximum bounds + HintMax +) + +// New creates a new webview in a new window. +func New(debug bool) WebView { + return webview2.New(debug) +} + +// NewWindow creates a new webview using an existing window. +func NewWindow(debug bool, window unsafe.Pointer) WebView { + return webview2.NewWindow(debug, window) +} diff --git a/go.mod b/go.mod index 94ab7f6b..5e57f273 100644 --- a/go.mod +++ b/go.mod @@ -23,10 +23,11 @@ require ( require gerace.dev/zipfs v0.2.0 +require github.com/webview/webview v0.0.0-20221218140943-9db4b8c3e9af // indirect + require ( - github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf // indirect - github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb // indirect - github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5 // indirect + github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541 // indirect + github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect ) require ( diff --git a/go.sum b/go.sum index 291f5ac8..9b305b3a 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,12 @@ github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf h1:LfCNdI github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf/go.mod h1:RfUO9QcPUZ27qVS+rq9SYhhjsVNiolWwaIQdNjqFUsQ= github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb h1:oKKhiqJVbFqiPo+cj7zmY/R8AaOxgLQixUAOP/bKuRM= github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb/go.mod h1:/BNVc0Sw3Wj6Sz9uSxPwhCEUhhWs92hPde75K2YV24A= +github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541 h1:a3nfcpypvn/2WUzZzmZ9Kc75nPOpCrYnV45zrlGcGJM= +github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541/go.mod h1:/BNVc0Sw3Wj6Sz9uSxPwhCEUhhWs92hPde75K2YV24A= github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5 h1:pdFFlHXY9tZXmJz+tRSm1DzYEH4ebha7cffmm607bMU= github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= +github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck= +github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= github.com/kardianos/minwinsvc v1.0.2 h1:JmZKFJQrmTGa/WiW+vkJXKmfzdjabuEW4Tirj5lLdR0= github.com/kardianos/minwinsvc v1.0.2/go.mod h1:LUZNYhNmxujx2tR7FbdxqYJ9XDDoCd3MQcl1o//FWl4= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -99,6 +103,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/webview/webview v0.0.0-20221218140943-9db4b8c3e9af h1:QO77Qt3ucuL5l8tFIAMXrLaDx4rYI9Nz89x+nrJwYJo= +github.com/webview/webview v0.0.0-20221218140943-9db4b8c3e9af/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/makefile b/makefile index 3636abd3..6c82ade8 100644 --- a/makefile +++ b/makefile @@ -18,7 +18,7 @@ $(addprefix $(OUT_DIR)/,$(ALL_PLATFORMS)): linux-amd64: $(addprefix linux-amd64-,$(ALL_EXE)) windows-amd64: $(addprefix windows-amd64-,$(ALL_EXE)) -windows-amd64-%: BUILD_ENV=CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ +#windows-amd64-%: BUILD_ENV=CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ macos-amd64: $(addprefix macos-amd64-,$(ALL_EXE)) macos-amd64-%: BUILD_ENV=GO111MODULE=on From bf64987a4a41016598df395ff550179decb7a17f Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Mon, 19 Dec 2022 13:22:26 +0200 Subject: [PATCH 2/5] Init webview2 window on constuct --- contrib/ui/mesh-ui/webview_windows.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/ui/mesh-ui/webview_windows.go b/contrib/ui/mesh-ui/webview_windows.go index 518e0e09..96badc20 100755 --- a/contrib/ui/mesh-ui/webview_windows.go +++ b/contrib/ui/mesh-ui/webview_windows.go @@ -46,7 +46,16 @@ const ( // New creates a new webview in a new window. func New(debug bool) WebView { - return webview2.New(debug) + //return webview2.New(debug) + return webview2.NewWithOptions(webview2.WebViewOptions{ + Debug: debug, + WindowOptions: webview2.WindowOptions{ + IconId: 128, + Title: "RiV-mesh", + Width: 706, + Height: 960, + }, + }) } // NewWindow creates a new webview using an existing window. From 4a4bb2741e3541d84def1c77eb7e7389e7f9abec Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Mon, 19 Dec 2022 13:49:40 +0200 Subject: [PATCH 3/5] changed iconId to 101 --- contrib/ui/mesh-ui/webview_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/ui/mesh-ui/webview_windows.go b/contrib/ui/mesh-ui/webview_windows.go index 96badc20..70bb2bb5 100755 --- a/contrib/ui/mesh-ui/webview_windows.go +++ b/contrib/ui/mesh-ui/webview_windows.go @@ -50,7 +50,7 @@ func New(debug bool) WebView { return webview2.NewWithOptions(webview2.WebViewOptions{ Debug: debug, WindowOptions: webview2.WindowOptions{ - IconId: 128, + IconId: 101, Title: "RiV-mesh", Width: 706, Height: 960, From a827ec125d1292eec69d1f4e4e06534c8827025e Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Mon, 19 Dec 2022 14:42:09 +0200 Subject: [PATCH 4/5] linter fix --- src/admin/admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/admin/admin.go b/src/admin/admin.go index 7db6f4a6..66526c81 100644 --- a/src/admin/admin.go +++ b/src/admin/admin.go @@ -331,7 +331,7 @@ func (a *AdminSocket) StartHttpServer(configFn string, nc *config.NodeConfig) { } fmt.Fprint(w, string(b[:])) case "POST": - handlePost() + _ = handlePost() case "PUT": if handleDelete() == nil { if handlePost() == nil { From 07cd6c22bf2416451eb74e40aefe9dbb2eb257d5 Mon Sep 17 00:00:00 2001 From: Mihail Slobodyanuk Date: Mon, 19 Dec 2022 14:55:22 +0200 Subject: [PATCH 5/5] go mod tidy --- go.mod | 12 ++++++------ go.sum | 5 ----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 5e57f273..46913fa5 100644 --- a/go.mod +++ b/go.mod @@ -21,15 +21,15 @@ require ( golang.zx2c4.com/wireguard/windows v0.4.12 ) -require gerace.dev/zipfs v0.2.0 - -require github.com/webview/webview v0.0.0-20221218140943-9db4b8c3e9af // indirect - require ( - github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541 // indirect - github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect + gerace.dev/zipfs v0.2.0 + github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541 ) +require github.com/webview/webview v0.0.0-20221218140943-9db4b8c3e9af + +require github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect + require ( github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 github.com/dustin/go-humanize v1.0.0 // indirect diff --git a/go.sum b/go.sum index 9b305b3a..350dcfc7 100644 --- a/go.sum +++ b/go.sum @@ -47,13 +47,8 @@ github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwM github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw= github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio= -github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf h1:LfCNdIjo0pYj7ChAEkRZKPW/GKOzQLGqz/8CbDTxBvE= -github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf/go.mod h1:RfUO9QcPUZ27qVS+rq9SYhhjsVNiolWwaIQdNjqFUsQ= -github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb h1:oKKhiqJVbFqiPo+cj7zmY/R8AaOxgLQixUAOP/bKuRM= -github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb/go.mod h1:/BNVc0Sw3Wj6Sz9uSxPwhCEUhhWs92hPde75K2YV24A= github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541 h1:a3nfcpypvn/2WUzZzmZ9Kc75nPOpCrYnV45zrlGcGJM= github.com/jchv/go-webview2 v0.0.0-20221027045535-e2a104b55541/go.mod h1:/BNVc0Sw3Wj6Sz9uSxPwhCEUhhWs92hPde75K2YV24A= -github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5 h1:pdFFlHXY9tZXmJz+tRSm1DzYEH4ebha7cffmm607bMU= github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=