Files
calorie-tracker/src-tauri/src/state.rs
Vilian Gerdzhikov 12365282a3 Merge release v0.0.2 (#60)
* update v0.0.1

* update v0.0.1

* add rust cache

* rename step

* fix test workflow

* change to build

* add password

* move app.jpeg

* bump & update name

* remove logo

* untrack .vscode

* remove icon from readme

* use npx

* rename file and do dom element check

* formating

* added rust files

* generated bindings

* rename to ipc

* add more examples

* move file

* new img

* refactor

* add clippy and tests

* imrpove clippy

* add semi

* enable release profile

* refactor

* first changeset

* version changeset

* version app

* move version in front of tagname

* do not error on local

* run after build

* use another workflow for clippy
2023-05-19 01:09:42 -02:00

35 lines
915 B
Rust

// This module shows examples of how to use managed custom state.
use std::collections::HashMap;
use std::string::ToString;
use std::sync::Mutex;
use tauri::{Builder, Wry};
// Exports a function for the tauri app instance to use and register all commands defined as frontend IPC command handlers.
pub fn register_managed_state(builder: Builder<Wry>) -> Builder<Wry> {
let store = Store::default();
builder.manage(store)
}
#[derive(Default)]
pub struct Store {
store: Mutex<HashMap<String, String>>,
}
impl Store {
pub fn add_key_val(&self, key: String, val: String) {
self.store
.lock()
.expect("cannot lock store")
.insert(key, val);
}
pub fn read_key(&self, key: &String) -> Option<String> {
self.store
.lock()
.expect("cannot lock store")
.get(key)
.map(ToString::to_string)
}
}