├── go.mod ├── cmd └── demo │ └── main.go ├── README.md ├── LICENSE.md ├── shim_other.go ├── shim_windows.go └── go.sum /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jchv/go-webview-selector 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb 7 | github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6 8 | ) 9 | -------------------------------------------------------------------------------- /cmd/demo/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/jchv/go-webview-selector" 7 | ) 8 | 9 | func main() { 10 | debug := true 11 | w := webview.New(debug) 12 | if w == nil { 13 | log.Fatalln("Failed to load webview.") 14 | } 15 | defer w.Destroy() 16 | w.SetTitle("Minimal webview example") 17 | w.SetSize(800, 600, webview.HintFixed) 18 | w.Navigate("https://en.m.wikipedia.org/wiki/Main_Page") 19 | w.Run() 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Webview Selector 2 | This library is a tiny shim that provides access to a native webview for a given platform. It selects between two implementations: 3 | 4 | * On Windows, [go-webview2](https://github.com/jchv/go-webview2) will be chosen. It embeds a copy of WebView2Loader, so it should work out of the box on any setup that has the WebView 2 runtime installed, which should include up-to-date Windows 10 installations and Windows 11. (As well, WebView 2 runtime is available going backwards to Windows 7.) This library does not require CGo and thus will build and run with `CGO_ENABLED=0`. 5 | 6 | * On other operating systems, [webview/webview](https://github.com/webview/webview) will be used. This runtime requires CGo, but supports a wide variety of platforms. 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # ISC License 2 | 3 | Copyright © 2021, John Chadwick 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 8 | -------------------------------------------------------------------------------- /shim_other.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package webview 4 | 5 | import ( 6 | "unsafe" 7 | 8 | "github.com/webview/webview_go" 9 | ) 10 | 11 | type WebView = webview.WebView 12 | 13 | type Hint = webview.Hint 14 | 15 | const ( 16 | // HintNone specifies that width and height are default size 17 | HintNone Hint = iota 18 | 19 | // HintFixed specifies that window size can not be changed by a user 20 | HintFixed 21 | 22 | // HintMin specifies that width and height are minimum bounds 23 | HintMin 24 | 25 | // HintMax specifies that width and height are maximum bounds 26 | HintMax 27 | ) 28 | 29 | // New creates a new webview in a new window. 30 | func New(debug bool) WebView { 31 | return webview.New(debug) 32 | } 33 | 34 | // NewWindow creates a new webview using an existing window. 35 | func NewWindow(debug bool, window unsafe.Pointer) WebView { 36 | return webview.NewWindow(debug, window) 37 | } 38 | -------------------------------------------------------------------------------- /shim_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package webview 4 | 5 | import ( 6 | "unsafe" 7 | 8 | "github.com/jchv/go-webview2" 9 | ) 10 | 11 | type WebView = webview2.WebView 12 | 13 | type Hint = webview2.Hint 14 | 15 | const ( 16 | // HintNone specifies that width and height are default size 17 | HintNone Hint = iota 18 | 19 | // HintFixed specifies that window size can not be changed by a user 20 | HintFixed 21 | 22 | // HintMin specifies that width and height are minimum bounds 23 | HintMin 24 | 25 | // HintMax specifies that width and height are maximum bounds 26 | HintMax 27 | ) 28 | 29 | // New creates a new webview in a new window. 30 | func New(debug bool) WebView { 31 | return webview2.New(debug) 32 | } 33 | 34 | // NewWindow creates a new webview using an existing window. 35 | func NewWindow(debug bool, window unsafe.Pointer) WebView { 36 | return webview2.NewWindow(debug, window) 37 | } 38 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb h1:oKKhiqJVbFqiPo+cj7zmY/R8AaOxgLQixUAOP/bKuRM= 2 | github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb/go.mod h1:/BNVc0Sw3Wj6Sz9uSxPwhCEUhhWs92hPde75K2YV24A= 3 | github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5 h1:pdFFlHXY9tZXmJz+tRSm1DzYEH4ebha7cffmm607bMU= 4 | github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= 5 | github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6 h1:VQpB2SpK88C6B5lPHTuSZKb2Qee1QWwiFlC5CKY4AW0= 6 | github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6/go.mod h1:yE65LFCeWf4kyWD5re+h4XNvOHJEXOCOuJZ4v8l5sgk= 7 | golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 8 | golang.org/x/sys v0.0.0-20210218145245-beda7e5e158e h1:f5mksnk+hgXHnImpZoWj64ja99j9zV7YUgrVG95uFE4= 9 | golang.org/x/sys v0.0.0-20210218145245-beda7e5e158e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 10 | --------------------------------------------------------------------------------