Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ type WebView interface {
// f must be a function
// f must return either value and error or just error
Bind(name string, f interface{}) error

// Show shows the native window if hidden.
// It will also restore a minimized window.
Show()

// Hide hides the native window from the screen and taskbar.
Hide()
}
5 changes: 4 additions & 1 deletion internal/w32/w32.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
User32SetWindowPos = user32.NewProc("SetWindowPos")
User32IsDialogMessage = user32.NewProc("IsDialogMessage")
User32GetAncestor = user32.NewProc("GetAncestor")
User32IsIconic = user32.NewProc("IsIconic")
)

const (
Expand Down Expand Up @@ -73,7 +74,9 @@ const (
)

const (
SWShow = 5
SWHide = 0
SWShow = 5
SWRestore = 9
)

const (
Expand Down
34 changes: 28 additions & 6 deletions webview.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type browser interface {
Eval(script string)
NotifyParentWindowPositionChanged() error
Focus()
Show() error
}

type webview struct {
Expand All @@ -59,11 +60,12 @@ type webview struct {
}

type WindowOptions struct {
Title string
Width uint
Height uint
IconId uint
Center bool
Title string
Width uint
Height uint
IconId uint
Center bool
StartHidden bool
}

type WebViewOptions struct {
Expand Down Expand Up @@ -333,17 +335,37 @@ func (w *webview) CreateWithOptions(opts WindowOptions) bool {
)
setWindowContext(w.hwnd, w)

_, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWShow)
_, _, _ = w32.User32UpdateWindow.Call(w.hwnd)
_, _, _ = w32.User32SetFocus.Call(w.hwnd)

if !w.browser.Embed(w.hwnd) {
return false
}
w.browser.Resize()
if !opts.StartHidden {
_, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWShow)
_ = w.browser.Show()
}
return true
}

func (w *webview) Hide() {
_, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWHide)
}

func (w *webview) Show() {
ret, _, _ := w32.User32IsIconic.Call(w.hwnd)
isMinimized := ret != 0

if isMinimized {
_, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWRestore)
} else {
_, _, _ = w32.User32ShowWindow.Call(w.hwnd, w32.SWShow)
}

_ = w.browser.Show()
}

func (w *webview) Destroy() {
_, _, _ = w32.User32PostMessageW.Call(w.hwnd, w32.WMClose, 0, 0)
}
Expand Down