Skip to content

Commit d1ff1a4

Browse files
authored
Add ElixirKit guide: Building Desktop Apps with Tauri (#3175)
1 parent eccc593 commit d1ff1a4

25 files changed

Lines changed: 903 additions & 312 deletions

File tree

elixirkit_next/config/config.exs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ import Config
22

33
if config_env() == :dev do
44
config :makeup_syntect,
5-
register_for_languages: ["rust"]
5+
register_for_languages: [
6+
"diff",
7+
"rust",
8+
"xml",
9+
"yaml"
10+
]
611
end

elixirkit_next/examples/tauri_project/.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ example-*.tar
2727

2828
# Ignore assets that are produced by build tools.
2929
/priv/static/assets/
30-
31-
# Ignore digested/compressed files produced by mix phx.digest.
32-
/priv/static/cache_manifest.json
3330
/priv/static/**/*.gz
3431
/priv/static/*.gz
3532
/priv/static/*-[0-9a-f]*.*
3633
/priv/static/**/*-[0-9a-f]*.*
3734

35+
# Ignore digested assets cache.
36+
/priv/static/cache_manifest.json
37+
3838
# In case you use Node.js/npm, you want to ignore these.
3939
npm-debug.log
4040
/assets/node_modules/

elixirkit_next/examples/tauri_project/.vscode/extensions.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

elixirkit_next/examples/tauri_project/config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ config :example, ExampleWeb.Endpoint,
1919
layout: false
2020
],
2121
pubsub_server: Example.PubSub,
22-
live_view: [signing_salt: "oXRpVA22"]
22+
live_view: [signing_salt: "h+72aWPG"]
2323

2424
# Configure the mailer
2525
#

