ExTauri.LiveView (ex_tauri v0.2.0)
View SourceCallback-style responses for Tauri commands — use this in your LiveViews.
Without this module, every Tauri result arrives as a raw
handle_event("tauri_response", ...) that you pattern-match by hand. With it,
you pass a callback where you issue the command and ExTauri routes the
response back to it:
defmodule MyAppWeb.HomeLive do
use MyAppWeb, :live_view
use ExTauri.LiveView
def handle_event("pick_file", _params, socket) do
socket =
ExTauri.Dialog.open(socket, [title: "Pick a file"], fn
{:ok, %{"path" => path}}, socket -> assign(socket, :file, path)
{:error, _reason}, socket -> put_flash(socket, :error, "No file selected")
end)
{:noreply, socket}
end
enduse ExTauri.LiveView attaches a handle_event hook (via
Phoenix.LiveView.attach_hook/4) that intercepts "tauri_response",
"tauri_error", and "tauri_event" and dispatches them:
- Reply callbacks (the optional last argument on every ExTauri API
function) are one-shot: invoked once with
{:ok, payload}or{:error, reason}, then removed. - Event handlers (the optional last argument to
ExTauri.Event.subscribe/3andExTauri.GlobalShortcut.register/3) are persistent: invoked with(payload, socket)on every occurrence until unsubscribed/unregistered. - Anything without a registered callback falls through to your own
handle_event/3clauses, so manual handling keeps working.
Callbacks receive the socket and must return the socket.
If you prefer not to use this module (e.g. you need custom mount ordering),
attach manually in mount/3:
def mount(_params, _session, socket) do
{:ok, ExTauri.LiveView.attach(socket)}
end
Summary
Functions
Attaches the ExTauri response router to the socket.