mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 01:19:29 +08:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
//go:build linux
|
|
|
|
package application
|
|
|
|
/*
|
|
#cgo linux pkg-config: gtk+-3.0
|
|
|
|
#include <stdio.h>
|
|
#include "gtk/gtk.h"
|
|
|
|
typedef struct CallbackID
|
|
{
|
|
unsigned int value;
|
|
} CallbackID;
|
|
|
|
extern void dispatchOnMainThreadCallback(unsigned int);
|
|
|
|
static gboolean dispatchCallback(gpointer data) {
|
|
struct CallbackID *args = data;
|
|
unsigned int cid = args->value;
|
|
dispatchOnMainThreadCallback(cid);
|
|
free(args);
|
|
|
|
return G_SOURCE_REMOVE;
|
|
};
|
|
|
|
static void dispatchOnMainThread(unsigned int id) {
|
|
CallbackID *args = malloc(sizeof(CallbackID));
|
|
args->value = id;
|
|
g_idle_add((GSourceFunc)dispatchCallback, (gpointer)args);
|
|
}
|
|
|
|
*/
|
|
import "C"
|
|
|
|
func (m *linuxApp) dispatchOnMainThread(id uint) {
|
|
C.dispatchOnMainThread(C.uint(id))
|
|
}
|
|
|
|
//export dispatchOnMainThreadCallback
|
|
func dispatchOnMainThreadCallback(callbackID C.uint) {
|
|
mainThreadFunctionStoreLock.RLock()
|
|
id := uint(callbackID)
|
|
fn := mainThreadFunctionStore[id]
|
|
if fn == nil {
|
|
Fatal("dispatchCallback called with invalid id: %v", id)
|
|
}
|
|
delete(mainThreadFunctionStore, id)
|
|
mainThreadFunctionStoreLock.RUnlock()
|
|
fn()
|
|
}
|