Skip to content

Commit

Permalink
Update to WebUI 2.5.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadordf committed Jun 24, 2024
1 parent 03e162e commit d237c90
Show file tree
Hide file tree
Showing 57 changed files with 1,535 additions and 525 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ You can also support this project with Liberapay.
* [WebView4Delphi](https://github.com/salvadordf/WebView4Delphi)
* [WebUI4Delphi](https://github.com/salvadordf/WebUI4Delphi)
* [Doxygen](https://github.com/doxygen/doxygen)
* [WebUI.NET](https://github.com/Juff-Ma/WebUI.NET)
14 changes: 12 additions & 2 deletions WebUI4CSharp/WebUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class WebUI
/// <summary>
/// WebUI library version.
/// </summary>
public const string WEBUI_VERSION = "2.4.2";
public const string WEBUI_VERSION = "2.5.0-beta.1";

/// <summary>
/// Max windows, servers and threads
Expand Down Expand Up @@ -54,7 +54,7 @@ public static bool SetDefaultRootFolder(string path)
}

/// <summary>
/// Timeout in seconds before the browser starts. 0 means wait forever.
/// Set the maximum time in seconds to wait for the window to connect. This affects `show()` and `wait()`.
/// </summary>
public static void SetTimeout(UIntPtr second)
{
Expand Down Expand Up @@ -211,5 +211,15 @@ public static void CommonBindCallback(ref webui_event_t e)
lWindow.DoBindEvent(ref e);
}
}

/// <summary>
/// Control the WebUI behaviour. It's better to call at the beginning.
/// </summary>
/// <param name="option">The desired option from `webui_config` enum.</param>
/// <param name="status">The status of the option, `true` or `false`.</param>
public static void SetConfig(webui_config option, bool status)
{
WebUILibFunctions.webui_set_config((UIntPtr) option, status);
}
}
}
8 changes: 4 additions & 4 deletions WebUI4CSharp/WebUIBase64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
public static class WebUIBase64
{
/// <summary>
/// Base64 encoding. Use this to safely send text based data to the UI. If it fails it will return an empty string.
/// Encode text to Base64.
/// </summary>
/// <param name="str">The string to encode.</param>
/// <returns>Returns a encoded string.</returns>
/// <returns>Returns the base64 encoded string.</returns>
public static string Encode(string str) { return WebUILibFunctions.webui_encode(str); }

/// <summary>
/// Base64 decoding. Use this to safely decode received Base64 text from the UI. If it fails it will return an empty string.
/// Decode a Base64 encoded text.
/// </summary>
/// <param name="str">The string to decode.</param>
/// <returns>Returns a decoded string.</returns>
/// <returns>Returns the base64 decoded string.</returns>
public static string Decode(string str) { return WebUILibFunctions.webui_decode(str); }
}
}
63 changes: 62 additions & 1 deletion WebUI4CSharp/WebUIEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public WebUIEvent(UIntPtr window, UIntPtr event_type, IntPtr element, UIntPtr ev
/// <summary>
/// Event type.
/// </summary>
public webui_events EventType { get => (webui_events)_event.event_type; }
public webui_event EventType { get => (webui_event)_event.event_type; }

/// <summary>
/// HTML element ID.
Expand Down Expand Up @@ -101,6 +101,39 @@ public long GetIntAt(UIntPtr index)
}
}

/// <summary>
/// Get the first argument as float.
/// </summary>
/// <returns>Returns argument as float.</returns>
public double GetFloat()
{
if (Initialized)
{
return WebUILibFunctions.webui_get_float(ref _event);
}
else
{
return 0;
}
}

/// <summary>
/// Get an argument as float at a specific index.
/// </summary>
/// <param name="index">The argument position starting from 0.</param>
/// <returns>Returns argument as float.</returns>
public double GetFloatAt(UIntPtr index)
{
if (Initialized)
{
return WebUILibFunctions.webui_get_float_at(ref _event, index);
}
else
{
return 0;
}
}

/// <summary>
/// Get the first argument as string.
/// </summary>
Expand Down Expand Up @@ -235,6 +268,22 @@ public UIntPtr GetSizeAt(UIntPtr index)
}
}

/// <summary>
/// Get how many arguments there are in an event.
/// </summary>
/// <returns>Returns the arguments count.</returns>
public UIntPtr GetCount()
{
if (Initialized)
{
return WebUILibFunctions.webui_get_count(ref _event);
}
else
{
return 0;
}
}

/// <summary>
/// Return the response to JavaScript as integer.
/// </summary>
Expand All @@ -247,6 +296,18 @@ public void ReturnInt(long value)
}
}

