#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)
Gonna need to share some code for this one (mainly your Rust code) and the output of tauri info
@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
Other than that the code is a liiiiittle funky, I dont see anything wrong that should cause the issue you're experiencing
@modest hare π could you tell me why do you think the code to be funky
- 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)
- 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 π
@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
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
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 π
I prefer poking me on the server π If you post something in support you can just @ me and I'll come running π
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 
can you share these 2 things:
- your tauri.conf.json file or at least the beforeDevCommand and beforeBuildCommand from the top
- the scripts section of your package.json file
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)
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.
okay at least we know now that it's not tauri's dev watcher x)
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 ??
that sounds super weird, can you share your package.json too?
or only the "script" section is enough
"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":""
hmm looks good
"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"
}
you can share it via a zip in a dm too if you don't want to leak it publicly
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");
}
here we go.
@covert canyon
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
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 ..
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
@modest hare what is actually want to do is this https://github.com/AviKKi/tauri-demo/blob/main/src-tauri/src/main.rs
now if you have notice my connection is taking place from App directory and i need to send this connection to all function like let con = state.conn.lock().unwrap();
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");
}
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
@modest hare cool.. worked out for me.