Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide the window without destroying it. #13

Open
precisionpete opened this issue Oct 9, 2023 · 2 comments
Open

How to hide the window without destroying it. #13

precisionpete opened this issue Oct 9, 2023 · 2 comments

Comments

@precisionpete
Copy link

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
Copy link
Author

precisionpete commented Oct 9, 2023

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
}

@i-xiao-zi
Copy link

i-xiao-zi commented Dec 6, 2023

//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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants