#on `yarn tauri dev` multiple application starts and do not stops the dev server on closing the app.

57 messages Β· Page 1 of 1 (latest)

burnt wren
#

I don't know what happen suddenly and my application is running multiple apps on yarn tauri dev. sometimes 3 to 4 windows appears. i deleted the node modules and all target file still the same.

modest hare
#

Gonna need to share some code for this one (mainly your Rust code) and the output of tauri info

burnt wren
#

@modest hare

#

@modest hare

#

i don't know if the codding structure is okay ..

#

it was working fine earlier. I think after migration something changed .

#

i tried undo things but didn't work for me

modest hare
#

Other than that the code is a liiiiittle funky, I dont see anything wrong that should cause the issue you're experiencing

burnt wren
#

@modest hare πŸ˜… could you tell me why do you think the code to be funky

modest hare
#
  1. You dont handle an option result properly, meaning that in the rare case it does return None your app will crash (unwrapping is almost never the right choice unless you've first verified the result isnt None)
  2. You clone the path into a variable instead of either & borrowing it or cloning when it's used so it can be dropped earlier, suggesting you might wanna take another gander at how the ownership system works

So nothing major and wont fix anything, just like, relatively minor code quality things πŸ™‚

burnt wren
#

@modest hare understood. Completely new to rust. I have understanding issue and need more time to sync. I learn by creating small task. I work on the above said ...

#

thank you simen

#

but the issue persist i don't know why there is multiple app running

modest hare
#

Yea I'm not sure why it does that either, your code shouldnt cause that behavior. You can enable more verbose output from the dev command to try to find the cause, dev -v

burnt wren
#

cool. Simen is there anyways connect with you directly or add you to my friend list so that i can keep on taking tips and lessons πŸ˜…

modest hare
#

I prefer poking me on the server πŸ˜… If you post something in support you can just @ me and I'll come running πŸ™‚

covert canyon
#

also someone can chime in in case simon is unavailable. at least that's what i always tell the people in my DMs but nobody wanna listen kkushKEKW

covert canyon
#

also simon's --verbose tip could really give us a hint

#

and lastly did you try commenting out the migration code to see if it's in any way related? (same for other parts of your app maybe)

burnt wren
#

tauri.config.json

{
  "$schema": "../node_modules/@tauri-apps/cli/schema.json",
  "build": {
    "beforeBuildCommand": "yarn build",
    "beforeDevCommand": "yarn dev",
    "devPath": "http://localhost:1420",
    "distDir": "../dist"
  },
  "package": {
    "productName": "accessbuddy",
    "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": "com.accessbuddyapp.AppData",
      "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,
        "height": 600,
        "resizable": true,
        "title": "AccessBuddy",
        "width": 800
      }
    ]
  }
}

#

Yes I tried commenting out the migrations.

covert canyon
# burnt wren

okay at least we know now that it's not tauri's dev watcher x)

burnt wren
#

I think the middleware setup is making the problem .. it is running even after the application is closed

#

after a good sleep i ran the code and after i comment the setup part its terminating the dev server instantly ... otherwise it halts afte the application closed and i do ctrl + c to close .. otherwise a ctrl + s bring the app ui again ...

#

do tauri keeps cache ??

covert canyon
#

or only the "script" section is enough

burnt wren
#

"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri",
"prepare": "husky install",
"lint": "eslint --max-warnings 0",
"reformat-code": "prettier --write .",
"pre-commit": "",
"commit": "",
"test":""

covert canyon
#

hmm looks good

burnt wren
#

"dependencies": {
"@tauri-apps/api": "^1.2.0",
"axios": "^1.3.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zustand": "^4.3.3"
},
"devDependencies": {
"@tauri-apps/cli": "^1.2.3",
"@types/node": "^18.14.1",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react-swc": "^3.0.0",
"autoprefixer": "^10.4.13",
"eslint": "^8.34.0",
"husky": "^8.0.0",
"postcss": "^8.4.21",
"prettier": "^2.8.4",
"tailwindcss": "^3.2.7",
"typescript": "^4.9.3",
"vite": "^4.1.0"
}

covert canyon
#

i'm at a loss to be honest

#

is your project public by any chance?

burnt wren
#

nops

#

aaah ..ya i can share

#

Its just a practice code .

#

i will push to git ..

covert canyon
#

you can share it via a zip in a dm too if you don't want to leak it publicly

burnt wren
#

tauri::Builder::default().setup(|app|{
let path = app.path_resolver().app_data_dir();
let path2 = path.clone();

if Path::new(& format!("{}{}", path.unwrap().to_string_lossy(), "/msspl-store-ab.sqlite")).exists(){
  print!("Database already exists. No database migration.");
} 
else {
  let mut conn = establish_connection(format!("{}{}", path2.unwrap().to_string_lossy(), "/msspl-store-ab.sqlite"));
  run_migrations(&mut conn).expect("Error migration");
  print!("Database not found. Running database migration.");     <-------- its halting over here on closing the app
}
Ok(())

})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

burnt wren
#

here we go.

#

and it seems like the build do not create any db to windows and linux

#

but the app runs

#

is there any ways to keep the database centralise from env file ?

establish_connection( ###db_env_path### ); for macos windows linux

#

on a specific folder .

#

@modest hare

burnt wren
#

is there any ways i can create a db for windows ,linux and macs before tauri::builder().setup()...

#

let mut conn = establish_connection(format!("{}{}", path.unwrap().to_string_lossy(), "/msspl-store-ab.sqlite")); I want to make this database centralise from env file

#

the path_resolver().app_data_dir() doesn't give me full path before the tauri setup ..

modest hare
#

Why do you need it before Tauri runs?

#

The setup function runs before Tauri runs, just that you have access to e.g. the path resolver

burnt wren
modest hare
#

Just manage it in the setup function then
https://docs.rs/tauri/1.2.4/tauri/trait.Manager.html#method.manage

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::Manager;
struct MyState(String);
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str, state: tauri::State<MyState>) -> String {
    format!("Hello, {name}! {}", state.0)
}
fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![greet])
        .setup(|app| {
            app.manage(MyState("some state value".into()));
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
modest hare
#

And just to be clear there's 0 performance loss or anything like that from running it from within the setup function. The setup function runs before Tauri starts running, you can do basically anything inside it that you can do outside of it

burnt wren
#

@modest hare cool.. worked out for me.