/// <summary>
/// Return the response to JavaScript as float.
/// </summary>
/// <param name="value">The float number to be send to JavaScript.</param>
public void ReturnFloat(double value)
{
if (Initialized)
{
WebUILibFunctions.webui_return_float(ref _event, value);
}
}

/// <summary>
/// Return the response to JavaScript as string.
/// </summary>
Expand Down
124 changes: 110 additions & 14 deletions WebUI4CSharp/WebUILibFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public static class WebUILibFunctions
// The demos define the WEBUIDEMO conditional for convenience
// Enable the right library depending on the selected platform target in each demo
private const string _LibName = "..\\..\\..\\..\\..\\WebUI_binaries\\64bits\\webui-2.dll"; // Any CPU
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\64bits\\webui-2.dll"; // x64
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\64bits\\webui-2_debug.dll"; // x64 (verbose logging)
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\32bits\\webui-2.dll"; // x32
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\32bits\\webui-2_debug.dll"; // x32 (verbose logging)
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\64bits\\webui-2.dll"; // x64
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\64bits\\webui-2_debug.dll"; // x64 (verbose logging)
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\32bits\\webui-2.dll"; // x32
//private const string _LibName = "..\\..\\..\\..\\..\\..\\WebUI_binaries\\32bits\\webui-2_debug.dll"; // x32 (verbose logging)
#else
private const string _LibName = "webui-2";
#endif
Expand All @@ -34,7 +34,7 @@ public static class WebUILibFunctions
/// Create a new webui window object using a specified window number.
/// </summary>
/// <param name="window_number">The window number (should be > 0, and < WEBUI_MAX_IDS).</param>
/// <returns>Returns the window number.</returns>
/// <returns>Returns the same window number if success.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_new_window_id)</see></para>
/// </remarks>
Expand Down Expand Up @@ -64,6 +64,18 @@ public static class WebUILibFunctions
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr webui_bind(UIntPtr window, [MarshalAs(UnmanagedType.LPUTF8Str)] string element, BindCallback func);

/// <summary>
/// Get the recommended web browser ID to use. If you are already using one,
/// this function will return the same ID.
/// </summary>
/// <param name="window">The window number.</param>
/// <returns>Returns a web browser ID.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_get_best_browser)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr webui_get_best_browser(UIntPtr window);

/// <summary>
/// Show a window using embedded HTML, or a file. If the window is already open, it will be refreshed.
/// </summary>
Expand Down Expand Up @@ -91,6 +103,20 @@ public static class WebUILibFunctions
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool webui_show_browser(UIntPtr window, [MarshalAs(UnmanagedType.LPUTF8Str)] string content, UIntPtr browser);

/// <summary>
/// Show a WebView window using embedded HTML, or a file. If the window is already
/// open, it will be refreshed. Note: Win32 need `WebView2Loader.dll`.
/// </summary>
/// <param name="window">The window number.</param>
/// <param name="content">The HTML, URL, Or a local file.</param>
/// <returns>Returns True if showing the window is successed.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_show_wv)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool webui_show_wv(UIntPtr window, [MarshalAs(UnmanagedType.LPUTF8Str)] string content);

/// <summary>
/// Set the window in Kiosk mode (Full screen).
/// </summary>
Expand Down Expand Up @@ -189,7 +215,7 @@ public static class WebUILibFunctions
public static extern bool webui_is_shown(UIntPtr window);

/// <summary>
/// Set the maximum time in seconds to wait for the browser to start.
/// Set the maximum time in seconds to wait for the window to connect. This affects `show()` and `wait()`.
/// </summary>
/// <param name="second">The timeout in seconds.</param>
/// <remarks>
Expand All @@ -211,10 +237,10 @@ public static class WebUILibFunctions
public static extern void webui_set_icon(UIntPtr window, [MarshalAs(UnmanagedType.LPUTF8Str)] string icon, [MarshalAs(UnmanagedType.LPUTF8Str)] string icon_type);

/// <summary>
/// Base64 encoding. Use this to safely send text based data to the UI. If it fails it will return NULL.
/// Encode text to Base64. The returned buffer need to be freed.
/// </summary>
/// <param name="str">The string to encode (Should be null terminated).</param>
/// <returns>Returns a encoded string.</returns>
/// <returns>Returns the base64 encoded string.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_encode)</see></para>
/// </remarks>
Expand All @@ -223,10 +249,10 @@ public static class WebUILibFunctions
public static extern string webui_encode([MarshalAs(UnmanagedType.LPUTF8Str)] string str);

