tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
81.22k stars 2.43k forks source link

[bug] building as a shared lib, app window is running in dev mode #7993

Closed doums closed 10 months ago

doums commented 10 months ago

Describe the bug

Hi, I'm working on a poc where I have to build a tauri app as a shared library (expected to be loaded and run from another app). So I build it using classic cargo build --release --lib (note the --release flag).

The thing is, when I load it and run it from another binary, also built with --release, the app window seems to run in “development mode” because it's white blank with the following error message

Could not connect: Connection refused

In my tauri.conf.json I have this (the app use vite + TS setup for frontend)

  "build": {
    "beforeDevCommand": "npm run dev",
    "beforeBuildCommand": "npm run build",
    "devPath": "http://localhost:1420",
    "distDir": "../dist",
    "withGlobalTauri": false
  },

As soon I update devPath property to use the static build assets path "../dist" it fix the issue and it works. But that corroborates my doubts: When running the app from a runner application, tauri app loaded as a shared lib (built in release mode), the window is running in dev mode and it shouldn't. Because devPath is used instead of distDir.

How can I fix this issue?

Reproduction

https://github.com/nymtech/tauri_lib

Expected behavior

No response

Platform and versions

[✔] Environment
    - OS: Arch Linux Unknown X64
    ✔ webkit2gtk-4.0: 2.42.1
    ✔ rsvg2: 2.57.0
    ✔ rustc: 1.72.1 (d5c2e9c34 2023-09-13)
    ✔ Cargo: 1.72.1 (103a7ff2e 2023-08-15)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 18.13.0
    - yarn: 1.22.19
    - npm: 8.19.3

[-] Packages
    - tauri [RUST]: 1.5.1
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.4
    - tao [RUST]: 0.16.4
    - tauri-cli [RUST]: 1.5.1
    - @tauri-apps/api [NPM]: 1.5.0
    - @tauri-apps/cli [NPM]: 1.5.1 (outdated, latest: 1.5.2)

[-] App
    - build-type: bundle
    - CSP: default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

doums commented 10 months ago

Solved using cargo build --release --lib --features custom-protocol