#Rendering binary running on localhost:4000 from Tauri window

12 messages · Page 1 of 1 (latest)

mellow furnace
#

Hello!

I'm new to Tauri and trying something off the golden path (I think).

Put simply, I have a binary that, when executed, runs a server on localhost:4000. This binary contains all of the logic for rendering a web view (Elixir Phoenix LiveView).

I'd like to leverage Tauri to deploy this app natively. The way I was thinking of doing this was by doing the following:

  1. Packaging the binary into Tauri via either external_binaries or resources– so far I have only gotten the server to run by using resources and launching the binary via a child process in main.rs
  2. Pointing the window launcher to localhost:4000.
  3. Setting up event listeners to kill the server if the window is killed.

I am able to do step 1 above. However, I am having trouble getting the window launcher to render the content coming from localhost:4000. Attached is my main.rs and my Tauri config.

Any ideas would be helpful here– thanks for taking a look!

midnight harbor
#

I am able to do step 1 above. However, I am having trouble getting the window launcher to render the content coming from localhost:4000. Attached is my main.rs and my Tauri config.
In what way does it not work?

#

Or maybe try just /index.html or something as the window url since you set devPath and frontendDist to the correct url already.

mellow furnace
#

Hello! Thanks for the quick response.

What I see is that the server child process runs, and the tauri app is loaded, but no tauri app window is loaded (i.e. when I click on the tauri icon in my macos dock, nothing happens)

Looking at my logs, I see the following error:

Failed to create window: a window with label `main` already exists

This is after I tried what you suggested by doing the following:

// Create the window after waiting
let window = tauri::WindowBuilder::new(
    &app_handle,
    "main",
    tauri::WindowUrl::App("index.html".into()),
)
.build();
midnight harbor
#

Failed to create window: a window with label main already exists
Ah that makes sense then. The window you configured in tauri.conf.json doesn't have a label set so it will use "main" which you also use in Rust. Labels must be unique though.

mellow furnace
#

oh that worked!!! Thank you!!! Can you help me to understand what is happening? Namely

  1. What happens to the "main" window that tauri.config.json specifies? Is it just not rendered?
  2. Which bits of my main.rs and config are redundant? I tried many things to get to this place, and I'm not sure that I have the most concise setup I could have 😅
midnight harbor
#

What happens to the "main" window that tauri.config.json specifies? Is it just not rendered?
You have visible: false so it exists but it's just not display on the screen.

Which bits of my main.rs and config are redundant? I tried many things to get to this place, and I'm not sure that I have the most concise setup I could have 😅
If the index.html url worked, the whole let window block and the windows config (the one containing the array of window configs, not bundle.windows the config for the OS specific stuff) do the same thing. That's the only redunancy i see rn

mellow furnace
#

Got it, thank you so much.

OOC is there a Tauri best practice I should follow for killing the child server process when quitting the app? Right now it seems when I kill the Tauri app, the server lingers on localhost:4000 until I manually kill it

midnight harbor
#

Maybe try listening to RunEvent::ExitRequested or Exit instead of window events.

#

That should catch a bit more cases.

#

But you can only catch 100% of all cases by also checking inside your sidecar if the parent app is still alive. There's always some way to ungracefully kill the tauri app in a way that doesn't trigger the exit events.

mellow furnace
#

that's an interesting idea– what's the recommend interface to health check the tauri app? Maybe a port it uses that I might be able to ping?