From 000f2441c93c8b6105c7e344ad714a7522fab995 Mon Sep 17 00:00:00 2001 From: Star Date: Thu, 24 Oct 2024 13:29:33 +0800 Subject: [PATCH] support RunInMain OnKill --- client.go | 14 +++++++------- go.mod | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 1ea55e8..9b4b6a8 100644 --- a/client.go +++ b/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, }) } diff --git a/go.mod b/go.mod index ae9f345..da81dbc 100644 --- a/go.mod +++ b/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