#Stop tauri window catching focus at startup?

18 messages Β· Page 1 of 1 (latest)

opal eagle
#

Hi, I'm writing a program with tauri and SvelteKit and it's rather annoying that the window always catches focus when the app is rebuilt.
Is there an option to change that behaviour? Is it just me? Would be a nice option anyways.

But maybe my actual problem is that cargo tauri dev rebuilds the whole application when it detects frontend changes, although I'm using Vite as a frontend server (due to SvelteKit) and devPath (all as per your guide). Which seems kind of pointless. And therefore feels like I'm doing something wrong.

wise shard
#

But maybe my actual problem is that cargo tauri dev rebuilds the whole application when it detects frontend changes
That's indeed not supposed to happen

#

is your frontend inside the src-tauri dir? (or whatever dir the tauri.conf.json file is inside)

#

the cli watches the whole src-tauri dir so that's the only thing that comes to mind which could cause this

opal eagle
#

Thanks for the quick answer! πŸ™

My base project structure looks like this

#

And that's my tauri.conf.json

{
  "build": {
    "beforeBuildCommand": "pnpm run build",
    "beforeDevCommand": "pnpm run dev",
    "devPath": "http://localhost:5173/chat",
    "distDir": "../build"
  },
  "package": {
    "productName": "ChatR",
    "version": "0.1.0"
  },
  "tauri": {
    "allowlist": {
      "all": false
    },
    "bundle": {
      "active": true,
      "category": "DeveloperTool",
      "copyright": "",
      "deb": {
        "depends": []
      },
      "externalBin": [],
      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/[email protected]",
        "icons/icon.icns",
        "icons/icon.ico"
      ],
      "identifier": "at.dslan.chatr",
      "longDescription": "",
      "macOS": {
        "entitlements": null,
        "exceptionDomain": "",
        "frameworks": [],
        "providerShortName": null,
        "signingIdentity": null
      },
      "resources": [],
      "shortDescription": "",
      "targets": "all",
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "security": {
      "csp": null
    },
    "updater": {
      "active": false
    },
    "windows": [
      {
        "fullscreen": false,
        "width": 800,
        "height": 600,
        "resizable": true,
        "title": "ChatR",
        "url": "chat/"
      }
    ]
  }
}
#

I don't really see why that won't work as expected. As I followed the Getting Started guide.
Only added a custom URL for the homepage, for code semantics

wise shard
#

so if i see that right on the screenshot the answer to my question is "yes, the frontend is inside the rust project folder"? opened it on my desktop to confirm

As I followed the Getting Started guide.
Well, the guide kinda assumes that the frontend is the parent folder and the tauri folder is a child of that, so basically the other way around to what you got.

you can tell tauri to not watch your ui/ folder by adding a .taurignore file next to tauri.conf.json (it has the same syntax as a normal .gitignore file)

opal eagle
#

Doesn't the UI have to be in the ui folder for tauri to work? Or rather, is the suggested workflow with SvelteKit to develop the frontend in the browser? How would i connect to the tauri backend then?

Ah okay. So I added ui/ in the .taurignore. But now it won't start with cargo tauri dev because it says it can't find a package.json.

#

Maybe I should aks one question at a time πŸ˜…
So, if the tauri source would be inside the ui source (maybe in a back-end folder). How would that work? Didn't seem clear for me in the guide, (obv)

#

Ah, wait.

wise shard
#

Doesn't the UI have to be in the ui folder for tauri to work?
No, all tauri cares about is devPath and distDir to be configured correctly. and as i said, even the "default" order is the opposite, so it really doesn't matter.

Or rather, is the suggested workflow with SvelteKit to develop the frontend in the browser?
That won't work as soon as you use any tauri apis in the frontend

Ah okay. So I added ui/ in the .taurignore. But now it won't start with cargo tauri dev because it says it can't find a package.json.
Okay that's super annoying and didn't except that. Maybe try explciitly allowing the package.json file with something like !ui/package.json ?

opal eagle
#

That's probably why distDir: '../build' right?

wise shard
#

yeah

opal eagle
#

Ah, then i'll try re-arranging and update you. Thanks so far πŸ™

wise shard
# wise shard yeah

it's really not that strict about it. for what it's worth the frontend and tauri folders could be next to each other instead of being nested

opal eagle
#

Hello,
sorry it took me a while. Got interrupted and couldn't continue on the project yesterday.

I re-arranged to look like this:

ChatR/
β”œβ”€ src/
β”‚  β”œβ”€ lib/
β”‚  β”œβ”€ routes/
β”œβ”€ src-tauri/
β”‚  β”œβ”€ src/
β”‚  β”œβ”€ icons/
β”‚  β”œβ”€ Cargo.toml
β”‚  β”œβ”€ tauri.conf.json
β”œβ”€ static/
package.json
svelte.config.js
tsconfig.json
vite.config.js

and now get this error:

error: OUT_DIR env var is not set, do you have a build script?
  --> src\main.rs:32:14
   |
32 |         .run(tauri::generate_context!())
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `tauri::generate_context` (in Nightly builds, run with -Z macro-backtrace for more info)

Of course, the error tells me what to do. But since I only re-arranged the project and didn't change the config I assume I'm missing something I have to change there.

wise shard
#

is that the whole file tree? There used to be a build.rs file next to Cargo.toml - if you moved it to somewhere else you may have to specify that in cargo.toml idk