ExTauri.Window (ex_tauri v0.2.0)

View Source

Manage 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 TauriHook must be mounted in your LiveView (see ExTauri.Hook)

  • Window permissions in src-tauri/capabilities/default.json. Projects created by current versions of mix ex_tauri.install already 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).

Allows or prevents window resizing.

Resizes the window to the given logical width and height (pixels).

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

center(socket, on_reply \\ nil)

Centers the window on the current monitor.

close(socket, label, on_reply \\ nil)

Closes a window previously opened with open/5, by label.

focus(socket, on_reply \\ nil)

Brings the window to the front and focuses it.

hide(socket, on_reply \\ nil)

Hides the window (it keeps running; use show/1 to bring it back).

info(socket, on_reply \\ nil)

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" => ...}.

maximize(socket, on_reply \\ nil)

Maximizes the window.

minimize(socket, on_reply \\ nil)

Minimizes the window.

open(socket, label, path, opts \\ [], on_reply \\ nil)

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)

set_always_on_top(socket, on_top?, on_reply \\ nil)

Keeps the window above all others (or stops doing so).

set_fullscreen(socket, fullscreen?, on_reply \\ nil)

Enters or leaves fullscreen.

set_resizable(socket, resizable?, on_reply \\ nil)

Allows or prevents window resizing.

set_size(socket, width, height, on_reply \\ nil)

Resizes the window to the given logical width and height (pixels).

set_title(socket, title, on_reply \\ nil)

Sets the window title.

show(socket, on_reply \\ nil)

Shows a previously hidden window.

start_dragging(socket, on_reply \\ nil)

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.

toggle_maximize(socket, on_reply \\ nil)

Toggles between maximized and windowed state.

unmaximize(socket, on_reply \\ nil)

Restores the window from the maximized state.