/// <summary>
/// Base64 decoding. Use this to safely decode received Base64 text from the UI. If it fails it will return NULL.
/// Decode a Base64 encoded text. The returned buffer need to be freed.
/// </summary>
/// <param name="str">The string to decode (Should be null terminated).</param>
/// <returns>Returns a decoded string.</returns>
/// <returns>Returns the base64 decoded string.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_decode)</see></para>
/// </remarks>
Expand Down Expand Up @@ -316,10 +342,10 @@ public static class WebUILibFunctions
public static extern void webui_set_profile(UIntPtr window, [MarshalAs(UnmanagedType.LPUTF8Str)] string name, [MarshalAs(UnmanagedType.LPUTF8Str)] string path);

/// <summary>
/// Set the web browser proxy_server to use. Need to be called before 'webui_show()'.
/// Set the web browser proxy server to use. Need to be called before `webui_show()`.
/// </summary>
/// <param name="window">The window number.</param>
/// <param name="proxy_server">The web browser proxy_server. For example 'http://127.0.0.1:8888'</param>
/// <param name="proxy_server">The web browser proxy_server.</param>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_set_proxy)</see></para>
/// </remarks>
Expand Down Expand Up @@ -412,7 +438,7 @@ public static class WebUILibFunctions
public static extern UIntPtr webui_get_child_process_id(UIntPtr window);

/// <summary>
/// Set a custom web-server network port to be used by WebUI.
/// Set a custom web-server/websocket network port to be used by WebUI.
/// This can be useful to determine the HTTP link of `webui.js` in case
/// you are trying to use WebUI with an external web-server like NGNIX
/// </summary>
Expand All @@ -426,6 +452,31 @@ public static class WebUILibFunctions
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool webui_set_port(UIntPtr window, UIntPtr port);

/// <summary>
/// Control the WebUI behaviour. It's better to call at the beginning.
/// </summary>
/// <param name="option">The desired option from `webui_config` enum.</param>
/// <param name="status">The status of the option, `true` or `false`.</param>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_set_config)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void webui_set_config(UIntPtr option, [MarshalAs(UnmanagedType.I1)] bool status);

/// <summary>
/// Control if UI events comming from this window should be processed
/// one a time in a single blocking thread `True`, or process every event in
/// a new non-blocking thread `False`. This update single window. You can use
/// `webui_set_config(ui_event_blocking, ...)` to update all windows.
/// </summary>
/// <param name="window">The window number.</param>
/// <param name="status">The blocking status `true` or `false`.</param>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_set_event_blocking)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void webui_set_event_blocking(UIntPtr window, [MarshalAs(UnmanagedType.I1)] bool status);

/// <summary>
/// Set the SSL/TLS certificate and the private key content, both in PEM
/// format. This works only with `webui-2-secure` library. If set empty WebUI
Expand Down Expand Up @@ -473,13 +524,24 @@ public static class WebUILibFunctions
/// Chose between Deno and Nodejs as runtime for .js and .ts files.
/// </summary>
/// <param name="window">The window number.</param>
/// <param name="runtime">Deno or Nodejs.</param>
/// <param name="runtime">Deno, Nodejs or None.</param>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_set_runtime)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void webui_set_runtime(UIntPtr window, UIntPtr runtime);

/// <summary>
/// Get how many arguments there are in an event.
/// </summary>
/// <param name="e">The event struct.</param>
/// <returns>Returns the arguments count.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_get_count)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr webui_get_count(ref webui_event_t e);

/// <summary>
/// Get an argument as integer at a specific index.
/// </summary>
Expand All @@ -503,6 +565,29 @@ public static class WebUILibFunctions
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern long webui_get_int(ref webui_event_t e);

/// <summary>
/// Get an argument as float at a specific index.
/// </summary>
/// <param name="e">The event struct.</param>
/// <param name="index">The argument position starting from 0.</param>
/// <returns>Returns argument as float.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_get_float_at)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern double webui_get_float_at(ref webui_event_t e, UIntPtr index);

/// <summary>
/// Get the first argument as float.
/// </summary>
/// <param name="e">The event struct.</param>
/// <returns>Returns argument as float.</returns>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_get_float)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern double webui_get_float(ref webui_event_t e);

/// <summary>
/// Get an argument as string at a specific index.
/// </summary>
Expand Down Expand Up @@ -585,6 +670,17 @@ public static class WebUILibFunctions
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void webui_return_int(ref webui_event_t e, long n);

/// <summary>
/// Return the response to JavaScript as float.
/// </summary>
/// <param name="e">The event struct.</param>
/// <param name="f">The float number to be send to JavaScript.</param>
/// <remarks>
/// <para><see href="https://github.com/webui-dev/webui/blob/main/include/webui.h">WebUI source file: /include/webui.h (webui_return_float)</see></para>
/// </remarks>
[DllImport(_LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void webui_return_float(ref webui_event_t e, double f);

/// <summary>
/// Return the response to JavaScript as string.
/// </summary>
Expand Down
Loading

0 comments on commit d237c90

Please sign in to comment.