#How to initialize managed app state using app or its handle?

2 messages · Page 1 of 1 (latest)

forest cargo
#

On setup, I try to initialize app_data_dir. The file <app_data_dir>/paths.json is meant to persist paths managed by the app between executions.

I would like to keep the paths in the state of the app and initialize them from <app_data_dir>/paths.json when the app loads. However, tauri::Builder::manage doesn't seem to allow it.

What am I missing?

simple osprey
#

you can use this to get the context and app_data_dir right at the start of your main:

let context = tauri::generate_context!();
let mut path = tauri::api::path::app_data_dir(&context.config()).unwrap();

tauri Builder then uses this to start the app, instead of regenerating the context there:

.run(context)

you should be able to use the path to read your json and add it to the managed state.

If this didn't help, please share some code and any errors you're getting, and more precisely what you mean by "doesn't seem to allow it"