[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 <hk@tinyclouds.cn>
Co-authored-by: Atterpac <89053530+atterpac@users.noreply.github.com>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
hkhere 2025-08-04 17:57:53 +08:00 committed by GitHub
commit ca449a7706
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View file

@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file
## Fixed
<!-- Bug fixes -->
- 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

View file

@ -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))

View file

@ -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