tauri-apps / tauri

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

BaseDirectory.App not set correctly in dev mode. #4616

Closed dominikj111 closed 2 years ago

dominikj111 commented 2 years ago

Describe the bug

Under dev mode pnpm tauri dev, the const contents = await readTextFile('app.conf', { dir: BaseDirectory.App }); tries to get the app.conf file from the /Users/me/Library/Application Support/com.tauri.dev/app.conf, but this location doesn't exist. On the other hand the const resourcePath = await resolveResource("app.conf"); set the resourcePath to /Users/me/my/Development/sandbox/edu/src-tauri/target/debug/app.conf what looks correct to me.

Reproduction

  1. initialize new fresh application (I did reactts with vite)
  2. use the import { readTextFile, BaseDirectory } from "@tauri-apps/api/fs"; api to read any text file

Expected behavior

I would to expect to read the text file from the folder where the actual application is.

Platform and versions

Environment
  › OS: Mac OS 12.4.0 X64
  › Node.js: 16.15.0
  › npm: 8.5.5
  › pnpm: 7.2.1
  › yarn: 1.22.19
  › rustup: 1.24.3
  › rustc: 1.62.0
  › cargo: 1.62.0
  › Rust toolchain: stable-x86_64-apple-darwin

Packages
  › @tauri-apps/cli [NPM]: 1.0.2 (outdated, latest: 1.0.3)
  › @tauri-apps/api [NPM]: 1.0.1 (outdated, latest: 1.0.2)
  › tauri [RUST]: 1.0.2,
  › tauri-build [RUST]: 1.0.2,
  › tao [RUST]: 0.12.1,
  › wry [RUST]: 0.19.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:3333/
  › framework: React

App directory structure
  ├─ resources
  ├─ node_modules
  ├─ src-tauri
  └─ src

Stack trace

No response

Additional context

No response

FabianLars commented 2 years ago

This path is correct, it is not the current working dir of the app, but our recommended path for app related configs and stuff,see https://tauri.app/v1/api/js/modules/path#appdir

dominikj111 commented 2 years ago

Ah, ok ... well my problem is that I would to load my svg files into the application and I would to have them editable without rebuilding the app. Usually (java), I have a folder with assets and providing them to the app when needed. I'm not sure what is correct way in this case.

FabianLars commented 2 years ago

Well the thing is that the location where your app is installed is most likely read-only. So you're better of just using a user data dir as your "shared" folder.