From 105c10aee72a0edb0cf08d36abbd3aceb9dfafcc Mon Sep 17 00:00:00 2001 From: Francesco Luzzi <81475751+FrancescoLuzzi@users.noreply.github.com> Date: Tue, 29 Apr 2025 16:25:59 +0200 Subject: [PATCH] fix: don't return error when SaveFileDialog is cancelled by the user --- v2/internal/go-common-file-dialog/cfd/errors.go | 2 ++ v2/internal/go-common-file-dialog/cfd/iShellItemArray.go | 2 +- v2/internal/go-common-file-dialog/cfd/vtblCommonFunc.go | 6 +++--- website/src/pages/changelog.mdx | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/v2/internal/go-common-file-dialog/cfd/errors.go b/v2/internal/go-common-file-dialog/cfd/errors.go index eeb48a9e9..4ca3300b9 100644 --- a/v2/internal/go-common-file-dialog/cfd/errors.go +++ b/v2/internal/go-common-file-dialog/cfd/errors.go @@ -4,4 +4,6 @@ import "errors" var ( ErrCancelled = errors.New("cancelled by user") + ErrInvalidGUID = errors.New("guid cannot be nil") + ErrEmptyFilters = errors.New("must specify at least one filter") ) diff --git a/v2/internal/go-common-file-dialog/cfd/iShellItemArray.go b/v2/internal/go-common-file-dialog/cfd/iShellItemArray.go index bdd459402..743313d92 100644 --- a/v2/internal/go-common-file-dialog/cfd/iShellItemArray.go +++ b/v2/internal/go-common-file-dialog/cfd/iShellItemArray.go @@ -58,7 +58,7 @@ func (vtbl *iShellItemArrayVtbl) getItemAt(objPtr unsafe.Pointer, index uintptr) return "", err } if shellItem == nil { - return "", fmt.Errorf("shellItem is nil") + return "", ErrCancelled } defer shellItem.vtbl.release(unsafe.Pointer(shellItem)) return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem)) diff --git a/v2/internal/go-common-file-dialog/cfd/vtblCommonFunc.go b/v2/internal/go-common-file-dialog/cfd/vtblCommonFunc.go index 9107c1904..eb142198b 100644 --- a/v2/internal/go-common-file-dialog/cfd/vtblCommonFunc.go +++ b/v2/internal/go-common-file-dialog/cfd/vtblCommonFunc.go @@ -34,7 +34,7 @@ func (vtbl *iModalWindowVtbl) show(objPtr unsafe.Pointer, hwnd uintptr) error { func (vtbl *iFileDialogVtbl) setFileTypes(objPtr unsafe.Pointer, filters []FileFilter) error { cFileTypes := len(filters) if cFileTypes < 0 { - return fmt.Errorf("must specify at least one filter") + return ErrEmptyFilters } comDlgFilterSpecs := make([]comDlgFilterSpec, cFileTypes) for i := 0; i < cFileTypes; i++ { @@ -168,7 +168,7 @@ func (vtbl *iFileDialogVtbl) getResultString(objPtr unsafe.Pointer) (string, err return "", err } if shellItem == nil { - return "", fmt.Errorf("shellItem is nil") + return "", ErrCancelled } defer shellItem.vtbl.release(unsafe.Pointer(shellItem)) return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem)) @@ -177,7 +177,7 @@ func (vtbl *iFileDialogVtbl) getResultString(objPtr unsafe.Pointer) (string, err func (vtbl *iFileDialogVtbl) setClientGuid(objPtr unsafe.Pointer, guid *ole.GUID) error { // Ensure the GUID is not nil if guid == nil { - return fmt.Errorf("guid cannot be nil") + return ErrInvalidGUID } // Call the SetClientGuid method diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index a5c8ea7c2..136da4477 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed Window size issues on Wayland [PR](https://github.com/wailsapp/wails/pull/4047) by [@lyimmi](https://github.com/lyimmi) +- Fixed SaveFileDialog cancellation result [PR](https://github.com/wailsapp/wails/pull/4253) by [@FrancescoLuzzi](https://github.com/FrancescoLuzzi) ### Changed @@ -88,10 +89,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed CGO memory issue on Darwin by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3590) - Fixed an error that occurred when an author name contains a string that is not suitable for JSON. Fixed by @taiseiotsuka in [PR](https://github.com/wailsapp/wails/pull/3638) - Fixed MacOS build to use `outputfilename` from wails.json. [#3200](https://github.com/wailsapp/wails/issues/3200) -- Fixed file drop events on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/3595) by @FrancescoLuzzi - Fixed doctor command not finding pkg-config on Solus. [PR #3670](https://github.com/wailsapp/wails/pull/3670) by [@ianmjones](https://github.com/ianmjones) - Fixed binding for struct fields that were exported but had no json tags. [PR #3678](https://github.com/wailsapp/wails/pull/3678) -- Fixed file drop events on Windows in [PR](https://github.com/wailsapp/wails/pull/3595) by @FrancescoLuzzi +- Fixed file drop events on Windows in [PR](https://github.com/wailsapp/wails/pull/3595) by [@FrancescoLuzzi](https://github.com/FrancescoLuzzi) - Modified `ZoomFactor` and `IsZoomControlEnabled` options to be Windows-only options in PR[#3644](https://github.com/wailsapp/wails/pull/3644) by @levinit - Added nil check for Drag-n-Drop on Windows. Fixed by in [PR](https://github.com/wailsapp/wails/pull/3597) by @leaanthony based on the suggestion by @Alpa-1 in [#3596](https://github.com/wailsapp/wails/issues/3596). - Fixed typos in various .mdx files. [PR #3628](https://github.com/wailsapp/wails/pull/3628) by [@deining](https://github.com/deining)