From 9b81ea70c7991e0f4c408fad796be74424c09f67 Mon Sep 17 00:00:00 2001 From: guixue Date: Mon, 18 Sep 2023 21:25:21 +0800 Subject: [PATCH] fix OpenFileDialog will locked under macos --- v3/pkg/application/dialogs.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/v3/pkg/application/dialogs.go b/v3/pkg/application/dialogs.go index 2a127a34693..7aaf0283616 100644 --- a/v3/pkg/application/dialogs.go +++ b/v3/pkg/application/dialogs.go @@ -1,6 +1,7 @@ package application import ( + "runtime" "strings" "sync" ) @@ -265,7 +266,16 @@ func (d *OpenFileDialogStruct) PromptForSingleSelection() (string, error) { if d.impl == nil { d.impl = newOpenFileDialogImpl(d) } - selection, err := invokeSyncWithResultAndError(d.impl.show) + var selection []string + var err error + //Fixed: macos will locked + // C.showOpenFileDialog has checked dispatch_async dispatch_get_main_queue() + if runtime.GOOS == "darwin" { + selection, err = d.impl.show() + } else { + selection, err = invokeSyncWithResultAndError(d.impl.show) + } + var result string if len(selection) > 0 { result = selection[0] @@ -289,7 +299,15 @@ func (d *OpenFileDialogStruct) PromptForMultipleSelection() ([]string, error) { if d.impl == nil { d.impl = newOpenFileDialogImpl(d) } - return invokeSyncWithResultAndError(d.impl.show) + + var selection []string + var err error + if runtime.GOOS == "darwin" { + selection, err = d.impl.show() + } else { + selection, err = invokeSyncWithResultAndError(d.impl.show) + } + return selection, err } func (d *OpenFileDialogStruct) SetMessage(message string) *OpenFileDialogStruct {