elixirkit_next/examples/tauri_project/config/dev.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ config :example, ExampleWeb.Endpoint,
1313
check_origin: false,
1414
code_reloader: true,
1515
debug_errors: true,
16-
secret_key_base: "Y6kTWU/bE59+vfA1I5WZr/E/ebgKrviJL4zVOvdePufDSDdTZN2Y+hXhXh/FI3jc",
16+
secret_key_base: "M7pWo8R2zBsZZ3VB6rxl5ic2xyf40SdhoM+XxGftFrlU0UrnARhBNLoeioGbysYq",
1717
watchers: [
1818
esbuild: {Esbuild, :install_and_run, [:example, ~w(--sourcemap=inline --watch)]},
1919
tailwind: {Tailwind, :install_and_run, [:example, ~w(--watch)]}

elixirkit_next/examples/tauri_project/config/prod.exs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
import Config
22

3+
# Note we also include the path to a cache manifest
4+
# containing the digested version of static files. This
5+
# manifest is generated by the `mix assets.deploy` task,
6+
# which you should run after static files are built and
7+
# before starting your production server.
8+
config :example, ExampleWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
9+
10+
# Force using SSL in production. This also sets the "strict-security-transport" header,
11+
# known as HSTS. If you have a health check endpoint, you may want to exclude it below.
12+
# Note `:force_ssl` is required to be set at compile-time.
313
config :example, ExampleWeb.Endpoint,
4-
cache_static_manifest: "priv/static/cache_manifest.json",
5-
check_origin: false
14+
force_ssl: [
15+
rewrite_on: [:x_forwarded_proto],
16+
exclude: [
17+
# paths: ["/health"],
18+
hosts: ["localhost", "127.0.0.1"]
19+
]
20+
]
621

22+
# Configure Swoosh API Client
723
config :swoosh, api_client: Swoosh.ApiClient.Req
824

25+
# Disable Swoosh Local Memory Storage
26+
config :swoosh, local: false
27+
928
# Do not print debug messages in production
1029
config :logger, level: :info
1130

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,103 @@
11
import Config
22

3+
# config/runtime.exs is executed for all environments, including
4+
# during releases. It is executed after compilation and before the
5+
# system starts, so it is typically used to load production configuration
6+
# and secrets from environment variables or elsewhere. Do not define
7+
# any compile-time configuration in here, as it won't be applied.
8+
# The block below contains prod specific runtime configuration.
9+
10+
# ## Using releases
11+
#
12+
# If you use `mix release`, you need to explicitly enable the server
13+
# by passing the PHX_SERVER=true when you start it:
14+
#
15+
# PHX_SERVER=true bin/example start
16+
#
17+
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18+
# script that automatically sets the env var above.
319
if System.get_env("PHX_SERVER") do
420
config :example, ExampleWeb.Endpoint, server: true
521
end
622

723
config :example, ExampleWeb.Endpoint,
8-
http: [ip: {127, 0, 0, 1}, port: String.to_integer(System.get_env("PORT", "4000"))]
24+
http: [port: String.to_integer(System.get_env("PORT", "4000"))]
925

1026
if config_env() == :prod do
27+
# The secret key base is used to sign/encrypt cookies and other secrets.
28+
# A default value is used in config/dev.exs and config/test.exs but you
29+
# want to use a different value for prod and you most likely don't want
30+
# to check this value into version control, so we use an environment
31+
# variable instead.
1132
secret_key_base =
1233
System.get_env("SECRET_KEY_BASE") ||
13-
raise "environment variable SECRET_KEY_BASE is missing"
34+
raise """
35+
environment variable SECRET_KEY_BASE is missing.
36+
You can generate one by calling: mix phx.gen.secret
37+
"""
38+
39+
host = System.get_env("PHX_HOST") || "example.com"
40+
41+
config :example, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
1442

1543
config :example, ExampleWeb.Endpoint,
16-
url: [host: "127.0.0.1"],
44+
url: [host: host, port: 443, scheme: "https"],
45+
http: [
46+
# Enable IPv6 and bind on all interfaces.
47+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
48+
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
49+
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
50+
ip: {0, 0, 0, 0, 0, 0, 0, 0}
51+
],
1752
secret_key_base: secret_key_base
53+
54+
# ## SSL Support
55+
#
56+
# To get SSL working, you will need to add the `https` key
57+
# to your endpoint configuration:
58+
#
59+
# config :example, ExampleWeb.Endpoint,
60+
# https: [
61+
# ...,
62+
# port: 443,
63+
# cipher_suite: :strong,
64+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
65+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
66+
# ]
67+
#
68+
# The `cipher_suite` is set to `:strong` to support only the
69+
# latest and more secure SSL ciphers. This means old browsers
70+
# and clients may not be supported. You can set it to
71+
# `:compatible` for wider support.
72+
#
73+
# `:keyfile` and `:certfile` expect an absolute path to the key
74+
# and cert in disk or a relative path inside priv, for example
75+
# "priv/ssl/server.key". For all supported SSL configuration
76+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
77+
#
78+
# We also recommend setting `force_ssl` in your config/prod.exs,
79+
# ensuring no data is ever sent via http, always redirecting to https:
80+
#
81+
# config :example, ExampleWeb.Endpoint,
82+
# force_ssl: [hsts: true]
83+
#
84+
# Check `Plug.SSL` for all available options in `force_ssl`.
85+
86+
# ## Configuring the mailer
87+
#
88+
# In production you need to configure the mailer to use a different adapter.
89+
# Here is an example configuration for Mailgun:
90+
#
91+
# config :example, Example.Mailer,
92+
# adapter: Swoosh.Adapters.Mailgun,
93+
# api_key: System.get_env("MAILGUN_API_KEY"),
94+
# domain: System.get_env("MAILGUN_DOMAIN")
95+
#
96+
# Most non-SMTP adapters require an API client. Swoosh supports Req, Hackney,
97+
# and Finch out-of-the-box. This configuration is typically done at
98+
# compile-time in your config/prod.exs:
99+
#
100+
# config :swoosh, :api_client, Swoosh.ApiClient.Req
101+
#
102+
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
18103
end

elixirkit_next/examples/tauri_project/config/test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Config
44
# you can enable the server option below.
55
config :example, ExampleWeb.Endpoint,
66
http: [ip: {127, 0, 0, 1}, port: 4002],
7-
secret_key_base: "fAeNvpnkRZcRGZTKjDpfxi7BdHNadLZO0ylQKN3gfGpipW3OcTD3hKJjf4T+O3UV",
7+
secret_key_base: "HfJYxZzxfb7+BKbFw1Q7RlZSlVBnS/lNIXtErXWzY7lncRSQHwOw8oPh1OQuom+V",
88
server: false
99

1010
# In test we don't send emails

elixirkit_next/examples/tauri_project/lib/example/application.ex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
defmodule Example.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
24
@moduledoc false
35

46
use Application
57

68
@impl true
79
def start(_type, _args) do
10+
pubsub = System.get_env("ELIXIRKIT_PUBSUB")
11+
812
children = [
913
ExampleWeb.Telemetry,
14+
{DNSCluster, query: Application.get_env(:example, :dns_cluster_query) || :ignore},
1015
{Phoenix.PubSub, name: Example.PubSub},
11-
{ElixirKit.PubSub,
12-
connect: System.get_env("ELIXIRKIT_PUBSUB") || :ignore,
13-
on_exit: fn -> System.stop() end},
16+
# Start a worker by calling: Example.Worker.start_link(arg)
17+
# {Example.Worker, arg},
18+
# Start to serve requests, typically the last entry
19+
{ElixirKit.PubSub, connect: pubsub || :ignore, on_exit: fn -> System.stop() end},
1420
ExampleWeb.Endpoint,
1521
{Task,
1622
fn ->
17-
ElixirKit.PubSub.broadcast("messages", "ready")
23+
if pubsub do
24+
ElixirKit.PubSub.broadcast("messages", "ready")
25+
end
1826
end}
1927
]
2028

29+
# See https://hexdocs.pm/elixir/Supervisor.html
30+
# for other strategies and supported options
2131
opts = [strategy: :one_for_one, name: Example.Supervisor]
2232
Supervisor.start_link(children, opts)
2333
end
2434

35+
# Tell Phoenix to update the endpoint configuration
36+
# whenever the application is updated.
2537
@impl true
2638
def config_change(changed, _new, removed) do
2739
ExampleWeb.Endpoint.config_change(changed, removed)

elixirkit_next/examples/tauri_project/lib/example_web/endpoint.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule ExampleWeb.Endpoint do
77
@session_options [
88
store: :cookie,
99
key: "_example_key",
10-
signing_salt: "5+Y3I5/r",
10+
signing_salt: "F0V0qjLQ",
1111
same_site: "Lax"
1212
]
1313

0 commit comments

Comments
 (0)