Skip to content

Commit 2c48499

Browse files
committed
Initial commit.
0 parents  commit 2c48499

File tree

7 files changed

+119
-0
lines changed

7 files changed

+119
-0
lines changed

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ISC License
2+
3+
Copyright © 2021, John Chadwick <[email protected]>
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.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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.

cmd/demo/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/jchv/go-webview-selector
2+
3+
go 1.16
4+
5+
require github.com/jchv/go-webview2 v0.0.0-20210720204005-cbb937ae0f7f

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
github.com/jchv/go-webview2 v0.0.0-20210720204005-cbb937ae0f7f h1:LkvHq825sNdOAkjmr8CNIOG2UR8HrhcLgHAWzPfQy8c=
2+
github.com/jchv/go-webview2 v0.0.0-20210720204005-cbb937ae0f7f/go.mod h1:TQ8wBGSagb6vuJxuRsQXw5YjLJvC6aXvy/VSXGJK+8E=
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+
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6+
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ=
7+
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

shim_other.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// +build !windows
2+
3+
package webview
4+
5+
import (
6+
"unsafe"
7+
8+
"github.com/webview/webview"
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+
}

shim_windows.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)