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)
|
var openFileResults = make(chan string)
|
||||||
|
|
||||||
func (f *Frontend) OpenFileDialog(dialogOptions frontend.OpenDialogOptions) (result string, err error) {
|
func (f *Frontend) OpenFileDialog(dialogOptions frontend.OpenDialogOptions) (result string, err error) {
|
||||||
|
f.mainWindow.OpenFileDialog(dialogOptions)
|
||||||
f.dispatch(func() {
|
|
||||||
println("Before OpenFileDialog")
|
|
||||||
f.mainWindow.OpenFileDialog(dialogOptions)
|
|
||||||
println("After OpenFileDialog")
|
|
||||||
})
|
|
||||||
println("Waiting for result")
|
|
||||||
result = <-openFileResults
|
result = <-openFileResults
|
||||||
println("Got result")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ static inline void processDispatchID(gpointer id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void gtkDispatch(int 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 {
|
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
|
// Set GDK_BACKEND=x11 to prevent warnings
|
||||||
os.Setenv("GDK_BACKEND", "x11")
|
os.Setenv("GDK_BACKEND", "x11")
|
||||||
|
|
||||||
@ -303,7 +302,6 @@ var dispatchCallbackLock sync.Mutex
|
|||||||
|
|
||||||
//export callDispatchedMethod
|
//export callDispatchedMethod
|
||||||
func callDispatchedMethod(cid C.int) {
|
func callDispatchedMethod(cid C.int) {
|
||||||
println("[callDispatchedMethod] PID:", os.Getpid())
|
|
||||||
id := int(cid)
|
id := int(cid)
|
||||||
fn := dispatchCallbacks[id]
|
fn := dispatchCallbacks[id]
|
||||||
if fn != nil {
|
if fn != nil {
|
||||||
|
@ -196,15 +196,23 @@ int executeJS(gpointer data) {
|
|||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteOnMainThread(void* f, JSCallback* jscallback) {
|
void ExecuteOnMainThread(void* f, gpointer jscallback) {
|
||||||
g_idle_add((GSourceFunc)f, (gpointer)jscallback);
|
g_idle_add((GSourceFunc)f, (gpointer)jscallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extern processOpenFileResult(char*);
|
void extern processOpenFileResult(char*);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct OpenFileDialogOptions {
|
||||||
|
void* webview;
|
||||||
|
char* title;
|
||||||
|
char** filters;
|
||||||
|
} OpenFileDialogOptions;
|
||||||
|
|
||||||
|
|
||||||
int opendialog(gpointer data) {
|
int opendialog(gpointer data) {
|
||||||
struct JSCallback *js = data;
|
struct OpenFileDialogOptions *options = data;
|
||||||
GtkWidget *dlg = gtk_file_chooser_dialog_new(js->script, js->webview, GTK_FILE_CHOOSER_ACTION_OPEN,
|
GtkWidget *dlg = gtk_file_chooser_dialog_new(options->title, options->webview, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
"_Cancel", GTK_RESPONSE_CANCEL,
|
"_Cancel", GTK_RESPONSE_CANCEL,
|
||||||
"_Open", GTK_RESPONSE_ACCEPT,
|
"_Open", GTK_RESPONSE_ACCEPT,
|
||||||
NULL);
|
NULL);
|
||||||
@ -215,9 +223,11 @@ int opendialog(gpointer data) {
|
|||||||
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
|
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
|
||||||
processOpenFileResult(filename);
|
processOpenFileResult(filename);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
}
|
} else {
|
||||||
|
processOpenFileResult("");
|
||||||
|
}
|
||||||
gtk_widget_destroy(dlg);
|
gtk_widget_destroy(dlg);
|
||||||
free(js->script);
|
free(options->title);
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,9 +447,9 @@ func (w *Window) SetTitle(title string) {
|
|||||||
func (w *Window) ExecJS(js string) {
|
func (w *Window) ExecJS(js string) {
|
||||||
jscallback := C.JSCallback{
|
jscallback := C.JSCallback{
|
||||||
webview: w.webview,
|
webview: w.webview,
|
||||||
script: C.CString(js),
|
script: C.CString(js),
|
||||||
}
|
}
|
||||||
C.ExecuteOnMainThread(C.executeJS, &jscallback)
|
C.ExecuteOnMainThread(C.executeJS, C.gpointer(&jscallback))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) StartDrag() {
|
func (w *Window) StartDrag() {
|
||||||
@ -451,10 +461,10 @@ func (w *Window) Quit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) OpenFileDialog(dialogOptions frontend.OpenDialogOptions) {
|
func (w *Window) OpenFileDialog(dialogOptions frontend.OpenDialogOptions) {
|
||||||
data := C.JSCallback{
|
data := C.OpenFileDialogOptions{
|
||||||
webview: w.webview,
|
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