Skip to content

Commit ca449a7

Browse files
hkhereatterpacleaanthony
authored
[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>
1 parent 9fe9c66 commit ca449a7

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

v3/UNRELEASED_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file
2323

2424
## Fixed
2525
<!-- Bug fixes -->
26+
- Fixed panic when closing or cancelling a `SaveFileDialog` on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284) by @hkhere
2627
- Fixed HTML level drag and drop on Windows by [@mbaklor](https://github.com/mbaklor) in [#4259](https://github.com/wailsapp/wails/pull/4259)
2728

2829
## Deprecated

v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ package cfd
44

55
import (
66
"fmt"
7-
"github.com/go-ole/go-ole"
87
"strings"
98
"syscall"
109
"unsafe"
10+
11+
"github.com/go-ole/go-ole"
1112
)
1213

1314
func hresultToError(hr uintptr) error {
@@ -168,7 +169,7 @@ func (vtbl *iFileDialogVtbl) getResultString(objPtr unsafe.Pointer) (string, err
168169
return "", err
169170
}
170171
if shellItem == nil {
171-
return "", fmt.Errorf("shellItem is nil")
172+
return "", ErrorCancelled
172173
}
173174
defer shellItem.vtbl.release(unsafe.Pointer(shellItem))
174175
return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem))

v3/pkg/application/dialogs_windows.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,16 @@ func (m *windowSaveFileDialog) show() (chan string, error) {
196196
func() (cfd.Dialog, error) {
197197
return cfd.NewSaveFileDialog(config)
198198
}, false)
199+
if err != nil {
200+
close(files)
201+
return files, err
202+
}
199203
go func() {
200204
defer handlePanic()
201-
files <- result.(string)
205+
f, ok := result.(string)
206+
if ok {
207+
files <- f
208+
}
202209
close(files)
203210
}()
204211
return files, err

0 commit comments

Comments
 (0)