### Application Lifecycle Functions Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Use these functions to initialize the application with command-line arguments and start the main event loop. ```c void Hermes_App_Init(int* argc, char*** argv); void Hermes_App_Run(void); ``` -------------------------------- ### Add Hermes Package Source: https://github.com/mythetech/hermes/blob/main/README.md Install the core Mythetech Hermes package using the .NET CLI. ```shell dotnet add package Mythetech.Hermes ``` -------------------------------- ### Blazor Application Setup Source: https://github.com/mythetech/hermes/blob/main/README.md Initialize and configure a Blazor application with Hermes, including window options. ```csharp using Hermes; using Hermes.Blazor; HermesWindow.Prewarm(); var builder = HermesBlazorAppBuilder.CreateDefault(args); builder.ConfigureWindow(options => { options.Title = "My Blazor App"; options.Width = 1024; options.Height = 768; options.CenterOnScreen = true; }); builder.RootComponents.Add("#app"); var app = builder.Build(); app.Run(); ``` -------------------------------- ### Typical Program.cs for Hermes App Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Demonstrates a typical Program.cs setup for a Hermes application, including window configuration, static file serving, and interop bridge registration. ```csharp HermesWindow.Prewarm(); var builder = HermesWebAppBuilder.Create(args); builder.ConfigureWindow(opts => { opts.Title = "My SPA App"; opts.Width = 800; opts.Height = 600; opts.DevToolsEnabled = true; }); var isDev = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") == "Development"; if (isDev) { builder.UseDevServer("http://localhost:5173"); } else { builder.UseStaticFiles("frontend/dist"); builder.UseSpaFallback(); } builder.UseInteropBridge(bridge => { bridge.Register("greet", name => $ ``` ```csharp "Hello, " + name + "!"); bridge.Register("getRuntime", () => $'.NET {Environment.Version}'); bridge.Register("getPlatform", () => Environment.OSVersion.Platform.ToString()); }); var app = builder.Build(); app.Run(); ``` -------------------------------- ### Configure Hermes.Web Application Source: https://github.com/mythetech/hermes/blob/main/docs/plans/SpaAlternatives.md Minimal setup for a Hermes.Web application, including window configuration, serving static files, and fallback for client-side routing. ```csharp var builder = HermesWebAppBuilder.CreateDefault(args); builder.ConfigureWindow(options => { options.Title = "My React App"; options.Width = 1280; options.Height = 720; }); // Production: serve built assets builder.UseStaticFiles("dist"); // explicit path, or empty for wwwroot/ builder.UseSpaFallback(); // index.html fallback for client-side routing // Interop bridge builder.UseInteropBridge(bridge => { bridge.Register("greet", (string name) => $ ``` ```csharp var app = builder.Build(); app.Run(); ``` -------------------------------- ### Record Start Time and Elapsed Time Source: https://github.com/mythetech/hermes/blob/main/benchmarks/Hermes.Benchmarks.Apps/TauriTestApp/BlazorApp/wwwroot/index.html Records the start time when the page loads and provides a function to calculate the elapsed time since then. This is useful for performance measurements. ```javascript const startTime = performance.now(); window.getElapsedTime = function() { return performance.now() - startTime; }; ``` -------------------------------- ### C# Menu API for Runtime Modifications Source: https://github.com/mythetech/hermes/blob/main/ARCHITECTURE.md Demonstrates initial menu setup, dynamic state changes, adding menus/items at runtime for plugins, removing menus/items on plugin unload, and creating context menus. Use for dynamic UI updates and plugin integration. ```csharp // Initial menu setup var menuBar = window.MenuBar; menuBar.AddMenu("File", file => file .AddItem("New", "file.new", item => item.WithAccelerator("Ctrl+N")) .AddItem("Open...", "file.open", item => item.WithAccelerator("Ctrl+O")) .AddSeparator() .AddItem("Save", "file.save", item => item.WithAccelerator("Ctrl+S"))); // Dynamic updates (state changes) menuBar["file.save"].IsEnabled = document.IsDirty; menuBar["view.sidebar"].IsChecked = sidebarVisible; // PLUGIN LOADING: Add menu at runtime public void OnPluginLoaded(IPlugin plugin) { menuBar.AddMenu(plugin.MenuName, menu => { foreach (var command in plugin.Commands) menu.AddItem(command.Label, command.Id); }); // Or insert into existing menu menuBar["Tools"].InsertItem( afterId: "tools.options", label: plugin.Name, commandId: $"plugins.{plugin.Id}.open"); } // PLUGIN UNLOADING: Remove menu at runtime public void OnPluginUnloaded(IPlugin plugin) { menuBar.RemoveMenu(plugin.MenuName); menuBar["Tools"].RemoveItem($"plugins.{plugin.Id}.open"); } // Context menus var contextMenu = window.CreateContextMenu(); contextMenu.AddItem("Cut", "edit.cut", item => item.WithAccelerator("Ctrl+X")); contextMenu.Show(mouseX, mouseY); ``` -------------------------------- ### Add Hermes Blazor Package Source: https://github.com/mythetech/hermes/blob/main/README.md Install the Mythetech Hermes package specifically for Blazor applications. ```shell dotnet add package Mythetech.Hermes.Blazor ``` -------------------------------- ### Window Property Functions Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Functions for getting and setting window properties like title and size. ```APIDOC ## Hermes_Window_SetTitle ### Description Sets the title of the specified application window. ### Signature ```c void Hermes_Window_SetTitle(void* window, const char* title); ``` ## Hermes_Window_GetSize ### Description Retrieves the current size (width and height) of the specified application window. ### Signature ```c void Hermes_Window_GetSize(void* window, int* width, int* height); ``` ## Hermes_Window_SetSize ### Description Sets the size (width and height) of the specified application window. ### Signature ```c void Hermes_Window_SetSize(void* window, int width, int height); ``` ``` -------------------------------- ### Interop Bridge Protocol Example Source: https://github.com/mythetech/hermes/blob/main/docs/plans/SpaAlternatives.md Illustrates the JSON message flow between JavaScript and the backend for method invocation and result handling. Errors are also handled via a similar JSON structure. ```json JS: bridge.invoke('greet', 'World') -> JSON: {"type":"invoke","id":"abc123","method":"greet","args":["World"]} -> window.external.sendMessage(json) -> WebMessageReceived event on backend -> InteropBridge deserializes, finds handler, executes -> Result JSON: {"type":"result","id":"abc123","value":"Hello, World!"} -> SendWebMessage(json) back to WebView -> JS promise resolves with "Hello, World!" ``` ```json Errors follow the same path with {"type":"error","id":"abc123","message":"..."} so the JS promise rejects. ``` -------------------------------- ### Window Property Accessors Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Functions for setting and getting window properties such as title and size. More property accessors are available but not listed. ```c void Hermes_Window_SetTitle(void* window, const char* title); void Hermes_Window_GetSize(void* window, int* width, int* height); void Hermes_Window_SetSize(void* window, int width, int height); ``` -------------------------------- ### Register Interop Bridge Handler Source: https://github.com/mythetech/hermes/blob/main/docs/plans/SpaAlternatives.md Register a C# method to be called from JavaScript via the interop bridge. This example registers a 'greet' function. ```csharp builder.UseInteropBridge(bridge => { bridge.Register("greet", (string name) => $"Hello, {name}!"); }); ``` -------------------------------- ### Build Linux Native Library Source: https://github.com/mythetech/hermes/blob/main/CONTRIBUTING.md Navigate to the Linux native library directory and build it using 'make'. ```bash cd src/Hermes.Native.Linux make ``` -------------------------------- ### Hermes Application Startup Flow Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Outlines the sequence of calls in the Program.cs file for application startup. ```text Program.cs ├─ HermesWindow.Prewarm() # Optional platform pre-warming ├─ HermesWebAppBuilder.Create(args) ├─ builder.ConfigureWindow(opts => {}) # Title, size, DevTools, etc. ├─ builder.UseStaticFiles("wwwroot") # OR builder.UseDevServer(url) ├─ builder.UseSpaFallback() # Route extensionless paths → index.html ├─ builder.UseInteropBridge(bridge => {}) ├─ builder.Build() │ ├─ Creates HermesWindow │ ├─ Registers custom scheme handler (StaticFileHost) │ ├─ Sets navigation URL (platform-specific scheme) │ ├─ Creates InteropBridge (if configured) │ └─ Returns HermesWebApp └─ app.Run() # Blocks until window closes ``` -------------------------------- ### Basic Window Creation Source: https://github.com/mythetech/hermes/blob/main/README.md Create and display a basic application window with a title, size, and initial URL. ```csharp using Hermes; var window = new HermesWindow() .SetTitle("My Application") .SetSize(1024, 768) .Center() .Load("https://example.com"); window.WaitForClose(); ``` -------------------------------- ### Build macOS Native Library Source: https://github.com/mythetech/hermes/blob/main/CONTRIBUTING.md Navigate to the macOS native library directory and build it using 'make'. ```bash cd src/Hermes.Native.macOS make ``` -------------------------------- ### Cross-platform File Filter Format in C# Source: https://github.com/mythetech/hermes/blob/main/PLATFORM-DIFFERENCES.md Defines a cross-platform format for file filters used in file dialogs. This C# example shows how to declare filter tuples. ```csharp // Cross-platform filter format var filters = new[] { ("Text Files", "*.txt"), ("All Files", "*.*") }; ``` -------------------------------- ### Build and Test Hermes Project Source: https://github.com/mythetech/hermes/blob/main/CONTRIBUTING.md Clone the repository, build the solution, and run tests using dotnet CLI commands. ```bash git clone https://github.com/Mythetech/Hermes.git cd Hermes dotnet build dotnet test ``` -------------------------------- ### Window Registration and Creation Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt Functions for registering window classes, creating windows, and managing their lifecycle. ```APIDOC ## RegisterClassExW ### Description Registers a window class for subsequent use in calls to the Create-WindowEx function. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## UnregisterClassW ### Description Unregisters a window class, freeing the memory currently allocated for the class. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## CreateWindowExW ### Description Creates an overlapped, top-level window with an extended style; otherwise, this function is identical to the CreateWindow function. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DestroyWindow ### Description Destroys the specified window. The function sends a WM_DESTROY message to the window being destroyed prior to removing it from the screen. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DefWindowProcW ### Description Passes window messages that the calling thread's message queue does not contain to the default window procedure. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## ShowWindow ### Description Sets the specified window's show state. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## UpdateWindow ### Description Updates the client area of the specified window by sending one or more WM_PAINT messages to the window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## SetWindowTextW ### Description Sets the text of the specified window's title bar (if the window has a title bar). ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetWindowTextW ### Description Copies the text of the specified window's title bar (if it has one) into a buffer. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetWindowTextLengthW ### Description Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar). ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## SetWindowPos ### Description Changes the size, position, and Z order of a child, pop-up, or top-level window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetWindowRect ### Description Gets the dimensions of the bounding rectangle of an object in screen coordinates. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetClientRect ### Description Retrieves the coordinates of a window's client area. The coordinates are relative to the lower-left corner of the window's client area. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IsZoomed ### Description Determines whether a window is zoomed (in its maximized state). ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IsIconic ### Description Determines whether a window is minimized (iconic). ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## LoadImageW ### Description Loads an image (icon, cursor, bitmap, or metafile) from the specified module or an executable file. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## LoadCursorW ### Description Loads a cursor resource from the executable file associated with a specified module, or from a system-defined resource. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## CreateSolidBrush ### Description Creates a solid brush with the specified color. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DeleteObject ### Description Deletes a logical pen, brush, or font resource from the system. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetModuleHandleW ### Description Retrieves a handle to the specified module (a dynamic-link library or executable file) that is mapped into the address space of the calling process. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Register Custom Scheme for Static Files Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Handles platform-specific custom URL scheme registration for static file serving. Windows uses 'http', while macOS and Linux use 'app://'. This must be done before window initialization. ```csharp if (OperatingSystem.IsWindows()) window.RegisterCustomScheme("http", staticFileHost.HandleRequest); else window.RegisterCustomScheme("app", staticFileHost.HandleRequest); var baseUri = OperatingSystem.IsWindows() ? "http://localhost/" : "app://localhost/"; window.Load(baseUri); ``` -------------------------------- ### Application Lifecycle Functions Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Functions for initializing and running the application. ```APIDOC ## Hermes_App_Init ### Description Initializes the Hermes application with command-line arguments. ### Signature ```c void Hermes_App_Init(int* argc, char*** argv); ``` ## Hermes_App_Run ### Description Starts the main event loop of the Hermes application. ### Signature ```c void Hermes_App_Run(void); ``` ``` -------------------------------- ### Windows and Linux Dependencies Source: https://github.com/mythetech/hermes/blob/main/ARCHITECTURE.md Include these NuGet packages for Windows and GtkSharp for Linux to enable native functionality. ```xml ``` -------------------------------- ### Configure Dev Server or Static Files Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Conditionally configures the application to use a development server or serve static files based on the environment. Use the DOTNET_ENVIRONMENT variable for this. ```csharp var isDev = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") == "Development"; if (isDev) { builder.UseDevServer("http://localhost:5173"); } else { builder.UseStaticFiles("frontend/dist"); builder.UseSpaFallback(); } ``` -------------------------------- ### Manage Development Server Process Source: https://github.com/mythetech/hermes/blob/main/docs/plans/SpaAlternatives.md Configure Hermes.Web to manage the development server process, including specifying the command, port, working directory, and startup timeout. ```csharp // Development option 2: let Hermes manage the dev server process builder.RunDevServer(dev => { dev.Command = "npm run dev"; dev.Port = 5173; dev.WorkingDirectory = "./frontend"; // optional, defaults to project root dev.StartupTimeout = TimeSpan.FromSeconds(30); // optional }); ``` -------------------------------- ### Window Lifecycle Functions Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Functions for creating, showing, closing, and destroying windows. ```APIDOC ## Hermes_Window_Create ### Description Creates a new application window with the specified parameters. ### Signature ```c void* Hermes_Window_Create(const HermesWindowParams* params); ``` ## Hermes_Window_Show ### Description Displays the specified application window. ### Signature ```c void Hermes_Window_Show(void* window); ``` ## Hermes_Window_Close ### Description Initiates the closing of the specified application window. ### Signature ```c void Hermes_Window_Close(void* window); ``` ## Hermes_Window_WaitForClose ### Description Blocks execution until the specified window is closed. ### Signature ```c void Hermes_Window_WaitForClose(void* window); ``` ## Hermes_Window_Destroy ### Description Destroys the specified application window and releases its resources. ### Signature ```c void Hermes_Window_Destroy(void* window); ``` ``` -------------------------------- ### Configure Dev Server or Static Files (Compiler Directives) Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Conditionally configures the application to use a development server or serve static files using compiler directives. This is an alternative to environment variables. ```csharp #if DEBUG builder.UseDevServer("http://localhost:5173"); #else builder.UseStaticFiles("frontend/dist"); builder.UseSpaFallback(); #endif ``` -------------------------------- ### Svelte Adapters for Hermes Integration Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Demonstrates using @hermes/svelte adapters to integrate with the Hermes bridge in a Svelte application. It utilizes stores for connection status, invoking .NET methods, and reacting to .NET events. The createInvokeStore auto-invokes on creation, and createEventStore provides reactive updates. ```svelte {#if $hermesConnected}

