diff --git a/v2/internal/ffenestri/ffenestri.go b/v2/internal/ffenestri/ffenestri.go index 66900445..2401d8ce 100644 --- a/v2/internal/ffenestri/ffenestri.go +++ b/v2/internal/ffenestri/ffenestri.go @@ -29,33 +29,6 @@ import "C" // TODO: move to compile time. var DEBUG bool = true -// // Config defines how our application should be configured -// type Config struct { -// Title string -// Width int -// Height int -// MinWidth int -// MinHeight int -// MaxWidth int -// MaxHeight int -// DevTools bool -// Resizable bool -// Fullscreen bool -// Frameless bool -// StartHidden bool -// } - -// var defaultConfig = &Config{ -// Title: "My Wails App", -// Width: 800, -// Height: 600, -// DevTools: true, -// Resizable: true, -// Fullscreen: false, -// Frameless: false, -// StartHidden: false, -// } - // Application is our main application object type Application struct { config *options.App diff --git a/v2/internal/ffenestri/ffenestri_client.go b/v2/internal/ffenestri/ffenestri_client.go index 98a3ea23..5c4de82c 100644 --- a/v2/internal/ffenestri/ffenestri_client.go +++ b/v2/internal/ffenestri/ffenestri_client.go @@ -19,6 +19,7 @@ import ( "unsafe" "github.com/wailsapp/wails/v2/internal/logger" + "github.com/wailsapp/wails/v2/pkg/options" ) // Client is our implentation of messageDispatcher.Client @@ -123,11 +124,11 @@ func (c *Client) WindowSetColour(colour int) { } // OpenDialog will open a dialog with the given title and filter -func (c *Client) OpenDialog(title string, filter string) []string { +func (c *Client) OpenDialog(dialogOptions *options.OpenDialog) []string { var result []string - cstring := C.OpenDialog(c.app.app, c.app.string2CString(title), c.app.string2CString(filter)) + cstring := C.OpenDialog(c.app.app, c.app.string2CString(dialogOptions.Title), c.app.string2CString(dialogOptions.Filter)) if cstring == nil { return result } diff --git a/v2/internal/messagedispatcher/dispatchclient.go b/v2/internal/messagedispatcher/dispatchclient.go index 4f6ae886..8dcbf692 100644 --- a/v2/internal/messagedispatcher/dispatchclient.go +++ b/v2/internal/messagedispatcher/dispatchclient.go @@ -6,6 +6,7 @@ import ( "github.com/wailsapp/wails/v2/internal/logger" "github.com/wailsapp/wails/v2/internal/messagedispatcher/message" "github.com/wailsapp/wails/v2/internal/servicebus" + "github.com/wailsapp/wails/v2/pkg/options" ) // Client defines what a frontend client can do @@ -13,7 +14,7 @@ type Client interface { Quit() NotifyEvent(message string) CallResult(message string) - OpenDialog(title string, filter string) []string + OpenDialog(*options.OpenDialog) []string WindowSetTitle(title string) WindowShow() WindowHide() diff --git a/v2/internal/messagedispatcher/messagedispatcher.go b/v2/internal/messagedispatcher/messagedispatcher.go index 54d2e24d..0c034be6 100644 --- a/v2/internal/messagedispatcher/messagedispatcher.go +++ b/v2/internal/messagedispatcher/messagedispatcher.go @@ -10,6 +10,7 @@ import ( "github.com/wailsapp/wails/v2/internal/logger" "github.com/wailsapp/wails/v2/internal/messagedispatcher/message" "github.com/wailsapp/wails/v2/internal/servicebus" + "github.com/wailsapp/wails/v2/pkg/options" ) // Dispatcher translates messages received from the frontend @@ -317,7 +318,6 @@ func (d *Dispatcher) processWindowMessage(result *servicebus.Message) { // processDialogMessage processes dialog messages func (d *Dispatcher) processDialogMessage(result *servicebus.Message) { splitTopic := strings.Split(result.Topic(), ":") - if len(splitTopic) < 4 { d.logger.Error("Invalid dialog message : %#v", result.Data()) return @@ -327,25 +327,23 @@ func (d *Dispatcher) processDialogMessage(result *servicebus.Message) { switch command { case "select": dialogType := splitTopic[2] - title := splitTopic[3] - filter := "" - if len(splitTopic) > 4 { - filter = splitTopic[4] - } switch dialogType { case "open": - responseTopic, ok := result.Data().(string) + dialogOptions, ok := result.Data().(*options.OpenDialog) if !ok { - d.logger.Error("Invalid responseTopic for 'dialog:select:open' : %#v", result.Data()) + d.logger.Error("Invalid data for 'dialog:select:open' : %#v", result.Data()) return } + // This is hardcoded in the sender too + responseTopic := "dialog:openselected:" + splitTopic[3] + d.logger.Info("Opening File dialog! responseTopic = %s", responseTopic) // TODO: Work out what we mean in a multi window environment... // For now we will just pick the first one var result []string for _, client := range d.clients { - result = client.frontend.OpenDialog(title, filter) + result = client.frontend.OpenDialog(dialogOptions) } // Send dummy response diff --git a/v2/internal/runtime/goruntime/dialog.go b/v2/internal/runtime/goruntime/dialog.go index 2d46b41b..1e7a74a6 100644 --- a/v2/internal/runtime/goruntime/dialog.go +++ b/v2/internal/runtime/goruntime/dialog.go @@ -1,15 +1,18 @@ package goruntime import ( + b64 "encoding/base64" + "encoding/json" "fmt" "github.com/wailsapp/wails/v2/internal/crypto" "github.com/wailsapp/wails/v2/internal/servicebus" + "github.com/wailsapp/wails/v2/pkg/options" ) // Dialog defines all Dialog related operations type Dialog interface { - OpenDialog(params ...string) []string + Open(dialogOptions *options.OpenDialog) []string } // dialog exposes the Dialog interface @@ -41,11 +44,8 @@ func (r *dialog) processTitleAndFilter(params ...string) (string, string) { return title, filter } -// OpenDialog prompts the user to select a file -func (r *dialog) OpenDialog(params ...string) []string { - - // Extract title + filter - title, filter := r.processTitleAndFilter(params...) +// Open prompts the user to select a file +func (r *dialog) Open(dialogOptions *options.OpenDialog) []string { // Create unique dialog callback uniqueCallback := crypto.RandomID() @@ -57,12 +57,8 @@ func (r *dialog) OpenDialog(params ...string) []string { fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error()) } - // Publish dialog request - message := "dialog:select:open:" + title - if filter != "" { - message += ":" + filter - } - r.bus.Publish(message, responseTopic) + message := "dialog:select:open:" + uniqueCallback + r.bus.Publish(message, dialogOptions) // Wait for result var result *servicebus.Message = <-dialogResponseChannel @@ -72,3 +68,13 @@ func (r *dialog) OpenDialog(params ...string) []string { return result.Data().([]string) } + +func optionsToBase64(dialogOptions *options.OpenDialog) (string, error) { + + encoded, err := json.Marshal(dialogOptions) + if err != nil { + return "", err + } + + return b64.StdEncoding.EncodeToString(encoded), nil +} diff --git a/v2/pkg/options/dialog.go b/v2/pkg/options/dialog.go new file mode 100644 index 00000000..609f67e5 --- /dev/null +++ b/v2/pkg/options/dialog.go @@ -0,0 +1,9 @@ +package options + +// OpenDialog contains the options for the OpenDialog runtime method +type OpenDialog struct { + Title string + Filter string + AllowFiles bool + AllowDirectories bool +} diff --git a/v2/test/runtime/runtime.go b/v2/test/runtime/runtime.go index 9062e41a..ed4d972e 100644 --- a/v2/test/runtime/runtime.go +++ b/v2/test/runtime/runtime.go @@ -4,6 +4,7 @@ import ( "time" wails "github.com/wailsapp/wails/v2" + "github.com/wailsapp/wails/v2/pkg/options" ) // RuntimeTest to test the runtimes @@ -68,7 +69,11 @@ func (r *RuntimeTest) SetColour(colour int) { // OpenDialog will call the Runtime.Dialog.OpenDirectory method func (r *RuntimeTest) OpenDialog(title string, filter string) []string { - return r.runtime.Dialog.OpenDialog(title, filter) + dialogOptions := &options.OpenDialog{ + Title: title, + Filter: filter, + } + return r.runtime.Dialog.Open(dialogOptions) } // HideWindow will call the Runtime.Window.Hide method and then call