5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 02:01:01 +08:00

[linux] Remove Go based dispatcher

This commit is contained in:
Lea Anthony 2022-01-31 21:22:17 +11:00
parent 6a10bf4d98
commit db9e0fd0d3
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405

View File

@ -9,15 +9,6 @@ package linux
#include "gtk/gtk.h"
#include "webkit2/webkit2.h"
extern void callDispatchedMethod(int id);
static inline void processDispatchID(gpointer id) {
callDispatchedMethod(GPOINTER_TO_INT(id));
}
static void gtkDispatch(int id) {
g_idle_add((GSourceFunc)processDispatchID, GINT_TO_POINTER(id));
}
*/
import "C"
import (
@ -27,7 +18,6 @@ import (
"log"
"os"
"strconv"
"sync"
"text/template"
"unsafe"
@ -230,7 +220,7 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
f.logger.Error(err.Error())
return
}
f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
f.mainWindow.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
}
func (f *Frontend) processMessage(message string) {
@ -267,25 +257,11 @@ func (f *Frontend) Callback(message string) {
}
func (f *Frontend) startDrag() {
f.dispatch(func() {
f.mainWindow.StartDrag()
})
}
func (f *Frontend) ExecJS(js string) {
f.dispatch(func() {
f.mainWindow.ExecJS(js)
})
}
func (f *Frontend) dispatch(fn func()) {
dispatchCallbackLock.Lock()
id := 0
for fn := dispatchCallbacks[id]; fn != nil; id++ {
}
dispatchCallbacks[id] = fn
dispatchCallbackLock.Unlock()
C.gtkDispatch(C.int(id))
}
var messageBuffer = make(chan string, 100)
@ -296,24 +272,6 @@ func processMessage(message *C.char) {
messageBuffer <- goMessage
}
// Map of functions passed to dispatch()
var dispatchCallbacks = make(map[int]func())
var dispatchCallbackLock sync.Mutex
//export callDispatchedMethod
func callDispatchedMethod(cid C.int) {
id := int(cid)
fn := dispatchCallbacks[id]
if fn != nil {
fn()
dispatchCallbackLock.Lock()
delete(dispatchCallbacks, id)
dispatchCallbackLock.Unlock()
} else {
println("Error: No dispatch method with id", id, cid)
}
}
var requestBuffer = make(chan unsafe.Pointer, 100)
func (f *Frontend) startRequestProcessor() {
@ -333,6 +291,11 @@ func (f *Frontend) processRequest(request unsafe.Pointer) {
goURI := C.GoString(uri)
file, match, err := common.TranslateUriToFile(goURI, "wails", "")
if err != nil {
// TODO Handle errors
return
} else if !match {
file, match, err = common.TranslateUriToFile(goURI, "wails", "null")
if err != nil {
// TODO Handle errors
return
@ -340,6 +303,7 @@ func (f *Frontend) processRequest(request unsafe.Pointer) {
// This should never happen on linux, because we get only called for wails://
panic("Unexpected host for request on wails:// scheme")
}
}
// Load file from asset store
content, mimeType, err := f.assets.Load(file)