support RunInMain OnKill
This commit is contained in:
parent
35c2a0f3cf
commit
000f2441c9
14
client.go
14
client.go
@ -47,7 +47,7 @@ type Webview struct {
|
||||
id uint64
|
||||
w webview.WebView
|
||||
isRunning bool
|
||||
isAsync bool
|
||||
// isAsync bool
|
||||
isDebug bool
|
||||
webRoot string
|
||||
watcher *watcher.Watcher
|
||||
@ -274,14 +274,13 @@ func init() {
|
||||
}
|
||||
|
||||
w := &Webview{isDebug: isDebug, html: html, url: url}
|
||||
startChan := make(chan bool, 1)
|
||||
go func() {
|
||||
// startChan := make(chan bool, 1)
|
||||
gojs.RunInMain(func() {
|
||||
windowsLock.Lock()
|
||||
w.id = windowsId
|
||||
windowsId++
|
||||
windows[w.id] = w
|
||||
windowsLock.Unlock()
|
||||
|
||||
w.w = webview.New(isDebug)
|
||||
w.w.SetTitle(title)
|
||||
w.w.SetSize(width, height, getSizeMode(sizeMode))
|
||||
@ -309,13 +308,13 @@ func init() {
|
||||
w.isRunning = true
|
||||
|
||||
w.reload()
|
||||
startChan <- true
|
||||
// startChan <- true
|
||||
w.w.Run()
|
||||
// fmt.Println("====== w.w.Run() end")
|
||||
w.doClose()
|
||||
}()
|
||||
})
|
||||
|
||||
<-startChan
|
||||
// <-startChan
|
||||
return vm.ToValue(gojs.MakeMap(w))
|
||||
},
|
||||
"closeAll": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||
@ -330,5 +329,6 @@ func init() {
|
||||
TsCode: clientTS,
|
||||
Example: clientMD,
|
||||
WaitForStop: Wait,
|
||||
OnKill: CloseAll,
|
||||
})
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,6 @@ go 1.18
|
||||
require (
|
||||
apigo.cc/gojs v0.0.1
|
||||
github.com/ssgo/tool v0.4.27
|
||||
github.com/ssgo/u v1.7.9
|
||||
github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6
|
||||
)
|
||||
|
||||
@ -17,6 +16,7 @@ require (
|
||||
github.com/ssgo/config v1.7.7 // indirect
|
||||
github.com/ssgo/log v1.7.7 // indirect
|
||||
github.com/ssgo/standard v1.7.7 // indirect
|
||||
github.com/ssgo/u v1.7.9 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
Loading…
Reference in New Issue
Block a user