progrium/darwinkit

Help Wanted: Implementing `webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:` and using `NSOpenPanel` in Go

Closed this issue · 3 comments

Hi @progrium, thanks for this library. Tbh, It was love at first sight and I've started using this in an Opensource Project. But I have an issue with implementing the webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler: method and using NSOpenPanel. After reading so many articles on this, I still can't figure out why file uploads always end in a panic:

Here's my implementation:

addMethodToDelegate("webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:", func(_ objc.Object, webView objc.Object, openPanelParams objc.
		Object, frame objc.Object, completionHandler objc.Object) {
		panel := objc.Get("NSOpenPanel").Send("openPanel")
		panel.Send("beginWithCompletionHandler:", completionHandler)
	})

But I always get this panic after selecting the file to be uploaded.

2023-07-10 23:39:23.262 dexc-desktop[4840:84904] +[CATransaction synchronize] called within transaction
2023-07-10 23:39:23.397 dexc-desktop[4840:84904] +[CATransaction synchronize] called within transaction
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x7ff8063e249d]

runtime stack:
runtime.throw({0x101a2d9d8?, 0x7ff80e6b79b2?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7ff7bfefd198 sp=0x7ff7bfefd168 pc=0x10003b55d
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:825 +0x3e9 fp=0x7ff7bfefd1f8 sp=0x7ff7bfefd198 pc=0x1000527e9

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x101431d90, 0xc00083db78)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc00083db50 sp=0xc00083db18 pc=0x1000072dc
github.com/progrium/macdriver/cocoa._Cfunc_NSApplication_inst_run(0x103b0ea10)
        _cgo_gotypes.go:449 +0x45 fp=0xc00083db78 sp=0xc00083db50 pc=0x100cec8a5
github.com/progrium/macdriver/cocoa.gen_NSApplication.Run.func1({{0x102453e68?, 0xc0005a4050?}})
        /Users/[Redacted]/go/pkg/mod/github.com/progrium/macdriver@v0.2.0/cocoa/cocoa_objc.gen.go:8656 +0x4d fp=0xc00083dbb0 sp=0xc00083db78 pc=0x100d1408d
github.com/progrium/macdriver/cocoa.gen_NSApplication.Run({{0x102453e68?, 0xc0005a4050?}})
        /Users/[Redacted]/go/pkg/mod/github.com/progrium/macdriver@v0.2.0/cocoa/cocoa_objc.gen.go:8656 +0x25 fp=0xc00083dbd0 sp=0xc00083dbb0 pc=0x100d14005
main.mainCore()
        /Users/[Redacted]/Desktop/dcrdex/client/cmd/dexc-desktop/app_darwin.go:468 +0x187a fp=0xc00083df38 sp=0xc00083dbd0 pc=0x10142305a
main.main()
        /Users/[Redacted]/Desktop/dcrdex/client/cmd/dexc-desktop/main.go:134 +0x19 fp=0xc00083df80 sp=0xc00083df38 pc=0x1014256b9
runtime.main()
        /usr/local/go/src/runtime/proc.go:250 +0x207 fp=0xc00083dfe0 sp=0xc00083df80 pc=0x10003de07
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00083dfe8 sp=0xc00083dfe0 pc=0x1000733c1

I'd appreciate it if you can find time to help with this.

Used a workaround for this already but still good to have NSOpenPanel.

tmc commented

Can you share full failing code somewhere?

Added NSOpenPanel in #144

Added NSOpenPanel in #144

Nice, thank you.

Can you share full failing code somewhere?

Well, it was actually not a "failing code". The issue was executing the completionHandler(the function that receives the selected URLs from [NSOpenPanel URLs]) in Go code.