ExTauri.Window (ex_tauri v0.2.0)
View SourceManage the native window at runtime from your LiveView.
Bridges to Tauri's core window API via the LiveView hook — no extra plugin is required. Minimize, maximize, resize, retitle, or hide the window in response to your application's state.
Requirements
The
TauriHookmust be mounted in your LiveView (seeExTauri.Hook)Window permissions in
src-tauri/capabilities/default.json. Projects created by current versions ofmix ex_tauri.installalready include them; older projects can add them with:mix ex_tauri.add window
Examples
# Update the window title to reflect the open document
def handle_event("select_doc", %{"name" => name}, socket) do
socket = ExTauri.Window.set_title(socket, "#{name} — MyApp")
{:noreply, assign(socket, :doc, name)}
end
# Toggle fullscreen from a button
def handle_event("toggle_fullscreen", _params, socket) do
fullscreen? = !socket.assigns.fullscreen
socket = ExTauri.Window.set_fullscreen(socket, fullscreen?)
{:noreply, assign(socket, :fullscreen, fullscreen?)}
end
# Query window state
def handle_event("check_window", _params, socket) do
{:noreply, ExTauri.Window.info(socket)}
end
def handle_event("tauri_response", %{"command" => "window", "title" => _} = params, socket) do
{:noreply, assign(socket, :window_info, params)}
end
Summary
Functions
Centers the window on the current monitor.
Closes a window previously opened with open/5, by label.
Brings the window to the front and focuses it.
Hides the window (it keeps running; use show/1 to bring it back).
Requests the current window state.
Maximizes the window.
Minimizes the window.
Opens a new window rendering the given path of your Phoenix app.
Keeps the window above all others (or stops doing so).
Enters or leaves fullscreen.
Allows or prevents window resizing.
Resizes the window to the given logical width and height (pixels).
Sets the window title.
Shows a previously hidden window.
Starts dragging the window, for custom titlebars.
Toggles between maximized and windowed state.
Restores the window from the maximized state.
Functions
Centers the window on the current monitor.
Closes a window previously opened with open/5, by label.
Brings the window to the front and focuses it.
Hides the window (it keeps running; use show/1 to bring it back).
Requests the current window state.
The result arrives as a "tauri_response" event with %{"command" => "window", "title" => ..., "is_maximized" => ..., "is_minimized" => ..., "is_fullscreen" => ..., "is_focused" => ..., "scale_factor" => ...}.
Maximizes the window.
Minimizes the window.
Opens a new window rendering the given path of your Phoenix app.
The label uniquely identifies the window (used by close/3). path is
resolved against the app's origin (e.g. "/settings").
Options
:title- Window title:width/:height- Initial logical size (both required to apply):resizable- Allow resizing (default: true)
Examples
ExTauri.Window.open(socket, "settings", "/settings", title: "Settings", width: 500, height: 400)
Keeps the window above all others (or stops doing so).
Enters or leaves fullscreen.
Allows or prevents window resizing.
Resizes the window to the given logical width and height (pixels).
Sets the window title.
Shows a previously hidden window.
Starts dragging the window, for custom titlebars.
Call this from a phx-click (or mousedown-driven event) on your custom
titlebar element to let users move a window with no native decorations.
Toggles between maximized and windowed state.
Restores the window from the maximized state.