HermesWindow
The main class for creating native windows with WebView.
Constructor
public HermesWindow()Creates a new Hermes window for the current platform.
Static Methods
Prewarm
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
public HermesWindow SetTitle(string title)Set the window title.
SetSize
public HermesWindow SetSize(int width, int height)Set the initial window size in pixels.
SetPosition
public HermesWindow SetPosition(int x, int y)Set the initial window position.
Center
public HermesWindow Center()Center the window on screen when shown.
SetResizable
public HermesWindow SetResizable(bool resizable)Set whether the window can be resized.
SetMinSize / SetMaxSize
public HermesWindow SetMinSize(int width, int height)
public HermesWindow SetMaxSize(int width, int height)Set size constraints.
SetDevToolsEnabled
public HermesWindow SetDevToolsEnabled(bool enabled)Enable or disable developer tools (F12).
SetCustomTitleBar
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
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
public HermesWindow Load(string url)Load a URL in the WebView.
LoadHtml
public HermesWindow LoadHtml(string html)Load HTML content directly.
RegisterCustomScheme
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
public HermesWindow OnClosing(Action handler)Register a handler for when the window is closing.
OnResized
public HermesWindow OnResized(Action<int, int> handler)Register a handler for when the window is resized.
OnWebMessage
public HermesWindow OnWebMessage(Action<string> handler)Register a handler for messages from JavaScript.
Lifecycle Methods
Show
public void Show()Show the window and return immediately.
WaitForClose
public void WaitForClose()Show the window and block until it is closed.
Close
public void Close()Close the window programmatically.
Properties
MenuBar
public NativeMenuBar MenuBar { get; }Access the native menu bar for this window.
Dialogs
public IDialogBackend Dialogs { get; }Access native dialogs (file open/save).
Title
public string Title { get; set; }Get or set the window title (works after initialization).
Size
public (int Width, int Height) Size { get; set; }Get or set the window size.
Position
public (int X, int Y) Position { get; set; }Get or set the window position.
IsMaximized
public bool IsMaximized { get; }Whether the window is currently maximized.
Runtime Methods
SendMessage
public void SendMessage(string message)Send a message to JavaScript in the WebView.
Invoke
public void Invoke(Action action)Execute an action on the UI thread.
MaximizeWindow / MinimizeWindow / RestoreWindow
public void MaximizeWindow()
public void MinimizeWindow()
public void RestoreWindow()Control window state at runtime.
ToggleMaximize
public void ToggleMaximize()Toggle between maximized and normal state.
Example
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();