From ca449a7706b2fc45fb1374ffa508756f1af47100 Mon Sep 17 00:00:00 2001 From: hkhere <33268704+hkhere@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:57:53 +0800 Subject: [PATCH] [V3] Windows: fix(application): handle error and type assertion in save file dialog (#4284) * fix(application): handle error and type assertion in save file dialog --------- Co-authored-by: hkhere Co-authored-by: Atterpac <89053530+atterpac@users.noreply.github.com> Co-authored-by: Lea Anthony --- v3/UNRELEASED_CHANGELOG.md | 1 + v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go | 5 +++-- v3/pkg/application/dialogs_windows.go | 9 ++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 179aaa7d8..eec808a19 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file ## Fixed +- Fixed panic when closing or cancelling a `SaveFileDialog` on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284) by @hkhere - Fixed HTML level drag and drop on Windows by [@mbaklor](https://github.com/mbaklor) in [#4259](https://github.com/wailsapp/wails/pull/4259) ## Deprecated diff --git a/v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go b/v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go index 9107c1904..a59ff1ed1 100644 --- a/v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go +++ b/v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go @@ -4,10 +4,11 @@ package cfd import ( "fmt" - "github.com/go-ole/go-ole" "strings" "syscall" "unsafe" + + "github.com/go-ole/go-ole" ) func hresultToError(hr uintptr) error { @@ -168,7 +169,7 @@ func (vtbl *iFileDialogVtbl) getResultString(objPtr unsafe.Pointer) (string, err return "", err } if shellItem == nil { - return "", fmt.Errorf("shellItem is nil") + return "", ErrorCancelled } defer shellItem.vtbl.release(unsafe.Pointer(shellItem)) return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem)) diff --git a/v3/pkg/application/dialogs_windows.go b/v3/pkg/application/dialogs_windows.go index ef5b625fc..64e72afe7 100644 --- a/v3/pkg/application/dialogs_windows.go +++ b/v3/pkg/application/dialogs_windows.go @@ -196,9 +196,16 @@ func (m *windowSaveFileDialog) show() (chan string, error) { func() (cfd.Dialog, error) { return cfd.NewSaveFileDialog(config) }, false) + if err != nil { + close(files) + return files, err + } go func() { defer handlePanic() - files <- result.(string) + f, ok := result.(string) + if ok { + files <- f + } close(files) }() return files, err