webview_go icon indicating copy to clipboard operation
webview_go copied to clipboard

How to hide the window without destroying it.

Open precisionpete opened this issue 2 years ago • 2 comments
trafficstars

Is there a way to show/hide the webview without destroying and recreating it? I would like an icon in the taskbar (like lantern systray) that when I click it, the webview ui shows or hides. I don't want to destroy it each time. Just make it invisible.

precisionpete avatar Oct 09 '23 02:10 precisionpete

I am also running into the problem that Destroy is not working. So at the moment, I have no way to control the window once it has been created. If I try to close (unsuccessfully) and then reopen, the whole thing crashes with a fatalsignal. I suspect this is a problem in the core library and not the Go bindings...

And... I cannot close it internally via javascript because of error: "Can't close the window since it was not opened by JavaScript". And calling the close binding in Go does not work...

this: Window {listeners: Object, Infinity: Infinity, window: Window, NaN: NaN, closewindow: function, …}

This is the way I understand the code to work. But it doesn't. Please comment re the Destroy/Terminate. The docs are a bit vague on that.

Show/Hide would also be a fantastic addition.

func OpenWindow() {
	wv = webview.New(true)
	defer wv.Destroy()

	wv.SetTitle("The Title")
	wv.SetSize(800, 600, webview.HintNone)

	wv.Bind("closewindow", CloseWindow)
	wv.Navigate(GuiUrl)
	wv.Run()
}

func CloseWindow() error {
	wv.Destroy()
	wv.Terminate()

	return nil
}

precisionpete avatar Oct 09 '23 14:10 precisionpete

//use windows api        import  "github.com/lxn/win"
w := webview.NewWindow(true, nil)
w.SetTitle("xdfsaldfkeo")
w.SetSize(800, 600, webview.HintNone)
w.Navigate("https://www.example.com")
hwnd := win.HWND(w.Window())

// hide titlebar
style := win.GetWindowLong(hwnd, win.GWL_STYLE)
style &^= win.WS_CAPTION | win.WS_SYSMENU | win.WS_THICKFRAME | win.WS_MINIMIZEBOX | win.WS_MAXIMIZEBOX | win.PFM_BORDER
win.SetWindowLong(hwnd, win.GWL_STYLE, style)

// transparent   
ext := win.GetWindowLong(hwnd, win.GWL_EXSTYLE)
ext |= win.WS_EX_LAYOUTRTL
win.SetWindowLong(hwnd, win.GWL_EXSTYLE, ext)

// hide window
w.bind("hide", fun(){win.ShowWindow(hwnd , win.SW_HIDE)})
// show window
w.bind("hide", fun(){win.ShowWindow(hwnd, win.SW_SHOW)})

win.Run()

i-xiao-zi avatar Dec 06 '23 09:12 i-xiao-zi