From 2f961750a8c8d628cd5819615aaad2a4dfe0866e Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Tue, 7 Oct 2025 21:55:14 +0200 Subject: [PATCH] [WIP] Crude changes to support liveview 1.x Requires phoenix 1.7.10 and liveview 1.x. - sigil_e is deprecated - Module.eval_quoted is deprecated --- lib/desktop/endpoint.ex | 14 +++----------- lib/desktop/menu.ex | 20 +++++++++----------- lib/desktop/wx.ex | 8 +++++--- mix.exs | 4 ++-- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/lib/desktop/endpoint.ex b/lib/desktop/endpoint.ex index 0dcb3fd..5f6fd80 100644 --- a/lib/desktop/endpoint.ex +++ b/lib/desktop/endpoint.ex @@ -17,17 +17,9 @@ defmodule Desktop.Endpoint do end end - if Version.match?(:phoenix |> Application.spec(:vsn) |> List.to_string(), "~> 1.7.10") do - def get_dynamic_port(scheme) do - {:ok, {_ip, port}} = server_info(scheme) - port - end - else - # Supports only cowboy adapter for phoenix - def get_dynamic_port(scheme) do - ref = Module.safe_concat(__MODULE__, scheme |> Atom.to_string() |> String.upcase()) - :ranch.get_port(ref) - end + def get_dynamic_port(scheme) do + {:ok, {_ip, port}} = server_info(scheme) + port end end end diff --git a/lib/desktop/menu.ex b/lib/desktop/menu.ex index 2f47ffa..2d098f6 100644 --- a/lib/desktop/menu.ex +++ b/lib/desktop/menu.ex @@ -28,21 +28,21 @@ defmodule Desktop.Menu do @impl true def render(assigns) do - ~E\""" + ~H\""" - "> - <%= gettext "Open" %> + + {gettext "Open"}
- <%= gettext "Quit" %> + {gettext "Quit"}
- "> + <%= for item <- @items do %> - <%= item.name %> + {item.name} <% end %> - "> - <%= gettext "Show Documentation" %> - <%= gettext "About" %> + + {gettext "Show Documentation"} + {gettext "About"} \""" @@ -143,7 +143,6 @@ defmodule Desktop.Menu do quote do @behaviour Desktop.Menu import Desktop.Menu, only: [assign: 2, assign: 3, assign_new: 3, connected?: 1] - import Phoenix.HTML, only: [sigil_e: 2, sigil_E: 2] import Phoenix.LiveView.Helpers, only: [sigil_L: 2, sigil_H: 2] alias Desktop.Menu @@ -153,7 +152,6 @@ defmodule Desktop.Menu do quote do @behaviour Desktop.Menu import Desktop.Menu, only: [assign: 2, assign: 3, assign_new: 3, connected?: 1] - import Phoenix.HTML, only: [sigil_e: 2, sigil_E: 2] import Phoenix.LiveView.Helpers, only: [sigil_L: 2] import Phoenix.Component, only: [sigil_H: 2] alias Desktop.Menu diff --git a/lib/desktop/wx.ex b/lib/desktop/wx.ex index df01166..a4eebc6 100644 --- a/lib/desktop/wx.ex +++ b/lib/desktop/wx.ex @@ -1,3 +1,4 @@ +# TODO: less stringy metaprogramming defmodule Desktop.Wx do @moduledoc """ Elixir version of the constants found in the wx.hrl file, reduced to what is needed in this sample only. @@ -25,11 +26,12 @@ defmodule Desktop.Wx do ) for wx_constant <- @constants do - Module.eval_quoted( - __MODULE__, + Code.eval_quoted( Code.string_to_quoted(""" def wx#{wx_constant}, do: :desktop_wx.get(:wx#{wx_constant}) - """) + """), + [], + module: __MODULE__ ) end end diff --git a/mix.exs b/mix.exs index d39a228..8a7b2e7 100644 --- a/mix.exs +++ b/mix.exs @@ -83,8 +83,8 @@ defmodule Desktop.MixProject do # {:ex_sni, path: "../ex_sni"}, # Phoenix & Plug - {:phoenix, "> 1.0.0"}, - {:phoenix_live_view, "> 0.15.0"}, + {:phoenix, "> 1.7.10"}, + {:phoenix_live_view, "> 1.0.0"}, {:plug, "> 1.0.0"}, {:gettext, "> 0.10.0"} ]