Greeting: {$greet.data}

Seconds: {$tick ?? 0}

{:else}

Not connected to Hermes

{/if} ``` -------------------------------- ### Configure Hermes Web App with Builder API Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Use the HermesWebAppBuilder to fluently configure window options, static files, SPA fallback, and interop bridges. All configuration is deferred until Build(). ```csharp var builder = HermesWebAppBuilder.Create(args); builder .ConfigureWindow(opts => { /* HermesWindowOptions */ }) .UseStaticFiles("frontend/dist") // Set static file root .UseSpaFallback() // Enable SPA routing .UseInteropBridge(bridge => // Register .NET handlers { bridge.Register("method", () => result); bridge.RegisterAsync("async", () => Task.FromResult(result)); bridge.On("event", () => { }); }); var app = builder.Build(); app.Run(); ``` -------------------------------- ### DWM APIs Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt Functions for interacting with the Desktop Window Manager. ```APIDOC ## DwmExtendFrameIntoClientArea ### Description Extends the window frame's client area. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DwmSetWindowAttribute ### Description Sets a value for a specified DWM attribute of a window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DwmGetColorizationColor ### Description Retrieves the current color of the Desktop Window Manager (DWM) colorization. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Connect to Running Development Server Source: https://github.com/mythetech/hermes/blob/main/docs/plans/SpaAlternatives.md Configure Hermes.Web to connect to an already running development server, typically used during frontend development. ```csharp // Development option 1: connect to already-running dev server builder.UseDevServer("http://localhost:5173"); ``` -------------------------------- ### Core Bridge API Usage Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Demonstrates how to use the core @hermes/bridge API to detect the environment, invoke .NET methods with and without options, subscribe to .NET events, and send data. Remember to clean up event subscriptions. ```typescript import { bridge } from '@hermes/bridge'; // Detect environment if (bridge.isHermes) { /* running in Hermes window */ } // Invoke .NET method const greeting = await bridge.invoke('greet', 'World'); // Invoke with options const result = await bridge.invoke('slowOp', { timeout: 5000 }, arg1); // Subscribe to .NET events (returns unsubscribe function) const unsub = bridge.on('tick', (seconds) => { console.log(`Tick: ${seconds}`); }); // Push event to .NET bridge.send('userAction', { type: 'click', target: 'button' }); // Cleanup unsub(); ``` -------------------------------- ### Build Native Menus with Fluent API Source: https://github.com/mythetech/hermes/blob/main/README.md Construct native application menus using a fluent API, including accelerators and separators. Handles runtime modification for dynamic plugin loading. ```csharp // Build menus with fluent API window.MenuBar .AddMenu("File", file => { file.AddItem("New", "file.new", item => item.WithAccelerator("Ctrl+N")) .AddItem("Open...", "file.open", item => item.WithAccelerator("Ctrl+O")) .AddSeparator() .AddItem("Save", "file.save", item => item.WithAccelerator("Ctrl+S")) .AddItem("Exit", "file.exit"); }) .AddMenu("Edit", edit => { edit.AddItem("Undo", "edit.undo", item => item.WithAccelerator("Ctrl+Z")) .AddItem("Redo", "edit.redo", item => item.WithAccelerator("Ctrl+Y")) .AddSeparator() .AddItem("Cut", "edit.cut", item => item.WithAccelerator("Ctrl+X")) .AddItem("Copy", "edit.copy", item => item.WithAccelerator("Ctrl+C")) .AddItem("Paste", "edit.paste", item => item.WithAccelerator("Ctrl+V")); }); // Handle menu clicks window.MenuBar.ItemClicked += itemId => { if (itemId == "file.exit") window.Close(); }; // Runtime modification for plugins window.MenuBar.AddMenu("Plugins", plugins => { plugins.AddItem("My Plugin", "plugins.myplugin"); }); ``` -------------------------------- ### Hermes NuGet Package Structure Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Defines the directory structure for the Mythetech.Hermes.Web NuGet package. ```tree src/Hermes.Web/ # Mythetech.Hermes.Web ├── Hermes.Web.csproj # Depends on Mythetech.Hermes (core) ├── HermesWebApp.cs # App facade (Run, Bridge access) ├── HermesWebAppBuilder.cs # Fluent builder API ├── Hosting/ │ ├── StaticFileHost.cs # SPA-aware file server │ └── MimeTypes.cs # Extension → MIME mapping └── Interop/ ├── InteropBridge.cs # Bidirectional message processor ├── InteropBridgeOptions.cs # Fluent handler registration └── InteropMessage.cs # JSON envelope types + source gen context ``` -------------------------------- ### Window Lifecycle Functions Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Manage the creation, display, closing, and destruction of application windows. `Hermes_Window_WaitForClose` blocks until the window is closed. ```c void* Hermes_Window_Create(const HermesWindowParams* params); void Hermes_Window_Show(void* window); void Hermes_Window_Close(void* window); void Hermes_Window_WaitForClose(void* window); void Hermes_Window_Destroy(void* window); ``` -------------------------------- ### Invoke Tauri Command Source: https://github.com/mythetech/hermes/blob/main/benchmarks/Hermes.Benchmarks.Apps/TauriTestApp/BlazorApp/wwwroot/index.html Provides a function to invoke a Tauri command named 'benchmark_ready'. It checks if the Tauri environment is available and sends a time value, otherwise it logs the data to the console. ```javascript window.invokeTauri = async function(time) { if (window.__TAURI__) { await window.__TAURI__.core.invoke('benchmark_ready', { time: time }); } else { console.log('BENCHMARK_READY:' + time.toFixed(2)); } }; ``` -------------------------------- ### Package.json for Hermes Framework Adapter Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Defines a framework adapter package, specifying its name and peer dependencies on the core Hermes bridge and the specific framework. ```json { "name": "@hermes/", "peerDependencies": { "@hermes/bridge": ">=1.0.0-preview.1", "": "^X.0.0" } } ``` -------------------------------- ### Dialogs - COM Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt COM interfaces and functions for file open/save dialogs. ```APIDOC ## IFileOpenDialog ### Description Represents a file open dialog box that allows the user to select one or more files or folders. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IFileSaveDialog ### Description Represents a file save dialog box that allows the user to select a location and file name to save a file. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IFileDialog ### Description Represents a common file dialog box interface. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IShellItem ### Description Represents a shell item, which can be a file, folder, or other item in the shell namespace. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IShellItemArray ### Description Represents an array of shell items. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## SHCreateItemFromParsingName ### Description Creates a shell item object from a parsing name. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## CoCreateInstance ### Description Creates a single uninitialized object of the specified class. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## CoTaskMemFree ### Description Frees memory allocated by CoTaskMemAlloc. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## FileOpenDialog ### Description Launches the file open dialog. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## FileSaveDialog ### Description Launches the file save dialog. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### React Adapter for Invoking .NET Methods Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Shows how to use the useInvoke hook from @hermes/react to call a .NET 'greet' method within a React component. The hook manages loading, error states, and provides a refetch function. It automatically invokes the method on mount and can be explicitly called with arguments. ```typescript import { useInvoke } from '@hermes/react'; function GreetCard() { const [name, setName] = useState('World'); const { data, loading, error, invoke } = useInvoke('greet'); return (
setName(e.target.value)} /> {loading && Loading...} {error && Error: {error.message}} {data &&

{data}

}
); } ``` -------------------------------- ### WebView Operations Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Functions for interacting with the WebView component within a window. ```APIDOC ## Hermes_Window_NavigateToUrl ### Description Navigates the WebView in the specified window to a given URL. ### Signature ```c void Hermes_Window_NavigateToUrl(void* window, const char* url); ``` ## Hermes_Window_NavigateToString ### Description Loads the WebView in the specified window with the provided HTML content. ### Signature ```c void Hermes_Window_NavigateToString(void* window, const char* html); ``` ## Hermes_Window_SendWebMessage ### Description Sends a message from the native side to the JavaScript running in the WebView. ### Signature ```c void Hermes_Window_SendWebMessage(void* window, const char* message); ``` ## Hermes_Window_RegisterCustomScheme ### Description Registers a custom URI scheme for the WebView to handle. ### Signature ```c void Hermes_Window_RegisterCustomScheme(void* window, const char* scheme); ``` ## Hermes_Window_RunJavascript ### Description Executes a JavaScript script within the WebView of the specified window. ### Signature ```c void Hermes_Window_RunJavascript(void* window, const char* script); ``` ``` -------------------------------- ### Icon loading Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt Function for loading icons. ```APIDOC ## LoadIcon ### Description Loads a system-defined icon or a custom icon from a file. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### macOS Native Code Dependency Source: https://github.com/mythetech/hermes/blob/main/ARCHITECTURE.md For macOS, a small Objective-C library named Hermes.Native.dylib is required. ```xml ``` -------------------------------- ### Svelte Adapter API Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md The Svelte adapter offers stores for managing connection status, invoking .NET methods, and reacting to events within Svelte applications. ```APIDOC ## Svelte Adapter (`@hermes/svelte`) ### Stores Provides reactive stores for seamless integration with Svelte. ```svelte {#if $hermesConnected}

