-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve docs of "Your first Desktop App" * Improve README.md * Move Changelog out of README.md * Use a consistent description * Adjust the minimum version of Elixir --------- Co-authored-by: c4710n <[email protected]>
- Loading branch information
Showing
5 changed files
with
163 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Changelog | ||
|
||
## Changes in 1.5 | ||
|
||
- Support for iOS hibernation and wakeup | ||
|
||
## Changes in 1.4 | ||
|
||
- Support for `~H` sigil with `<item onclick={...}>` | ||
- Changed Menu XML escaping to LiveView automatic escaping logic from LiveView HTML tokenizer & engine. | ||
- Removed `Menu.escape_attribute/1` and `Menu.escape/1` | ||
- Dropped `:xmerl` dependency | ||
|
||
## Changes in 1.3 | ||
|
||
- Added `Env.subscribe/1` to listen to MacOS application events such as `{:open_url, url}` when a url associated with the application is clicked. | ||
- Using (experimental) dbus support to render the systray icon on linux | ||
- Added `Menu.escape_attribute/1` | ||
- Added `Window.url/1` | ||
- Added `Window.hide/1` and `Window.is_hidden/` | ||
- Fixed MacOS "Quit" menu item | ||
- Other fixes | ||
|
||
## Changes in 1.2 | ||
|
||
- Removed the bleeding edge notices because Erlang OTP 24 is now broadly available for Windows/Linux/MacOS | ||
- Added build support for iOS devices | ||
- Moved most phoenix dependencies out to allow using Phoenix 1.6 / esbuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Your first Desktop App | ||
|
||
> If you prefer to start with a working Desktop sample application, please refer to [elixir-desktop/desktop-example-app](https://github.com/elixir-desktop/desktop-example-app). | ||
## 1. Create a demo Phoenix LiveView app | ||
|
||
``` | ||
$ mix phx.new demo --no-ecto --no-dashboard --no-mailer | ||
``` | ||
|
||
After running this command, a demo Phoenix LiveView app will be created: | ||
|
||
- OTP app name is `:demo` | ||
- root module name is `Demo` | ||
- web root module name is `DemoWeb` | ||
|
||
## 2. Change above app as a Desktop app | ||
|
||
### 2.1 Add required dependency | ||
|
||
Add `desktop` package to the dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
# ... | ||
{:desktop, github: "elixir-desktop/desktop"} | ||
] | ||
end | ||
``` | ||
|
||
### 2.2 Tweak existing Phoenix endpoint | ||
|
||
```elixir | ||
defmodule DemoWeb.Endpoint do | ||
# Step 1: Change the endpoint as a `Desktop` endpoint. | ||
use Desktop.Endpoint, otp_app: :demo | ||
|
||
# ... | ||
|
||
# Step 2: Add `Desktop.Auth` plug to ensure that only requests from | ||
# the Desktop app's WebView are allowed. | ||
plug Desktop.Auth | ||
|
||
plug YourAppWeb.Router | ||
end | ||
``` | ||
|
||
### 2.3 Add child specification for opening WebView window | ||
|
||
```elixir | ||
defmodule Demo.Application do | ||
# ... | ||
|
||
def start(_type, _args) do | ||
children = [ | ||
# ... | ||
|
||
DemoWeb.Endpoint, | ||
{Desktop.Window, | ||
[ | ||
app: :demo, | ||
id: DemoWindow, | ||
url: &DemoWeb.Endpoint.url/0 | ||
]} | ||
] | ||
|
||
# ... | ||
end | ||
end | ||
``` | ||
|
||
### 2.4 Configure the Desktop endpoint | ||
|
||
> You can configure it in `config/dev.exs` or `config/runtime.exs`. | ||
``` | ||
config :demo, DemoWeb.Endpoint, | ||
# Step 1: set the port number to 0, so the port can be chosen automatically. | ||
http: [ip: {127, 0, 0, 1}, port: 0], | ||
# Step 2: start endpoint automatically, so we have no need to start it manually. | ||
server: true, | ||
# ... | ||
``` | ||
|
||
## 3. Extra Steps (optional) | ||
|
||
### 3.1 Localization support | ||
|
||
For localization and to autodetect the desktop language, desktop provides a helper function for that. You can call it before starting the app: | ||
|
||
```elixir | ||
defmodule Demo.Application do | ||
# ... | ||
|
||
def start(_type, _args) do | ||
Desktop.identify_default_locale(DemoWeb.Gettext) | ||
|
||
children = [ | ||
# ... | ||
] | ||
|
||
# ... | ||
end | ||
end | ||
``` | ||
|
||
## 4. Run it | ||
|
||
``` | ||
$ mix run | ||
``` | ||
|
||
The Desktop app should be visible now! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters