#Initializing managed state with a value that depends on PathResolver

3 messages · Page 1 of 1 (latest)

mortal stone
#

Hi, I would like the state to hold a multidimensional array. The initial state should be initialized from a default file that is embedded as an additional resource (https://tauri.app/v1/guides/building/resources).

How can I achieve that?

tauri::app::Builder::setup doesn't seem to provide a way to extract the data from it:

pub fn setup<F>(self, setup: F) -> Self
where
    F: FnOnce(&mut App<R>) -> Result<(), Box<dyn std::error::Error>> + Send + 'static,

Theoretically, I could try to copy the resource into tauri::api::path::app_data_dir(&context.config()).unwrap() but it looks like a very weird way to accomplish what I want.

zenith cosmos
#

Why would you copy over the resource to AppData? What would that accomplish?

Why does its initial state have to be created before it's managed? Just read the file in the setup function and update the managed Vec<Vec>> (arrays need to be known at compile time, in which case you need to use e.g. a Rust macro to create it a build time, but for a couple of reasons, just use a vector instead)

mortal stone
#

Why would you copy over the resource to AppData? What would that accomplish?

I thought it could be a hacky way to resolve AppData without a path resolver. I just want to have an access to a multidimensional array from a Tauri command and, ultimately, from the frontend. However, it seems that app.path_resolver().resolve_resource(DEFAULT_NIFTI_FILE) resolves to some weird path (\\?\C:\Users\USER\Documents\github\repalungs\tauri-client\src-tauri\target\debug\assets\default_nifti.nii.gz), which std::fs::metadata and other functions from sts::fs do not identify as a path to a file.

Why does its initial state have to be created before it's managed?

Because I just want to have a multidimensional array at the moment Tauri starts a browser window so that I could paint a layer from a NIFTI-1 image in the frontend. I fail to understand why I can't access a path resolver from a function for registering a managed sate.