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.

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.

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.

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();

Released under the Elastic License 2.0