mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 19:50:15 +08:00
Tidy up and slight refactor
This commit is contained in:
parent
a2d447aecf
commit
6e30c6770b
@ -11,15 +11,8 @@ import "C"
|
||||
var openFileResults = make(chan string)
|
||||
|
||||
func (f *Frontend) OpenFileDialog(dialogOptions frontend.OpenDialogOptions) (result string, err error) {
|
||||
|
||||
f.dispatch(func() {
|
||||
println("Before OpenFileDialog")
|
||||
f.mainWindow.OpenFileDialog(dialogOptions)
|
||||
println("After OpenFileDialog")
|
||||
})
|
||||
println("Waiting for result")
|
||||
result = <-openFileResults
|
||||
println("Got result")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ static inline void processDispatchID(gpointer id) {
|
||||
}
|
||||
|
||||
static void gtkDispatch(int id) {
|
||||
gdk_threads_add_idle((GSourceFunc)processDispatchID, GINT_TO_POINTER(id));
|
||||
g_idle_add((GSourceFunc)processDispatchID, GINT_TO_POINTER(id));
|
||||
}
|
||||
|
||||
*/
|
||||
@ -63,7 +63,6 @@ type Frontend struct {
|
||||
|
||||
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
|
||||
|
||||
println("[NewFrontend] PID:", os.Getpid())
|
||||
// Set GDK_BACKEND=x11 to prevent warnings
|
||||
os.Setenv("GDK_BACKEND", "x11")
|
||||
|
||||
@ -303,7 +302,6 @@ var dispatchCallbackLock sync.Mutex
|
||||
|
||||
//export callDispatchedMethod
|
||||
func callDispatchedMethod(cid C.int) {
|
||||
println("[callDispatchedMethod] PID:", os.Getpid())
|
||||
id := int(cid)
|
||||
fn := dispatchCallbacks[id]
|
||||
if fn != nil {
|
||||
|
@ -196,15 +196,23 @@ int executeJS(gpointer data) {
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
void ExecuteOnMainThread(void* f, JSCallback* jscallback) {
|
||||
void ExecuteOnMainThread(void* f, gpointer jscallback) {
|
||||
g_idle_add((GSourceFunc)f, (gpointer)jscallback);
|
||||
}
|
||||
|
||||
void extern processOpenFileResult(char*);
|
||||
|
||||
|
||||
typedef struct OpenFileDialogOptions {
|
||||
void* webview;
|
||||
char* title;
|
||||
char** filters;
|
||||
} OpenFileDialogOptions;
|
||||
|
||||
|
||||
int opendialog(gpointer data) {
|
||||
struct JSCallback *js = data;
|
||||
GtkWidget *dlg = gtk_file_chooser_dialog_new(js->script, js->webview, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
struct OpenFileDialogOptions *options = data;
|
||||
GtkWidget *dlg = gtk_file_chooser_dialog_new(options->title, options->webview, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
"_Cancel", GTK_RESPONSE_CANCEL,
|
||||
"_Open", GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
@ -215,9 +223,11 @@ int opendialog(gpointer data) {
|
||||
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
|
||||
processOpenFileResult(filename);
|
||||
g_free(filename);
|
||||
} else {
|
||||
processOpenFileResult("");
|
||||
}
|
||||
gtk_widget_destroy(dlg);
|
||||
free(js->script);
|
||||
free(options->title);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
@ -439,7 +449,7 @@ func (w *Window) ExecJS(js string) {
|
||||
webview: w.webview,
|
||||
script: C.CString(js),
|
||||
}
|
||||
C.ExecuteOnMainThread(C.executeJS, &jscallback)
|
||||
C.ExecuteOnMainThread(C.executeJS, C.gpointer(&jscallback))
|
||||
}
|
||||
|
||||
func (w *Window) StartDrag() {
|
||||
@ -451,10 +461,10 @@ func (w *Window) Quit() {
|
||||
}
|
||||
|
||||
func (w *Window) OpenFileDialog(dialogOptions frontend.OpenDialogOptions) {
|
||||
data := C.JSCallback{
|
||||
data := C.OpenFileDialogOptions{
|
||||
webview: w.webview,
|
||||
script: C.CString(dialogOptions.Title),
|
||||
title: C.CString(dialogOptions.Title),
|
||||
}
|
||||
C.ExecuteOnMainThread(C.opendialog, &data)
|
||||
// TODO: Filter
|
||||
C.ExecuteOnMainThread(C.opendialog, C.gpointer(&data))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user