defmodule LiveDebuggerWeb.SettingsLive do @moduledoc """ LiveView for the settings page. """ use LiveDebuggerWeb, :live_view alias LiveDebugger.GenServers.CallbackTracingServer alias LiveDebugger.GenServers.SettingsServer alias LiveDebuggerWeb.Components.Navbar alias LiveDebuggerWeb.Helpers.RoutesHelper @impl true def handle_params(params, _url, socket) do socket |> assign(:return_to, params["return_to"]) |> assign_settings() |> noreply() end @impl true def render(assigns) do ~H"""
<.h1>Settings
<%!-- Upper section --%>
<%!-- Appearance --%>

Appearance

<.dark_mode_button /> <.light_mode_button />
<%!-- Checkboxes --%>
<.settings_switch id="dead-view-mode-switch" label="Enable DeadView mode" description="When enabled, LiveDebugger won't redirect to new LiveView after page redirect or reload, allowing you to browse assigns and traces of dead LiveViews." checked={@settings[:dead_view_mode]} phx-click="update" phx-value-setting="dead_view_mode" /> <.settings_switch id="tracing-update-on-reload-switch" label="Refresh tracing after recompilation" description="Tracing in LiveDebugger may be interrupted when modules are recompiled. With this option enabled, LiveDebugger will refresh tracing after project recompilation. It may have a negative impact on application performance." checked={@settings[:tracing_update_on_code_reload]} phx-click="update" phx-value-setting="tracing_update_on_code_reload" />
<%!-- Lower section --%>
<%!-- Refresh tracing button --%>

Refresh LiveDebugger Tracing

Manually refresh traced modules and callbacks. Use this when you don't see traces from your application.

<.button variant="secondary" phx-click="restart">Refresh Tracing
""" end @impl true def handle_event("update", %{"setting" => setting}, socket) do setting = String.to_existing_atom(setting) new_setting_value = not socket.assigns.settings[setting] SettingsServer.save(setting, new_setting_value) settings = Map.put(socket.assigns.settings, setting, new_setting_value) socket |> assign(:settings, settings) |> noreply() end @impl true def handle_event("restart", _, socket) do CallbackTracingServer.update_traced_modules() {:noreply, socket} end attr(:id, :string, required: true) attr(:label, :string, required: true) attr(:description, :string, required: true) attr(:checked, :boolean, default: false) attr(:rest, :global) defp settings_switch(assigns) do ~H"""
<.toggle_switch id={@id} checked={@checked} wrapper_class="pr-3 py-0" {@rest} />

<%= @label %>

<%= @description %>

""" end defp dark_mode_button(assigns) do ~H""" <.mode_button id="dark-mode-switch" icon="icon-moon" text="Dark" class="dark:hidden text-button-secondary-content bg-button-secondary-bg hover:bg-button-secondary-bg-hover border border-default-border" phx-hook="ToggleTheme" /> <.mode_button icon="icon-moon" text="Dark" disabled class="hidden dark:flex text-button-primary-content bg-button-primary-bg" /> """ end defp light_mode_button(assigns) do ~H""" <.mode_button id="light-mode-switch" icon="icon-sun" text="Light" class="hidden dark:flex text-button-secondary-content bg-button-secondary-bg hover:bg-button-secondary-bg-hover border border-default-border" phx-hook="ToggleTheme" /> <.mode_button icon="icon-sun" text="Light" disabled class="dark:hidden text-button-primary-content bg-button-primary-bg" /> """ end attr(:icon, :string, required: true) attr(:text, :string, required: true) attr(:class, :string, default: "") attr(:rest, :global, include: ~w(disabled)) defp mode_button(assigns) do ~H""" """ end defp assign_settings(socket) do assign(socket, :settings, SettingsServer.get_all()) end end