Greeting: {$greet.data}

Seconds: {$tick ?? 0}

{:else}

Not connected to Hermes

{/if} ``` **Store Types:** - **`hermesConnected: Readable`**: Indicates whether the application is running within the Hermes environment. - **`createInvokeStore(method, ...args): Readable>`**: An auto-invoking store that exposes `{ data, loading, error }` states for a given .NET method. - **`createEventStore(eventName, initialValue?): Readable`**: A reactive store that updates automatically when events are pushed from the .NET backend. ``` -------------------------------- ### Menu APIs Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt Functions for creating, manipulating, and displaying menus. ```APIDOC ## CreateMenu ### Description Creates a menu, a list of commands that an application presents to the user. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## CreatePopupMenu ### Description Creates an empty pop-up menu. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DestroyMenu ### Description Destroys the specified menu and frees any memory the menu occupied. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## AppendMenuW ### Description Appends a new item to the end of the specified menu bar, pop-up menu, or submenu. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## InsertMenuW ### Description Inserts a new item into the specified menu at the specified position. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## RemoveMenu ### Description Removes an item from the specified menu and invalidates the menu's layout. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## SetMenu ### Description Replaces the current menu of the specified window with the menu specified by the hMenu parameter. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DrawMenuBar ### Description Redraws the menu bar for the specified window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetMenu ### Description Retrieves a handle to the menu associated with the specified window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetSubMenu ### Description Retrieves a handle to the specified submenu. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetMenuItemCount ### Description Retrieves the number of items in the specified menu. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## EnableMenuItem ### Description Enables, disables, or grays the specified menu item. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## CheckMenuItem ### Description Enables, disables, or selects (checks) a menu item. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## ModifyMenuW ### Description Modifies an existing menu item or adds a new item to a menu. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetMenuItemInfoW ### Description Retrieves information about a specified menu item. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## SetMenuItemInfoW ### Description Sets new information about a specified menu item. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## TrackPopupMenu ### Description Displays a pop-up menu and tracks the user's selection of items. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## EndMenu ### Description Closes the current menu. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Accelerator APIs Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt Functions for creating and translating accelerator tables. ```APIDOC ## CreateAcceleratorTableW ### Description Creates an accelerator table. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## DestroyAcceleratorTable ### Description Destroys an accelerator table. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## TranslateAcceleratorW ### Description Translates accelerator keystrokes. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Implement Content Security Policy Source: https://github.com/mythetech/hermes/blob/main/SECURITY.md Add CSP headers to HTML to restrict script execution. For Blazor WebAssembly applications, 'unsafe-eval' is required. ```html ``` -------------------------------- ### WebView Operations Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Control the WebView component, including navigation, sending messages, registering custom schemes, and executing JavaScript. ```c void Hermes_Window_NavigateToUrl(void* window, const char* url); void Hermes_Window_NavigateToString(void* window, const char* html); void Hermes_Window_SendWebMessage(void* window, const char* message); void Hermes_Window_RegisterCustomScheme(void* window, const char* scheme); void Hermes_Window_RunJavascript(void* window, const char* script); ``` -------------------------------- ### Platform Backend Interface for Menu Operations Source: https://github.com/mythetech/hermes/blob/main/ARCHITECTURE.md Defines the interface for platform-specific menu backend operations, including adding/removing menus and items, and setting item properties. This is a low-level interface for implementing menu functionality. ```csharp public interface IMenuBackend { void AddMenu(string label, int insertIndex); void AddItem(nint menuHandle, string id, string label, string? accelerator, MenuItemFlags flags); void InsertItem(nint menuHandle, string afterId, string id, string label, string? accelerator, MenuItemFlags flags); void RemoveMenu(string label); void RemoveItem(nint menuHandle, string id); void SetItemEnabled(nint menuHandle, string id, bool enabled); void SetItemChecked(nint menuHandle, string id, bool isChecked); void SetItemLabel(nint menuHandle, string id, string label); void SetItemAccelerator(nint menuHandle, string id, string accelerator); } ``` -------------------------------- ### C# Registration API for Hermes Bridge Source: https://github.com/mythetech/hermes/blob/main/SPA-ARCHITECTURE.md Provides methods to register synchronous and asynchronous handlers for JavaScript invocations, and to subscribe to or send events. Use `Register` for sync, `RegisterAsync` for async operations. ```csharp // Sync handlers bridge.Register(string method, Func handler) bridge.Register(string method, Func handler) bridge.Register(string method, Func handler) // Async handlers bridge.RegisterAsync(string method, Func> handler) bridge.RegisterAsync(string method, Func> handler) // Events: subscribe to JS events bridge.On(string eventName, Action handler) bridge.On(string eventName, Action handler) // Events: push to JS bridge.Send(string eventName, object? data = null) ``` -------------------------------- ### Foreground / Cursor Source: https://github.com/mythetech/hermes/blob/main/src/Hermes/Platforms/Windows/NativeMethods.txt Functions for managing foreground window focus and cursor position. ```APIDOC ## SetForegroundWindow ### Description Brings the specified window to the foreground. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetCursorPos ### Description Retrieves the screen coordinates of the mouse cursor, if the mouse is in the client area of the specified window or in the window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## EnumWindows ### Description Enumerates all of the top-level windows with the system. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## GetWindowThreadProcessId ### Description Retrieves the identifier of the thread or process that created the specified window and, optionally, retrieves the identifier of the thread or process that owns the specified window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## IsWindowVisible ### Description Determines whether the specified window, its parent window, its parent's parent, and so on, are visible. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` ```APIDOC ## AllowSetForegroundWindow ### Description Enables the calling process to set the foreground window. ### Method Call ### Endpoint N/A ### Parameters None explicitly documented. ### Request Example N/A ### Response N/A ``` -------------------------------- ### GLib Threading Integration for Main Thread Invocation Source: https://github.com/mythetech/hermes/blob/main/docs/plans/NativeLinuxLib.md Provides a mechanism to invoke a callback function on the main GLib thread. It uses a condition variable and mutex to ensure the callback is executed and completion is signaled. ```c static gboolean invoke_on_main(gpointer user_data) { InvokeContext* ctx = (InvokeContext*)user_data; ctx->callback(); g_mutex_lock(&ctx->mutex); ctx->done = TRUE; g_cond_signal(&ctx->cond); g_mutex_unlock(&ctx->mutex); return G_SOURCE_REMOVE; } void Hermes_Window_Invoke(void* window, InvokeCallback callback) { InvokeContext ctx = { .callback = callback, .done = FALSE }; g_cond_init(&ctx.cond); g_mutex_init(&ctx.mutex); g_idle_add(invoke_on_main, &ctx); // Wait for completion... } ``` -------------------------------- ### Hermes Repository Structure Source: https://github.com/mythetech/hermes/blob/main/ARCHITECTURE.md Overview of the directory layout for the Hermes project, including core libraries, platform-specific implementations, native code, and Blazor integration. ```plaintext Hermes/ ├── src/ │ ├── Hermes/ # Core .NET library │ │ ├── Abstractions/ # IHermesWindow, IMenuBar, etc. │ │ ├── Platforms/ │ │ │ ├── Windows/ # WebView2 + CsWin32 (pure C#) │ │ │ ├── Linux/ # GtkSharp (pure C#) │ │ │ └── macOS/ # P/Invoke to Hermes.Native.dylib │ │ ├── Menu/ # NativeMenuBar, NativeContextMenu │ │ └── HermesWindow.cs # Facade over platform backends │ │ │ ├── Hermes.Native.macOS/ # ONLY native code needed (~3,100 LOC Obj-C) │ │ ├── HermesWindow.m # NSWindow + WKWebView │ │ ├── HermesMenu.m # NSMenu │ │ ├── HermesDialogs.m # NSOpenPanel, NSSavePanel │ │ └── Makefile # Simple clang build │ │ │ └── Hermes.Blazor/ # Blazor integration │ ├── HermesBlazorApp.cs │ └── HermesWebViewManager.cs │ ├── samples/ │ ├── HelloWorld/ │ ├── MenuDemo/ │ └── PluginMenuDemo/ │ └── Hermes.sln ```