tauri icon indicating copy to clipboard operation
tauri copied to clipboard

Use with OTP/Elixir, and specifically Phoenix LiveView

Open mayel opened this issue 3 years ago • 21 comments

Is your feature request related to a problem? Please describe.

Glad to see a solid alternative to Electron! While Rust is a great choice (though I am currently building apps in Elixir) I much prefer not using JS-heavy frameworks like React and instead use Phoenix's LiveView to build SPA apps driven by the backend.

Describe the solution you'd like

I'd love see what it would take to bundle OTP and an Elixir and LiveView-based app using Tauri.

Describe alternatives you've considered

Bakeware is a step in the right direction, and could maybe be combined with Tauri for these purposes.

mayel avatar Feb 21 '21 20:02 mayel

Hmm, it might be interesting to do this. Really, would just need to use bakeware or elixirscript and then sideload the pheonix/elixir binary with the Tauri app to produce a binary containing both. The main difference here between a live view style app and something more traditional, is that you have this server in between, feeding the rendered HTML into the Tauri WebView through the phoenix channel.

The other side of this is that you would likely have to use an embeddable database if you planned to still use ecto. You wouldn't be able to package postgres with the phoenix app.

tensor-programming avatar Feb 21 '21 20:02 tensor-programming

Glad to hear it seems straightforward! I just saw embedding binaries is already supported, so I guess we'd mostly need a third app loading mode to load the Elixir app's port.

[off topic @tensor-programming you may be interested in this if you haven't seen t yet]

mayel avatar Feb 21 '21 21:02 mayel

We should probably work to make this possible with a Tauri plugin.

lucasfernog avatar Feb 21 '21 21:02 lucasfernog

Here is an example of a Tauri app that spawns a binary that starts a server and then navigates the webview to that url.

nklayman avatar Feb 21 '21 21:02 nklayman

You should also consider looking for an embeddable database to replace Postgres for your project: good news, we have an SQLite plugin!

Laegel avatar Feb 21 '21 21:02 Laegel

The other side of this is that you would likely have to use an embeddable database if you planned to still use ecto. You wouldn't be able to package postgres with the phoenix app.

Yeah that was at the back of my mind... Postgres can do silent installs on Windows, and there's an app bundle for OSX (and Linux users are used to and usually know how to jump through a few more hoops) but I guess users would have to set that up separately?

mayel avatar Feb 21 '21 21:02 mayel

You should also consider looking for an embeddable database to replace Postgres for your project: good news, we have an SQLite plugin!

While that may suit a lot of projects, some apps use things like JSONB fields, Postgis, or other features that would at the very least require rewrites and at worst loose important functionality (not to mention performance).

mayel avatar Feb 21 '21 21:02 mayel

@mayel yeah, am aware of Nx. Yet another really cool idea out of the elixir scene.

I am looking at building a LiveView example right now just to see whats possible and where the potential bottle necks are. And I wonder what kind of benefits you would get from this kind of setup.

tensor-programming avatar Feb 21 '21 21:02 tensor-programming

@tensor-programming no pressure, but wondering what you discovered if you got around to playing with this?

mayel avatar Mar 10 '21 21:03 mayel

+1 on being excited about the possibility of running a phoenix app on a desktop and mobile 🤞

@tensor-programming here are some projects doing somewhat similar things

And any news on this?

  • https://github.com/elixir-desktop
  • https://github.com/lumen/lumen
  • https://github.com/bake-bake-bake/bakeware
  • https://elixirforum.com/t/best-option-to-do-desktop-apps-in-elixir/36835

jonericcook avatar Dec 22 '21 22:12 jonericcook

another cool project that could be useful? https://github.com/burrito-elixir/burrito

jonericcook avatar Dec 27 '21 06:12 jonericcook

very curious to see examples of tauri apps with elixir!

gotjoshua avatar Apr 12 '22 13:04 gotjoshua

One of the (only?) concerns with rustler Nifs is that you won't be able to handle extreme crashes...

https://news.ycombinator.com/item?id=31023587

nothingismagick avatar Apr 25 '22 12:04 nothingismagick

A neat use case for this would be to ship an elixir binary as a sidecar and use phoenix channels and websocket listeners in the webview (or just place liveviews in the webview too). I would expect this to literally work right out of the box.

nothingismagick avatar Apr 25 '22 12:04 nothingismagick

No to Typescript. Prefer just Liveview but doesn't seem to be a way to call Taurus API from Liveview?

heri16 avatar Apr 25 '22 12:04 heri16

Liveview is really AFAIK SSR HTML passed to Tauri via websockets. So you HAVE to place the liveview into the webview somehow and that means integrating a websocket.

image

nothingismagick avatar Apr 25 '22 13:04 nothingismagick

But we haven't experimented with how you would interact with the API in this way, but it is interesting for sure.

nothingismagick avatar Apr 25 '22 13:04 nothingismagick

I make a demo project for this lookup here: https://github.com/feng19/phx_new_desktop

feng19 avatar Mar 29 '23 16:03 feng19

@feng19 thanks for sharing, this repo is super helpful!

I notice you're calling out to rust/tauri from within javascript (i.e. client-side, if this was a web app). Is it possible to interface with tauri from within Elixir? There is a rust API as well as JS, so not sure if this is possible from within a Rust NIF in Elixir.

chris838 avatar Jan 09 '24 09:01 chris838

@feng19 thanks for sharing, this repo is super helpful!

I notice you're calling out to rust/tauri from within javascript (i.e. client-side, if this was a web app). Is it possible to interface with tauri from within Elixir? There is a rust API as well as JS, so not sure if this is possible from within a Rust NIF in Elixir.

Erlang VM and Tauri are separate processes, there is no ready-made interface, maybe you can have a try.

feng19 avatar Jan 10 '24 02:01 feng19

I am working in this fork to improve ex_tauri from @filipecabaco , but the most challenging part is not being able to cross compile from Linux to other platfroms, and not be able to use Tauri actions to compile an actual release that works on Linux, but I can compile on locally that runs fine :). Eventually some day I will manage to get this to work ;)

Exadra37 avatar Apr 18 '24 07:04 Exadra37