To convert a barebones Phoenix Live View example to a Desktop Application you will need to add this to your application:
-
Add a Desktop.Window child to your supervision tree on startup. E.g. in
application.ex
children = [{ # After your other children # Starting Desktop.Windows Desktop.Window, [ app: :your_app, id: YourAppWindow, url: &YourAppWeb.Endpoint.url/0 ] }] Supervisor.start_link()
-
In
endpoint.ex
calluse Desktop.Endpoint
instead ofuse Phoenix.Endpoint
defmodule YourAppWeb.Endpoint do use Desktop.Endpoint, otp_app: :your_app
-
In
config.exs
ensure http is configured and the port is set to0
so it's chosen automatically# Configures the endpoint config :your_app, YourAppWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 0], server: true, ...
-
For localization and to autodetect the desktop language (optional), add the detection hook to your application startup. E.g. in
application.ex
:def start(_type, args) do Desktop.identify_default_locale(YourWebApp.Gettext) children = [ ...