https://github.com/avh4/elm-desktop-app
the simplest way to write desktop applications in Elm
https://github.com/avh4/elm-desktop-app
Last synced: about 1 month ago
JSON representation
the simplest way to write desktop applications in Elm
- Host: GitHub
- URL: https://github.com/avh4/elm-desktop-app
- Owner: avh4
- License: mit
- Created: 2019-05-12T02:10:18.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2020-12-17T22:00:52.000Z (over 4 years ago)
- Last Synced: 2025-03-02T14:15:37.606Z (5 months ago)
- Language: Elm
- Homepage:
- Size: 220 KB
- Stars: 47
- Watchers: 8
- Forks: 4
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/avh4/elm-desktop-app)
[][elm-package]
[][npm-package]`elm-desktop-app` is the simplest way to write desktop applications in [Elm].
It's built on top of [Electron], and it currently supports the following uses:- Your app can **persist state to disk** as a JSON file
- automatically to your end user's ["userData" directory](https://electronjs.org/docs/api/app#appgetpathname)
- to a JSON file specified by your end user
- Build and package **Mac, Linux, and Windows apps**
- (soon) prepare and publish an npm package that can launch your app from the command line[Elm]: https://elm-lang.org/
[Electron]: https://electronjs.org/
[elm-package]: https://package.elm-lang.org/packages/avh4/elm-desktop-app/latest/
[npm-package]: https://www.npmjs.com/package/elm-desktop-app## Usage
Use the [`elm-desktop-app`][npm-package] command line tool to create a new project, which includes a dependency on the [`avh4/elm-desktop-app`][elm-package] Elm pacakge and a working starting-point for you app:
```sh
npm install -g elm-desktop-appmkdir my-app
cd my-app
elm-desktop-app init
```Edit the generated `src/Main.elm` to implement your app and define how to persist data (you can see the [full example code here](https://github.com/avh4/elm-desktop-app/tree/master/example)):
```elm
import DesktopApp
import DesktopApp.JsonMapping as JsonMappingmain : DesktopApp.Program Model Msg
main =
DesktopApp.program
{ init = ( init, Cmd.none )
, update = \msg model -> ( update msg model, Cmd.none )
, subscriptions = \model -> Sub.none
, view = view
, persistence = Just persistence
}
type alias Model =
{ name : String
, count : Int
}
...
persistence : JsonMapping.ObjectMapping Model Msg
persistence =
JsonMapping.object Loaded
|> JsonMapping.with "name" .name JsonMapping.string
|> JsonMapping.with "count" .count JsonMapping.int
```Use the command line tool to run your app:
```sh
elm-desktop-app run
```
The user data for your app is automatically persisted! πΎπ
You can easily build Mac, Linux, and Windows packages (packages are built to `./elm-stuff/elm-desktop-app/app/dist/`):
```sh
elm-desktop-app package
```