feat(store): Add android & iOS support (#1011)

* 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
This commit is contained in:
Ahmed Elkhoudiry
2024-03-04 21:02:17 +02:00
committed by GitHub
parent 8a5e05cd83
commit 22f5acf240
17 changed files with 583 additions and 66 deletions
+53
View File
@@ -0,0 +1,53 @@
// 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(())
}
}