diff --git a/assets/js/client.js b/assets/js/client.js index 3c2d3b042..c49279e2c 100644 --- a/assets/js/client.js +++ b/assets/js/client.js @@ -18,10 +18,42 @@ function getSessionId() { } } +function handleMetaTagError() { + const message = ` + LiveDebugger meta tag not found! + If you have recently bumped LiveDebugger version, please update your layout according to the instructions in the GitHub README. + You can find it here: https://github.com/software-mansion/live-debugger#installation + `; + + throw new Error(message); +} + +function debugButtonEnabled() { + const metaTag = document.querySelector('meta[name="live-debugger-config"]'); + + if (metaTag) { + return metaTag.hasAttribute('debug-button'); + } else { + handleMetaTagError(); + } +} + +function highlightingEnabled() { + const metaTag = document.querySelector('meta[name="live-debugger-config"]'); + + if (metaTag) { + return metaTag.hasAttribute('highlighting'); + } +} + function getLiveDebuggerBaseURL() { - return document - .getElementById('live-debugger-scripts') - .src.replace('/assets/live_debugger/client.js', ''); + const metaTag = document.querySelector('meta[name="live-debugger-config"]'); + + if (metaTag) { + return metaTag.getAttribute('url'); + } else { + handleMetaTagError(); + } } function getSessionURL(baseURL) { @@ -31,20 +63,17 @@ function getSessionURL(baseURL) { return `${baseURL}/${session_path}`; } -window.getLiveDebuggerURL = function () { - const baseURL = getLiveDebuggerBaseURL(); - const sessionURL = getSessionURL(baseURL); - - return sessionURL; -}; - window.document.addEventListener('DOMContentLoaded', function () { const baseURL = getLiveDebuggerBaseURL(); const sessionURL = getSessionURL(baseURL); - initDebugButton(sessionURL); + if (debugButtonEnabled()) { + initDebugButton(sessionURL); + } - initHighlight(); + if (highlightingEnabled()) { + initHighlight(); + } // Finalize console.info(`LiveDebugger available at: ${baseURL}`); diff --git a/config/config.exs b/config/config.exs index fbb521635..a491c2389 100644 --- a/config/config.exs +++ b/config/config.exs @@ -47,9 +47,6 @@ if config_env() == :dev do ] ] - config :live_debugger, server: true - - config :live_debugger, browser_features?: true config :live_debugger, experimental_features: :all end diff --git a/dev/layout.ex b/dev/layout.ex index 72d1a6191..4f2f71939 100644 --- a/dev/layout.ex +++ b/dev/layout.ex @@ -23,10 +23,7 @@ defmodule LiveDebuggerDev.Layout do - <%= if Application.get_env(:live_debugger, :browser_features?) do %> - - <% end %> + <%= Application.get_env(:live_debugger, :live_debugger_tags) %> + <% end %> + """ + end +end diff --git a/lib/live_debugger/components/tree.ex b/lib/live_debugger/components/tree.ex index d2f234e56..22b73b2e3 100644 --- a/lib/live_debugger/components/tree.ex +++ b/lib/live_debugger/components/tree.ex @@ -33,7 +33,7 @@ defmodule LiveDebugger.Components.Tree do
<%= @title %>
- <%= if Application.get_env(:live_debugger, :browser_features?) && LiveDebugger.Feature.enabled?(:highlighting) do %> + <%= if LiveDebugger.Feature.enabled?(:highlighting) do %> <.toggle_switch label="Highlight" checked={@highlight?} phx-click="toggle-highlight" /> <% end %>
diff --git a/lib/live_debugger/feature.ex b/lib/live_debugger/feature.ex index 8a19cbcaf..80a625c2f 100644 --- a/lib/live_debugger/feature.ex +++ b/lib/live_debugger/feature.ex @@ -1,24 +1,32 @@ defmodule LiveDebugger.Feature do @moduledoc """ - Feature flags for LiveDebugger. If you create a new feature, you need to add it to the @experimental_features list. - This way we can easily find all the features that are experimental and not ready for production. + Feature flags for LiveDebugger. + If you create a new feature, create a new function here with defined rules for enabling it. """ - @experimental_features [ - :dark_mode, - :highlighting, - :callback_filters - ] + def enabled?(:highlighting) do + experimental_feature_enabled?(:highlighting) and + Application.get_env(:live_debugger, :browser_features?, true) and + Application.get_env(:live_debugger, :highlighting?, true) + end + + def enabled?(:dark_mode) do + experimental_feature_enabled?(:dark_mode) + end - def enabled?(feature_name) when feature_name in @experimental_features do + def enabled?(:callback_filters) do + experimental_feature_enabled?(:callback_filters) + end + + def enabled?(feature_name) do + raise "Feature #{feature_name} is not allowed" + end + + defp experimental_feature_enabled?(feature_name) do case Application.get_env(:live_debugger, :experimental_features, false) do :all -> true features when is_list(features) -> Enum.member?(features, feature_name) _ -> false end end - - def enabled?(feature_name) do - raise "Feature #{feature_name} is not allowed" - end end diff --git a/lib/live_debugger/live_views/sidebar_live.ex b/lib/live_debugger/live_views/sidebar_live.ex index 510e280d5..90b88b6de 100644 --- a/lib/live_debugger/live_views/sidebar_live.ex +++ b/lib/live_debugger/live_views/sidebar_live.ex @@ -82,8 +82,8 @@ defmodule LiveDebugger.LiveViews.SidebarLive do @impl true def render(assigns) do ~H""" -
-