English 中文(简体)
从Yew frontend
原标题:Access Tauri s plugin variable from Yew frontend

我有一个项目,包括<代码>Tauri后附和Yew前言。 I m试图节省一个表格变量,以存档tauri_plugin_store/code>。 但文件是可怕的,我并不肯定如何打上<条码>。 由我前言或仅从<代码>save_to_file功能中产生的变量,以便能够节省数据。 这就是我的Tauri <代码>main.rs。 like


// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::Error;
use tauri_plugin_store::StoreBuilder;
use serde_json::json;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greets(name: &str) -> String {
    format!("Hello, {}! You ve been greeted from Rust!", name)
}

#[tauri::command]
fn save_to_file(day: &str, text: &str, parent: &str) -> Result<(), Error>{
    println!(">>>>{}", text);
    return Ok(())
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![greets, save_to_file])
        .plugin(tauri_plugin_store::Builder::default().build())
        .setup(|app| {
            let mut store = StoreBuilder::new(app.handle(), "/Users/a/Desktop/tauri_project/store.bin".parse()?).build();
            Ok(store.insert("a".to_string(), json!("b"))?)
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

As you can see I have save_to_file() to saving my data. I m invoking this function from my form.rs inside of Yew app. I m able to call it and pass the data, but no save it, because store is defined in main as local variable


fn execute_effect(user_record: Record) {
    spawn_local(async move {
        if user_record.day == "" || user_record.text == "" || user_record.parent == "" {
            return;
        } else {
            let args = to_value(&Record {
                day: user_record.day.clone(),
                text: user_record.text.clone(),
                parent: user_record.parent.clone(),
            })
            .unwrap();

            let new_msg = invoke("save_to_file", args).await.as_string();
            log!("{:#?}", new_msg);
        }
    });
}

是否有这方面的工作?

我看到了这个例子。


//As you may have noticed, the Store crated above isn t accessible to the frontend. To interoperate with stores created by JS use the exported with_store method:

use tauri::Wry;
use tauri_plugin_store::with_store;

let stores = app.state::<StoreCollection<Wry>>();
let path = PathBuf::from("path/to/the/storefile");

with_store(app_handle, stores, path, |store| store.insert("a".to_string(), json!("b")))

但是,这真的说不是什么? 如何从<代码>进口。 Yew。 Wtf is app?

问题回答

暂无回答




相关问题
Creating an alias for a variable

I have the following code in Rust (which will not compile but illustrates what I am after). For readability purposes, I would like to refer the same string with two different names so that the name of ...

Rust Visual Studio Code code completion not working

I m trying to learn Rust and installed the Rust extension for VSCode. But I m not seeing auto-completions for any syntax. I d like to call .trim() on String but I get no completion for it. I read that ...

热门标签