webview / webview_go

Go language bindings for the webview library.
MIT License
176 stars 27 forks source link

How to hide the window without destroying it. #13

Open precisionpete opened 9 months ago

precisionpete commented 9 months ago

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 commented 9 months ago

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 commented 7 months ago
//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()