mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 04:42:00 +08:00
[linux] Remove Go based dispatcher
This commit is contained in:
parent
6a10bf4d98
commit
db9e0fd0d3
@ -9,15 +9,6 @@ package linux
|
|||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
#include "webkit2/webkit2.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 "C"
|
||||||
import (
|
import (
|
||||||
@ -27,7 +18,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -230,7 +220,7 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
|
|||||||
f.logger.Error(err.Error())
|
f.logger.Error(err.Error())
|
||||||
return
|
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) {
|
func (f *Frontend) processMessage(message string) {
|
||||||
@ -267,25 +257,11 @@ func (f *Frontend) Callback(message string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) startDrag() {
|
func (f *Frontend) startDrag() {
|
||||||
f.dispatch(func() {
|
f.mainWindow.StartDrag()
|
||||||
f.mainWindow.StartDrag()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) ExecJS(js string) {
|
func (f *Frontend) ExecJS(js string) {
|
||||||
f.dispatch(func() {
|
f.mainWindow.ExecJS(js)
|
||||||
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)
|
var messageBuffer = make(chan string, 100)
|
||||||
@ -296,24 +272,6 @@ func processMessage(message *C.char) {
|
|||||||
messageBuffer <- goMessage
|
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)
|
var requestBuffer = make(chan unsafe.Pointer, 100)
|
||||||
|
|
||||||
func (f *Frontend) startRequestProcessor() {
|
func (f *Frontend) startRequestProcessor() {
|
||||||
@ -337,8 +295,14 @@ func (f *Frontend) processRequest(request unsafe.Pointer) {
|
|||||||
// TODO Handle errors
|
// TODO Handle errors
|
||||||
return
|
return
|
||||||
} else if !match {
|
} else if !match {
|
||||||
// This should never happen on linux, because we get only called for wails://
|
file, match, err = common.TranslateUriToFile(goURI, "wails", "null")
|
||||||
panic("Unexpected host for request on wails:// scheme")
|
if err != nil {
|
||||||
|
// TODO Handle errors
|
||||||
|
return
|
||||||
|
} else if !match {
|
||||||
|
// 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
|
// Load file from asset store
|
||||||
|
Loading…
Reference in New Issue
Block a user