tauri_plugin_libsql/
desktop.rs1use serde::de::DeserializeOwned;
2use std::path::PathBuf;
3use tauri::{plugin::PluginApi, AppHandle, Runtime};
4
5use crate::models::*;
6
7#[derive(Debug, Clone, Default)]
9pub struct Config {
10 pub base_path: Option<PathBuf>,
12 pub encryption: Option<EncryptionConfig>,
15}
16
17pub fn init<R: Runtime, C: DeserializeOwned>(
18 _app: &AppHandle<R>,
19 _api: PluginApi<R, C>,
20 config: Config,
21) -> crate::Result<Libsql> {
22 Ok(Libsql(config))
23}
24
25pub struct Libsql(Config);
27
28impl Libsql {
29 pub fn ping(&self, payload: PingRequest) -> crate::Result<PingResponse> {
30 Ok(PingResponse {
31 value: payload.value,
32 })
33 }
34
35 pub fn base_path(&self) -> PathBuf {
37 self.0
38 .base_path
39 .clone()
40 .unwrap_or_else(|| std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")))
41 }
42
43 pub fn encryption(&self) -> Option<&EncryptionConfig> {
45 self.0.encryption.as_ref()
46 }
47}