support RunInMain OnKill

This commit is contained in:
Star 2024-10-24 13:29:33 +08:00
parent 35c2a0f3cf
commit 000f2441c9
2 changed files with 8 additions and 8 deletions

View File

@ -47,7 +47,7 @@ type Webview struct {
id uint64 id uint64
w webview.WebView w webview.WebView
isRunning bool isRunning bool
isAsync bool // isAsync bool
isDebug bool isDebug bool
webRoot string webRoot string
watcher *watcher.Watcher watcher *watcher.Watcher
@ -274,14 +274,13 @@ func init() {
} }
w := &Webview{isDebug: isDebug, html: html, url: url} w := &Webview{isDebug: isDebug, html: html, url: url}
startChan := make(chan bool, 1) // startChan := make(chan bool, 1)
go func() { gojs.RunInMain(func() {
windowsLock.Lock() windowsLock.Lock()
w.id = windowsId w.id = windowsId
windowsId++ windowsId++
windows[w.id] = w windows[w.id] = w
windowsLock.Unlock() windowsLock.Unlock()
w.w = webview.New(isDebug) w.w = webview.New(isDebug)
w.w.SetTitle(title) w.w.SetTitle(title)
w.w.SetSize(width, height, getSizeMode(sizeMode)) w.w.SetSize(width, height, getSizeMode(sizeMode))
@ -309,13 +308,13 @@ func init() {
w.isRunning = true w.isRunning = true
w.reload() w.reload()
startChan <- true // startChan <- true
w.w.Run() w.w.Run()
// fmt.Println("====== w.w.Run() end") // fmt.Println("====== w.w.Run() end")
w.doClose() w.doClose()
}() })
<-startChan // <-startChan
return vm.ToValue(gojs.MakeMap(w)) return vm.ToValue(gojs.MakeMap(w))
}, },
"closeAll": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { "closeAll": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
@ -330,5 +329,6 @@ func init() {
TsCode: clientTS, TsCode: clientTS,
Example: clientMD, Example: clientMD,
WaitForStop: Wait, WaitForStop: Wait,
OnKill: CloseAll,
}) })
} }

2
go.mod
View File

@ -5,7 +5,6 @@ go 1.18
require ( require (
apigo.cc/gojs v0.0.1 apigo.cc/gojs v0.0.1
github.com/ssgo/tool v0.4.27 github.com/ssgo/tool v0.4.27
github.com/ssgo/u v1.7.9
github.com/webview/webview_go v0.0.0-20240831120633-6173450d4dd6 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/config v1.7.7 // indirect
github.com/ssgo/log v1.7.7 // indirect github.com/ssgo/log v1.7.7 // indirect
github.com/ssgo/standard 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/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect