mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 20:03:01 +08:00
add support for 'DomReady' callback on linux (#1249)
* add support for 'DomReady' callback on linux cosmetic: use bodyLen instead of len() in processRequest() * reformat webViewLoadChanged() for consistency Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
parent
daad8437c2
commit
d9e5cce2b2
@ -226,6 +226,13 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frontend) processMessage(message string) {
|
func (f *Frontend) processMessage(message string) {
|
||||||
|
if message == "DomReady" {
|
||||||
|
if f.frontendOptions.OnDomReady != nil {
|
||||||
|
f.frontendOptions.OnDomReady(f.ctx)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if message == "drag" {
|
if message == "drag" {
|
||||||
if !f.mainWindow.IsFullScreen() {
|
if !f.mainWindow.IsFullScreen() {
|
||||||
f.startDrag()
|
f.startDrag()
|
||||||
@ -313,7 +320,7 @@ func (f *Frontend) processRequest(request unsafe.Pointer) {
|
|||||||
cContent = C.malloc(C.ulong(bodyLen))
|
cContent = C.malloc(C.ulong(bodyLen))
|
||||||
if cContent != nil {
|
if cContent != nil {
|
||||||
C.memcpy(cContent, unsafe.Pointer(&res.Body[0]), C.size_t(bodyLen))
|
C.memcpy(cContent, unsafe.Pointer(&res.Body[0]), C.size_t(bodyLen))
|
||||||
cLen = C.long(len(res.Body))
|
cLen = C.long(bodyLen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,13 @@ static void sendMessageToBackend(WebKitUserContentManager *contentManager,
|
|||||||
g_free(message);
|
g_free(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void webviewLoadChanged(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer data)
|
||||||
|
{
|
||||||
|
if (load_event == WEBKIT_LOAD_FINISHED) {
|
||||||
|
processMessage("DomReady");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ulong setupInvokeSignal(void* contentManager) {
|
ulong setupInvokeSignal(void* contentManager) {
|
||||||
return g_signal_connect((WebKitUserContentManager*)contentManager, "script-message-received::external", G_CALLBACK(sendMessageToBackend), NULL);
|
return g_signal_connect((WebKitUserContentManager*)contentManager, "script-message-received::external", G_CALLBACK(sendMessageToBackend), NULL);
|
||||||
}
|
}
|
||||||
@ -185,7 +192,7 @@ GtkWidget* setupWebview(void* contentManager, GtkWindow* window, int hideWindowO
|
|||||||
//gtk_container_add(GTK_CONTAINER(window), webview);
|
//gtk_container_add(GTK_CONTAINER(window), webview);
|
||||||
WebKitWebContext *context = webkit_web_context_get_default();
|
WebKitWebContext *context = webkit_web_context_get_default();
|
||||||
webkit_web_context_register_uri_scheme(context, "wails", (WebKitURISchemeRequestCallback)processURLRequest, NULL, NULL);
|
webkit_web_context_register_uri_scheme(context, "wails", (WebKitURISchemeRequestCallback)processURLRequest, NULL, NULL);
|
||||||
//g_signal_connect(G_OBJECT(webview), "load-changed", G_CALLBACK(webview_load_changed_cb), NULL);
|
g_signal_connect(G_OBJECT(webview), "load-changed", G_CALLBACK(webviewLoadChanged), NULL);
|
||||||
if (hideWindowOnClose) {
|
if (hideWindowOnClose) {
|
||||||
g_signal_connect(GTK_WIDGET(window), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
g_signal_connect(GTK_WIDGET(window), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
||||||
} else {
|
} else {
|
||||||
@ -536,6 +543,7 @@ gboolean UnFullscreen(gpointer data) {
|
|||||||
bool disableContextMenu(GtkWindow* window) {
|
bool disableContextMenu(GtkWindow* window) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisableContextMenu(void* webview) {
|
void DisableContextMenu(void* webview) {
|
||||||
contextMenuDisabled = TRUE;
|
contextMenuDisabled = TRUE;
|
||||||
g_signal_connect(WEBKIT_WEB_VIEW(webview), "context-menu", G_CALLBACK(disableContextMenu), NULL);
|
g_signal_connect(WEBKIT_WEB_VIEW(webview), "context-menu", G_CALLBACK(disableContextMenu), NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user