mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
22f5acf240
* update cli * init android module * upgdate gitignore * add desktop and mobile * android * ios * lib * remove comment * cargo fmt * skip empty file creation * android comments * apple path * Discard changes to plugins/store/ios/README.md * stop auto directories creation * Update README.md
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use tauri::Runtime;
|
|
|
|
use crate::error::Result;
|
|
use crate::Store;
|
|
use serde_json::Value;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct LoadStore {
|
|
pub cache: HashMap<String, Value>,
|
|
}
|
|
|
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SaveStore {
|
|
pub store: String,
|
|
pub cache: HashMap<String, Value>,
|
|
}
|
|
|
|
#[cfg(mobile)]
|
|
impl<R: Runtime> Store<R> {
|
|
pub fn save(&self) -> Result<()> {
|
|
self.mobile_plugin_handle
|
|
.as_ref()
|
|
.ok_or_else(|| crate::error::Error::MobilePluginHandleUnInitialized)?
|
|
.run_mobile_plugin(
|
|
"save",
|
|
SaveStore {
|
|
store: self.path.to_string_lossy().to_string(),
|
|
cache: self.cache.clone(),
|
|
},
|
|
)
|
|
.map_err(Into::into)
|
|
}
|
|
|
|
pub fn load(&mut self) -> Result<()> {
|
|
let result: Value = self
|
|
.mobile_plugin_handle
|
|
.as_ref()
|
|
.ok_or_else(|| crate::error::Error::MobilePluginHandleUnInitialized)?
|
|
.run_mobile_plugin("load", self.path.to_string_lossy().to_string())?;
|
|
|
|
let map = serde_json::from_value::<HashMap<String, Value>>(result)?;
|
|
self.cache.extend(map);
|
|
|
|
Ok(())
|
|
}
|
|
}
|