U: any > interface{}

This commit is contained in:
杨红岩 2023-12-30 23:13:29 +08:00
parent cc0525c4b8
commit 27608eb931
6 changed files with 18 additions and 5 deletions

View File

@ -40,7 +40,7 @@ func main() {
// 在渲染进程页面加载时触发主进程 browserOn 事件
app.SetOnRenderLoadStart(func(browser *cef.ICefBrowser, frame *cef.ICefFrame, transitionType consts.TCefTransitionType) {
url := frame.Url()
arguments := []any{url}
arguments := []interface{}{url}
//触发主进程事件, 并接收返回结果
ipc.EmitTargetAndCallback("browserOn", target.NewTargetMain(), arguments, func(result string) {
// 接收主进程直接返回结果

View File

@ -50,7 +50,7 @@ func timeTask() {
//将数据发送出去
ipc.Emit("js-on-event-demo", fmt.Sprintf("Go发送的数据: %d", param0), float64(param0+10))
// 如果JS返回结果, 需要通过回调函数入参方式接收返回值
ipc.EmitAndCallback("js-on-event-demo-return", []any{fmt.Sprintf("Go发送的数据: %d", param0), float64(param0 + 10)}, func(r1 string) {
ipc.EmitAndCallback("js-on-event-demo-return", []interface{}{fmt.Sprintf("Go发送的数据: %d", param0), float64(param0 + 10)}, func(r1 string) {
//需要正确的获取类型,否则会失败
fmt.Println("JS返回数据:", r1)
})

View File

@ -50,7 +50,7 @@ func main() {
iTarget := info.Target(target.TgJs)
ok = ipc.EmitTarget("receiveMessage", iTarget, time.Now().String())
println("ipc.EmitTarget", ok, iTarget.BrowserId())
ok = ipc.EmitTargetAndCallback("receiveMessage", iTarget, []any{"带有callback的触发事件: " + time.Now().String()}, func() {
ok = ipc.EmitTargetAndCallback("receiveMessage", iTarget, []interface{}{"带有callback的触发事件: " + time.Now().String()}, func() {
fmt.Println("target callback")
})
println("ipc.EmitTargetAndCallback", ok, iTarget.BrowserId())
@ -59,7 +59,7 @@ func main() {
// 主窗口接收, 主窗口被关闭后发送无效
ok = ipc.Emit("receiveMessage", "测试当前新主窗口接收")
println("ipc.Emit", ok)
ok = ipc.EmitAndCallback("receiveMessage", []any{"带有callback的触发事件"}, func() {
ok = ipc.EmitAndCallback("receiveMessage", []interface{}{"带有callback的触发事件"}, func() {
fmt.Println("callback")
})
println("ipc.EmitAndCallback", ok)

View File

@ -9,7 +9,7 @@ import (
var spinValues = []string{"🍒", "💎", "7⃣", "🍊", "🔔", "⭐", "🍇", "🍀"}
func randomChoice[T any](choices []T) (*T, error) {
func randomChoice(choices []string) (*string, error) {
v, err := rand.Int(rand.Reader, big.NewInt(int64(len(choices))))
if err != nil {
return nil, err

View File

@ -0,0 +1,5 @@
SET CGO_ENABLED=0
set GOARCH=386
set GOOS=windows
go build windowsxp.go

View File

@ -73,6 +73,14 @@ func (m *BrowserWindow) OnFormCreate(sender lcl.IObject) {
//m.chromium.SetOnOpenUrlFromTab(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, targetUrl string, targetDisposition consts.TCefWindowOpenDisposition, userGesture bool) bool {
// return true
//})
m.chromium.SetOnTooltip(func(sender lcl.IObject, browser *cef.ICefBrowser, text *string) (result bool) {
fmt.Println("text", *text)
return true
})
m.chromium.SetOnRenderCompMsg(func(sender lcl.IObject, message *types.TMessage, lResult *types.LRESULT, aHandled *bool) {
fmt.Println("SetOnRenderCompMsg", *lResult, *aHandled)
//*aHandled = true
})
}
func (m *BrowserWindow) show(sender lcl.IObject) {