Skip to content

HermesWindow ​

The main class for creating native windows with WebView.

Constructor ​

csharp
public HermesWindow()

Creates a new Hermes window for the current platform.

Static Methods ​

Prewarm ​

csharp
public static void Prewarm()

Pre-warm platform resources for faster first-window creation. Call this early in application startup.

On Windows, this begins WebView2 environment creation on a background thread. On Linux and macOS, this is a no-op.

Configuration Methods ​

These methods use a fluent API and must be called before Show() or WaitForClose().

SetTitle ​

csharp
public HermesWindow SetTitle(string title)

Set the window title.

SetSize ​

csharp
public HermesWindow SetSize(int width, int height)

Set the initial window size in pixels.

SetPosition ​

csharp
public HermesWindow SetPosition(int x, int y)

Set the initial window position.

Center ​

csharp
public HermesWindow Center()

Center the window on screen when shown.

SetResizable ​

csharp
public HermesWindow SetResizable(bool resizable)

Set whether the window can be resized.

SetMinSize / SetMaxSize ​

csharp
public HermesWindow SetMinSize(int width, int height)
public HermesWindow SetMaxSize(int width, int height)

Set size constraints.

SetDevToolsEnabled ​

csharp
public HermesWindow SetDevToolsEnabled(bool enabled)

Enable or disable developer tools (F12).

SetCustomTitleBar ​

csharp
public HermesWindow SetCustomTitleBar(bool enabled)

Enable custom title bar mode:

  • macOS: Transparent title bar with native traffic light buttons
  • Windows/Linux: Chromeless mode for fully custom window chrome

RememberWindowState ​

csharp
public HermesWindow RememberWindowState(string? key = null)

Enable window state persistence. Position, size, and maximized state will be saved on close and restored on next launch.

SetTheme ​

csharp
public HermesWindow SetTheme(HermesWindowTheme theme)

Set the initial light or dark appearance of the native window chrome and the WebView: System (default), Light or Dark. Use the Theme property to change it after the window is shown. See Light and Dark Appearance.

Content Methods ​

Load ​

csharp
public HermesWindow Load(string url)

Load a URL in the WebView.

LoadHtml ​

csharp
public HermesWindow LoadHtml(string html)

Load HTML content directly.

RegisterCustomScheme ​

csharp
public HermesWindow RegisterCustomScheme(
    string scheme,
    Func<string, (Stream? Content, string? ContentType)> handler)

Register a custom URL scheme handler for loading bundled assets.

Event Methods ​

OnClosing ​

csharp
public HermesWindow OnClosing(Action handler)

Register a handler for when the window is closing.

OnCloseRequested ​

csharp
public HermesWindow OnCloseRequested(Func<Task<bool>> handler)

Register an async handler that is called when the user clicks the window's close button. Return true to allow the close, or false to cancel it. This is useful for prompting the user to save unsaved changes before closing.

Unlike OnClosing, which fires after the close is confirmed, OnCloseRequested fires before the window closes and can prevent it.

OnResized ​

csharp
public HermesWindow OnResized(Action<int, int> handler)

Register a handler for when the window is resized.

OnWebMessage ​

csharp
public HermesWindow OnWebMessage(Action<string> handler)

Register a handler for messages from JavaScript.

Lifecycle Methods ​

Show ​

csharp
public void Show()

Show the window and return immediately.

WaitForClose ​

csharp
public void WaitForClose()

Show the window and block until it is closed.

Close ​

csharp
public void Close()

Close the window programmatically.

Properties ​

csharp
public NativeMenuBar MenuBar { get; }

Access the native menu bar for this window.

Dialogs ​

csharp
public IDialogBackend Dialogs { get; }

Access native dialogs (file open/save).

Title ​

csharp
public string Title { get; set; }

Get or set the window title (works after initialization).

Size ​

csharp
public (int Width, int Height) Size { get; set; }

Get or set the window size.

Position ​

csharp
public (int X, int Y) Position { get; set; }

Get or set the window position.

IsMaximized ​

csharp
public bool IsMaximized { get; }

Whether the window is currently maximized.

Theme ​

csharp
public HermesWindowTheme Theme { get; set; }

Get or set the light or dark appearance of the native window chrome and the WebView. Can be changed at runtime and from any thread; the change is applied on the UI thread.

Runtime Methods ​

SendMessage ​

csharp
public void SendMessage(string message)

Send a message to JavaScript in the WebView.

Invoke ​

csharp
public void Invoke(Action action)

Execute an action on the UI thread.

MaximizeWindow / MinimizeWindow / RestoreWindow ​

csharp
public void MaximizeWindow()
public void MinimizeWindow()
public void RestoreWindow()

Control window state at runtime.

ToggleMaximize ​

csharp
public void ToggleMaximize()

Toggle between maximized and normal state.

Example ​

csharp
using Hermes;

HermesWindow.Prewarm();

var window = new HermesWindow()
    .SetTitle("My App")
    .SetSize(1024, 768)
    .Center()
    .SetDevToolsEnabled(true)
    .RememberWindowState()
    .OnClosing(() => Console.WriteLine("Closing..."))
    .LoadHtml("<h1>Hello!</h1>");

window.WaitForClose();