diff --git a/CHANGELOG.md b/CHANGELOG.md
index 921be8b..31db333 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [0.6.0] - 2020-05-17
+### Add
+- Add binding for webview_dispatch
+- New webview version
+
## [0.5.5] - 2020-05-05
### Add
- Link interception for image links
diff --git a/examples/Minimal/Minimal.csproj b/examples/Minimal/Minimal.csproj
index be81cf0..f2d2beb 100644
--- a/examples/Minimal/Minimal.csproj
+++ b/examples/Minimal/Minimal.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/libs/webview.dll b/libs/webview.dll
index 9e7e0de..6408593 100644
Binary files a/libs/webview.dll and b/libs/webview.dll differ
diff --git a/src/SharpWebview/Bindings.cs b/src/SharpWebview/Bindings.cs
index 639e241..db38db5 100644
--- a/src/SharpWebview/Bindings.cs
+++ b/src/SharpWebview/Bindings.cs
@@ -29,6 +29,11 @@ public enum RPCResult
Error = 1,
}
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DispatchFunction(
+ IntPtr webview,
+ IntPtr args);
+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void CallBackFunction(
[MarshalAs(UnmanagedType.LPStr)] string id,
@@ -155,6 +160,19 @@ internal static class Bindings
[DllImport(DllFile, CallingConvention = CallingConvention.Cdecl)]
internal extern static void webview_eval(IntPtr webview, [MarshalAs(UnmanagedType.LPStr)] string js);
+ ///
+ /// Posts a function to be executed on the main thread. You normally do not need
+ /// to call this function, unless you want to tweak the native window.
+ ///
+ /// Binding for:
+ /// WEBVIEW_API void webview_dispatch(webview_t w, void (*fn)(webview_t w, void *arg), void *arg);
+ ///
+ /// The webview to dispatch the function to
+ /// The function to execute on the webview thread
+ /// Paramters to pass to the dispatched function
+ [DllImport(DllFile, CallingConvention = CallingConvention.Cdecl)]
+ internal extern static void webview_dispatch(IntPtr webview, DispatchFunction dispatchFunction, IntPtr args);
+
///
/// Binds a native C callback so that it will appear under the given name as a
/// global JavaScript function. Internally it uses webview_init(). Callback
@@ -196,10 +214,6 @@ internal extern static void webview_return(IntPtr webview,
/*
Not mapped:
- // Posts a function to be executed on the main thread. You normally do not need
- // to call this function, unless you want to tweak the native window.
- WEBVIEW_API void
- webview_dispatch(webview_t w, void (*fn)(webview_t w, void *arg), void *arg);
// Returns a native window handle pointer. When using GTK backend the pointer
// is GtkWindow pointer, when using Cocoa backend the pointer is NSWindow
diff --git a/src/SharpWebview/SharpWebview.csproj b/src/SharpWebview/SharpWebview.csproj
index a852caf..9b49400 100644
--- a/src/SharpWebview/SharpWebview.csproj
+++ b/src/SharpWebview/SharpWebview.csproj
@@ -7,7 +7,7 @@
Gerrit 'Geaz' Gazic
C# bindings for zserge/webview - Batteries included
SharpWebview
- 0.5.5
+ 0.6.0
MIT
https://github.com/geaz/sharpWebview
diff --git a/src/SharpWebview/Webview.cs b/src/SharpWebview/Webview.cs
index bdfac40..11afffa 100644
--- a/src/SharpWebview/Webview.cs
+++ b/src/SharpWebview/Webview.cs
@@ -3,6 +3,7 @@
using SharpWebview.Content;
using System.Diagnostics;
using System.Collections.Generic;
+using System.Runtime.InteropServices;
namespace SharpWebview
{
@@ -96,7 +97,7 @@ public Webview Navigate(IWebviewContent webviewContent)
/// The webview object for a fluent api.
public Webview Bind(string name, Action callback)
{
- var callbackInstance = new CallBackFunction((id, req, arg) => { callback(id, req); });
+ var callbackInstance = new CallBackFunction((id, req, _) => callback(id, req));
callbacks.Add(callbackInstance); // Pin the callback for the GC
Bindings.webview_bind(_nativeWebview, name, callbackInstance, IntPtr.Zero);
@@ -135,6 +136,16 @@ public void Evaluate(string javascript)
Bindings.webview_eval(_nativeWebview, javascript);
}
+ ///
+ /// Posts a function to be executed on the main thread of the webview.
+ ///
+ /// The function to call on the main thread
+ public void Dispatch(Action dispatchFunc)
+ {
+ var dispatchFuncInstance = new DispatchFunction((_, __) => dispatchFunc());
+ Bindings.webview_dispatch(_nativeWebview, dispatchFuncInstance, IntPtr.Zero);
+ }
+
///
/// Disposes the current webview.
///
@@ -148,6 +159,7 @@ protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
+ Bindings.webview_terminate(_nativeWebview);
Bindings.webview_destroy(_nativeWebview);
_disposed = true;
}