mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 18:10:48 +08:00
Fix invalid path for windows dialogs (#4019)
* Fix invalid path for windows dialogs * Update Go version in pipelines for v2
This commit is contained in:
parent
d824318a66
commit
4a1d101d04
2
.github/workflows/pr.yml
vendored
2
.github/workflows/pr.yml
vendored
@ -56,7 +56,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-22.04, windows-latest, macos-latest, ubuntu-24.04]
|
os: [ubuntu-22.04, windows-latest, macos-latest, ubuntu-24.04]
|
||||||
go-version: ['1.21']
|
go-version: ['1.23']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
@ -5,24 +5,24 @@ package cfd
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
var errUnsupported = fmt.Errorf("common file dialogs are only available on windows")
|
var unsupportedError = fmt.Errorf("common file dialogs are only available on windows")
|
||||||
|
|
||||||
// TODO doc
|
// TODO doc
|
||||||
func NewOpenFileDialog(config DialogConfig) (OpenFileDialog, error) {
|
func NewOpenFileDialog(config DialogConfig) (OpenFileDialog, error) {
|
||||||
return nil, errUnsupported
|
return nil, unsupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO doc
|
// TODO doc
|
||||||
func NewOpenMultipleFilesDialog(config DialogConfig) (OpenMultipleFilesDialog, error) {
|
func NewOpenMultipleFilesDialog(config DialogConfig) (OpenMultipleFilesDialog, error) {
|
||||||
return nil, errUnsupported
|
return nil, unsupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO doc
|
// TODO doc
|
||||||
func NewSelectFolderDialog(config DialogConfig) (SelectFolderDialog, error) {
|
func NewSelectFolderDialog(config DialogConfig) (SelectFolderDialog, error) {
|
||||||
return nil, errUnsupported
|
return nil, unsupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO doc
|
// TODO doc
|
||||||
func NewSaveFileDialog(config DialogConfig) (SaveFileDialog, error) {
|
func NewSaveFileDialog(config DialogConfig) (SaveFileDialog, error) {
|
||||||
return nil, errUnsupported
|
return nil, unsupportedError
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
package cfd
|
package cfd
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
type FileFilter struct {
|
type FileFilter struct {
|
||||||
// The display name of the filter (That is shown to the user)
|
// The display name of the filter (That is shown to the user)
|
||||||
@ -11,6 +15,9 @@ type FileFilter struct {
|
|||||||
Pattern string
|
Pattern string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Never obfuscate the FileFilter type.
|
||||||
|
var _ = reflect.TypeOf(FileFilter{})
|
||||||
|
|
||||||
type DialogConfig struct {
|
type DialogConfig struct {
|
||||||
// The title of the dialog
|
// The title of the dialog
|
||||||
Title string
|
Title string
|
||||||
@ -69,6 +76,10 @@ func (config *DialogConfig) apply(dialog Dialog) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Folder != "" {
|
if config.Folder != "" {
|
||||||
|
_, err = os.Stat(config.Folder)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = dialog.SetFolder(config.Folder)
|
err = dialog.SetFolder(config.Folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -76,6 +87,10 @@ func (config *DialogConfig) apply(dialog Dialog) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.DefaultFolder != "" {
|
if config.DefaultFolder != "" {
|
||||||
|
_, err = os.Stat(config.DefaultFolder)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = dialog.SetDefaultFolder(config.DefaultFolder)
|
err = dialog.SetDefaultFolder(config.DefaultFolder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -2,4 +2,6 @@ package cfd
|
|||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
var ErrCancelled = errors.New("cancelled by user")
|
var (
|
||||||
|
ErrorCancelled = errors.New("cancelled by user")
|
||||||
|
)
|
||||||
|
@ -5,7 +5,7 @@ package cfd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-ole/go-ole"
|
"github.com/go-ole/go-ole"
|
||||||
"github.com/wailsapp/wails/v2/internal/go-common-file-dialog/util"
|
"github.com/google/uuid"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@ -106,7 +106,7 @@ func (fileOpenDialog *iFileOpenDialog) SetFileFilters(filter []FileFilter) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fileOpenDialog *iFileOpenDialog) SetRole(role string) error {
|
func (fileOpenDialog *iFileOpenDialog) SetRole(role string) error {
|
||||||
return fileOpenDialog.vtbl.setClientGuid(unsafe.Pointer(fileOpenDialog), util.StringToUUID(role))
|
return fileOpenDialog.vtbl.setClientGuid(unsafe.Pointer(fileOpenDialog), StringToUUID(role))
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should only be callable when the user asks for a multi select because
|
// This should only be callable when the user asks for a multi select because
|
||||||
@ -177,7 +177,7 @@ func (vtbl *iFileOpenDialogVtbl) getResultsStrings(objPtr unsafe.Pointer) ([]str
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if shellItemArray == nil {
|
if shellItemArray == nil {
|
||||||
return nil, ErrCancelled
|
return nil, ErrorCancelled
|
||||||
}
|
}
|
||||||
defer shellItemArray.vtbl.release(unsafe.Pointer(shellItemArray))
|
defer shellItemArray.vtbl.release(unsafe.Pointer(shellItemArray))
|
||||||
count, err := shellItemArray.vtbl.getCount(unsafe.Pointer(shellItemArray))
|
count, err := shellItemArray.vtbl.getCount(unsafe.Pointer(shellItemArray))
|
||||||
@ -194,3 +194,7 @@ func (vtbl *iFileOpenDialogVtbl) getResultsStrings(objPtr unsafe.Pointer) ([]str
|
|||||||
}
|
}
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StringToUUID(str string) *ole.GUID {
|
||||||
|
return ole.NewGUID(uuid.NewSHA1(uuid.Nil, []byte(str)).String())
|
||||||
|
}
|
||||||
|
@ -5,7 +5,6 @@ package cfd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-ole/go-ole"
|
"github.com/go-ole/go-ole"
|
||||||
"github.com/wailsapp/wails/v2/internal/go-common-file-dialog/util"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -77,7 +76,7 @@ func (fileSaveDialog *iFileSaveDialog) SetFileFilters(filter []FileFilter) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fileSaveDialog *iFileSaveDialog) SetRole(role string) error {
|
func (fileSaveDialog *iFileSaveDialog) SetRole(role string) error {
|
||||||
return fileSaveDialog.vtbl.setClientGuid(unsafe.Pointer(fileSaveDialog), util.StringToUUID(role))
|
return fileSaveDialog.vtbl.setClientGuid(unsafe.Pointer(fileSaveDialog), StringToUUID(role))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fileSaveDialog *iFileSaveDialog) SetDefaultExtension(defaultExtension string) error {
|
func (fileSaveDialog *iFileSaveDialog) SetDefaultExtension(defaultExtension string) error {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package cfd
|
package cfd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/go-ole/go-ole"
|
"github.com/go-ole/go-ole"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -57,7 +58,7 @@ func (vtbl *iShellItemArrayVtbl) getItemAt(objPtr unsafe.Pointer, index uintptr)
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if shellItem == nil {
|
if shellItem == nil {
|
||||||
return "", ErrCancelled
|
return "", fmt.Errorf("shellItem is nil")
|
||||||
}
|
}
|
||||||
defer shellItem.vtbl.release(unsafe.Pointer(shellItem))
|
defer shellItem.vtbl.release(unsafe.Pointer(shellItem))
|
||||||
return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem))
|
return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem))
|
||||||
|
@ -168,7 +168,7 @@ func (vtbl *iFileDialogVtbl) getResultString(objPtr unsafe.Pointer) (string, err
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if shellItem == nil {
|
if shellItem == nil {
|
||||||
return "", ErrCancelled
|
return "", fmt.Errorf("shellItem is nil")
|
||||||
}
|
}
|
||||||
defer shellItem.vtbl.release(unsafe.Pointer(shellItem))
|
defer shellItem.vtbl.release(unsafe.Pointer(shellItem))
|
||||||
return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem))
|
return shellItem.vtbl.getDisplayName(unsafe.Pointer(shellItem))
|
||||||
|
@ -10,9 +10,7 @@ func ShowOpenFileDialog(config cfd.DialogConfig) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer dialog.Release()
|
||||||
_ = dialog.Release()
|
|
||||||
}()
|
|
||||||
return dialog.ShowAndGetResult()
|
return dialog.ShowAndGetResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,9 +20,7 @@ func ShowOpenMultipleFilesDialog(config cfd.DialogConfig) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer dialog.Release()
|
||||||
_ = dialog.Release()
|
|
||||||
}()
|
|
||||||
return dialog.ShowAndGetResults()
|
return dialog.ShowAndGetResults()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +30,7 @@ func ShowPickFolderDialog(config cfd.DialogConfig) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer dialog.Release()
|
||||||
_ = dialog.Release()
|
|
||||||
}()
|
|
||||||
return dialog.ShowAndGetResult()
|
return dialog.ShowAndGetResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,8 +40,6 @@ func ShowSaveFileDialog(config cfd.DialogConfig) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer dialog.Release()
|
||||||
_ = dialog.Release()
|
|
||||||
}()
|
|
||||||
return dialog.ShowAndGetResult()
|
return dialog.ShowAndGetResult()
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fixed failed models.ts build due to non-json-encodable Go types [PR](https://github.com/wailsapp/wails/pull/3975) by [@pbnjay](https://github.com/pbnjay)
|
- Fixed failed models.ts build due to non-json-encodable Go types [PR](https://github.com/wailsapp/wails/pull/3975) by [@pbnjay](https://github.com/pbnjay)
|
||||||
- Fixed more binding and typescript export bugs [PR](https://github.com/wailsapp/wails/pull/3978) by [@pbnjay](https://github.com/pbnjay)
|
- Fixed more binding and typescript export bugs [PR](https://github.com/wailsapp/wails/pull/3978) by [@pbnjay](https://github.com/pbnjay)
|
||||||
- Fixed Dispatcher.ProcessMessage crash process instead of return error [PR](https://github.com/wailsapp/wails/pull/4016) [#4015](https://github.com/wailsapp/wails/issues/4015) by [@ronaldinho_x86](https://github.com/RonaldinhoL)
|
- Fixed Dispatcher.ProcessMessage crash process instead of return error [PR](https://github.com/wailsapp/wails/pull/4016) [#4015](https://github.com/wailsapp/wails/issues/4015) by [@ronaldinho_x86](https://github.com/RonaldinhoL)
|
||||||
|
- Fixed Windows SaveDialog crash by [@leaanthony](https://github.com/leaanthony)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Allow to specify macos-min-version externally. Implemented by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3756)
|
- Allow to specify macos-min-version externally. Implemented by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3756)
|
||||||
|
Loading…
Reference in New Issue
Block a user