#Is there a way to copy files to the local assets folder ?

28 messages · Page 1 of 1 (latest)

austere bobcat
#

I see below example in the document, where we copy file from APPCONFIG/app.conf to APPCONFIG/app.conf.bk

import { copyFile, BaseDirectory } from '@tauri-apps/api/fs';
// Copy the $APPCONFIG/app.conf file to $APPCONFIG/app.conf.bk
await copyFile('app.conf', 'app.conf.bk', { dir: BaseDirectory.AppConfig });

Is there a way we can copy this file to local assets folder ???

golden anvil
#

If you mean the frontend files, it requires a work-around because they are compressed and stored inside the binary.

austere bobcat
#

Yes @golden anvil . I want to replace assets/config.txt with this

#

It will help me to solve my CI/CD for all the customers.
Otherwise, I have to do CI/CD for each customer 😦

golden anvil
#

Oh, you mean at build time?

austere bobcat
#

At run time

#

If I make this config to load from external path, then I can only focus on one build

#

Otherwise, I have to keep this config for each, and it's going to be truly painful

golden anvil
#

Ah, for runtime the asset protocol is needed. Is this not the same query as the previous thread?

austere bobcat
#

Trying all the ways 🙂

#

But end goal is, to read this config file from external 🙂

golden anvil
#

I'm not sure why the asset protocol isn't working for you when it is for me on the same versions.

#

If you can't get the asset protocol to work, you can read the file in Rust and pass it to the frontend.

austere bobcat
#

Oh, is there any example for this please

#

What I all want is, this config file contains an OBJECT. I want to pass this object value as parameter to one off the function call.

#

Every runtime, I want to read this file and pass this to the angular function

golden anvil
#
#[tauri::command(async)]
fn read_config() -> Result<Vec<u8>, String> {
  return std::fs::read("image.jpg").map_err(|e| e.to_string())?;
}
austere bobcat
#

Is the above function run first, before my angular load it's modules ?

#

Would you help me, where I need to create this file.

golden anvil
#

It runs when you call it from the frontend.

#

I can't help with angular, I only know standard JavaScript, but I can help with Rust.

austere bobcat
#

Angular is a typescript it's okay

#

Thank you so much for your support. Learned a lot from you

#

Is there a way, like "PreAppRun" hook where I can inject Rust code to read this file,
And Pass this read file content as input to the web app ?

golden anvil
#

The code I posted above should go in the src-tauri/src/main.rs file. You will also find a main() in that file which contains tauri::Builder. Inside the builder is the line .invoke_handler(tauri::generate_handler![test]) which you need to append read_config to the array as [test, read_config]. Or just replace the test entirely because it's just an example.

austere bobcat
#

Thank you @golden anvil . But I want to pre-load the file content, before app starts

golden anvil