├── .gitignore ├── examples └── AppSettingsManager │ ├── dist │ └── .gitkeep │ ├── src-tauri │ ├── src │ │ ├── app │ │ │ ├── mod.rs │ │ │ └── settings.rs │ │ └── main.rs │ ├── build.rs │ ├── .gitignore │ ├── icons │ │ ├── 32x32.png │ │ ├── icon.icns │ │ ├── icon.ico │ │ ├── icon.png │ │ ├── 128x128.png │ │ ├── 128x128@2x.png │ │ ├── StoreLogo.png │ │ ├── Square30x30Logo.png │ │ ├── Square44x44Logo.png │ │ ├── Square71x71Logo.png │ │ ├── Square89x89Logo.png │ │ ├── Square107x107Logo.png │ │ ├── Square142x142Logo.png │ │ ├── Square150x150Logo.png │ │ ├── Square284x284Logo.png │ │ └── Square310x310Logo.png │ ├── Cargo.toml │ └── tauri.conf.json │ ├── .vscode │ └── extensions.json │ ├── src │ ├── main.ts │ ├── assets │ │ ├── vite.svg │ │ ├── typescript.svg │ │ └── tauri.svg │ └── styles.css │ ├── package.json │ ├── .gitignore │ ├── README.md │ ├── tsconfig.json │ ├── vite.config.ts │ └── index.html ├── banner.png ├── tsconfig.json ├── rollup.config.mjs ├── Cargo.toml ├── package.json ├── LICENSE.spdx ├── LICENSE_MIT ├── src ├── error.rs ├── lib.rs └── store.rs ├── dist-js ├── index.mjs.map ├── index.d.ts ├── index.mjs ├── index.min.js └── index.min.js.map ├── README.md ├── guest-js └── index.ts └── LICENSE_APACHE-2.0 /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /examples/AppSettingsManager/dist/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/src/app/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod settings; 2 | -------------------------------------------------------------------------------- /banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/banner.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | tauri_build::build() 3 | } 4 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "include": ["guest-js/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"] 3 | } 4 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/32x32.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/icon.icns -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/icon.ico -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/icon.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/128x128.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/128x128@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/128x128@2x.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/StoreLogo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square30x30Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square30x30Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square44x44Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square44x44Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square71x71Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square71x71Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square89x89Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square89x89Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square107x107Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square107x107Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square142x142Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square142x142Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square150x150Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square150x150Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square284x284Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square284x284Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/icons/Square310x310Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tauri-apps/tauri-plugin-store/HEAD/examples/AppSettingsManager/src-tauri/icons/Square310x310Logo.png -------------------------------------------------------------------------------- /examples/AppSettingsManager/src/main.ts: -------------------------------------------------------------------------------- 1 | window.addEventListener("DOMContentLoaded", () => { 2 | document.querySelector("#greet-form")?.addEventListener("submit", (e) => { 3 | e.preventDefault(); 4 | }); 5 | }); 6 | -------------------------------------------------------------------------------- /rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import { readFileSync } from "fs"; 2 | 3 | import { createConfig } from "../../shared/rollup.config.mjs"; 4 | 5 | export default createConfig({ 6 | input: "guest-js/index.ts", 7 | pkg: JSON.parse( 8 | readFileSync(new URL("./package.json", import.meta.url), "utf8"), 9 | ), 10 | external: [/^@tauri-apps\/api/], 11 | }); 12 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "type": "module", 4 | "scripts": { 5 | "dev": "vite", 6 | "build": "tsc && vite build", 7 | "preview": "vite preview", 8 | "tauri": "tauri" 9 | }, 10 | "devDependencies": { 11 | "@tauri-apps/cli": "1.6.3", 12 | "typescript": "^5.8.2", 13 | "vite": "^7.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | #dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/README.md: -------------------------------------------------------------------------------- 1 | # Tauri + Vanilla TS 2 | 3 | This template should help get you started developing with Tauri in vanilla HTML, CSS and Typescript. 4 | 5 | ## Recommended IDE Setup 6 | 7 | - [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) 8 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tauri-plugin-store" 3 | version = "0.0.0" 4 | description = "Simple, persistent key-value store." 5 | authors = { workspace = true } 6 | license = { workspace = true } 7 | edition = { workspace = true } 8 | rust-version = { workspace = true } 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [dependencies] 13 | serde = { workspace = true } 14 | serde_json = { workspace = true } 15 | tauri = { workspace = true } 16 | log = { workspace = true } 17 | thiserror = { workspace = true } -------------------------------------------------------------------------------- /examples/AppSettingsManager/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "noEmit": true, 15 | 16 | /* Linting */ 17 | "strict": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noFallthroughCasesInSwitch": true 21 | }, 22 | "include": ["src"] 23 | } 24 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | 3 | // https://vitejs.dev/config/ 4 | export default defineConfig(async () => ({ 5 | // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` 6 | // 7 | // 1. prevent vite from obscuring rust errors 8 | clearScreen: false, 9 | // 2. tauri expects a fixed port, fail if that port is not available 10 | server: { 11 | port: 1420, 12 | strictPort: true, 13 | }, 14 | // 3. to make use of `TAURI_DEBUG` and other env variables 15 | // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand 16 | envPrefix: ["VITE_", "TAURI_"], 17 | })); 18 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "app_settings_manager" 3 | version = "0.0.0" 4 | description = "A Tauri App" 5 | authors = ["you"] 6 | license = "" 7 | repository = "" 8 | edition = "2021" 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [build-dependencies] 13 | tauri-build = { workspace = true } 14 | 15 | [dependencies] 16 | tauri = { workspace = true, features = ["shell-open"] } 17 | serde = { workspace = true } 18 | serde_json = { workspace = true } 19 | tauri-plugin-store = { path = "../../../" } 20 | 21 | [features] 22 | # this feature is used for production builds or when `devPath` points to the filesystem 23 | # DO NOT REMOVE!! 24 | custom-protocol = ["tauri/custom-protocol"] 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tauri-plugin-store-api", 3 | "version": "0.0.0", 4 | "description": "Simple, persistent key-value store.", 5 | "license": "MIT or APACHE-2.0", 6 | "authors": [ 7 | "Tauri Programme within The Commons Conservancy" 8 | ], 9 | "type": "module", 10 | "browser": "dist-js/index.min.js", 11 | "module": "dist-js/index.mjs", 12 | "types": "dist-js/index.d.ts", 13 | "exports": { 14 | "import": "./dist-js/index.mjs", 15 | "types": "./dist-js/index.d.ts", 16 | "browser": "./dist-js/index.min.js" 17 | }, 18 | "scripts": { 19 | "build": "rollup -c" 20 | }, 21 | "files": [ 22 | "dist-js", 23 | "!dist-js/**/*.map", 24 | "README.md", 25 | "LICENSE" 26 | ], 27 | "devDependencies": { 28 | "tslib": "2.8.1" 29 | }, 30 | "dependencies": { 31 | "@tauri-apps/api": "1.6.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/src/app/settings.rs: -------------------------------------------------------------------------------- 1 | use tauri_plugin_store::Store; 2 | 3 | #[derive(Debug, Clone)] 4 | pub struct AppSettings { 5 | pub launch_at_login: bool, 6 | pub theme: String, 7 | } 8 | 9 | impl AppSettings { 10 | pub fn load_from_store( 11 | store: &Store, 12 | ) -> Result> { 13 | let launch_at_login = store 14 | .get("appSettings.launchAtLogin") 15 | .and_then(|v| v.as_bool()) 16 | .unwrap_or(false); 17 | 18 | let theme = store 19 | .get("appSettings.theme") 20 | .and_then(|v| v.as_str()) 21 | .map(|s| s.to_string()) 22 | .unwrap_or_else(|| "dark".to_string()); 23 | 24 | Ok(AppSettings { 25 | launch_at_login, 26 | theme, 27 | }) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE.spdx: -------------------------------------------------------------------------------- 1 | SPDXVersion: SPDX-2.1 2 | DataLicense: CC0-1.0 3 | PackageName: tauri 4 | DataFormat: SPDXRef-1 5 | PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy 6 | PackageHomePage: https://tauri.app 7 | PackageLicenseDeclared: Apache-2.0 8 | PackageLicenseDeclared: MIT 9 | PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy 10 | PackageSummary: Tauri is a rust project that enables developers to make secure 11 | and small desktop applications using a web frontend. 12 | 13 | PackageComment: The package includes the following libraries; see 14 | Relationship information. 15 | 16 | Created: 2019-05-20T09:00:00Z 17 | PackageDownloadLocation: git://github.com/tauri-apps/tauri 18 | PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git 19 | PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git 20 | Creator: Person: Daniel Thompson-Yvetot -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/tauri.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "beforeDevCommand": "pnpm dev", 4 | "beforeBuildCommand": "pnpm build", 5 | "devPath": "http://localhost:1420", 6 | "distDir": "../dist", 7 | "withGlobalTauri": true 8 | }, 9 | "package": { 10 | "productName": "AppSettingsManager", 11 | "version": "0.0.0" 12 | }, 13 | "tauri": { 14 | "allowlist": { 15 | "all": false, 16 | "shell": { 17 | "all": false, 18 | "open": true 19 | } 20 | }, 21 | "bundle": { 22 | "active": true, 23 | "targets": "all", 24 | "identifier": "com.tauri.dev", 25 | "icon": [ 26 | "icons/32x32.png", 27 | "icons/128x128.png", 28 | "icons/128x128@2x.png", 29 | "icons/icon.icns", 30 | "icons/icon.ico" 31 | ] 32 | }, 33 | "security": { 34 | "csp": null 35 | }, 36 | "windows": [ 37 | { 38 | "fullscreen": false, 39 | "resizable": true, 40 | "title": "AppSettingsManager", 41 | "width": 800, 42 | "height": 600 43 | } 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE_MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 - Present Tauri Apps Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tauri Programme within The Commons Conservancy 2 | // SPDX-License-Identifier: Apache-2.0 3 | // SPDX-License-Identifier: MIT 4 | 5 | use serde::{Serialize, Serializer}; 6 | use std::path::PathBuf; 7 | 8 | /// The error types. 9 | #[derive(thiserror::Error, Debug)] 10 | #[non_exhaustive] 11 | pub enum Error { 12 | #[error("Failed to serialize store. {0}")] 13 | Serialize(Box), 14 | #[error("Failed to deserialize store. {0}")] 15 | Deserialize(Box), 16 | /// JSON error. 17 | #[error(transparent)] 18 | Json(#[from] serde_json::Error), 19 | /// IO error. 20 | #[error(transparent)] 21 | Io(#[from] std::io::Error), 22 | /// Store not found 23 | #[error("Store \"{0}\" not found")] 24 | NotFound(PathBuf), 25 | /// Some Tauri API failed 26 | #[error(transparent)] 27 | Tauri(#[from] tauri::Error), 28 | } 29 | 30 | impl Serialize for Error { 31 | fn serialize(&self, serializer: S) -> std::result::Result 32 | where 33 | S: Serializer, 34 | { 35 | serializer.serialize_str(self.to_string().as_ref()) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src/assets/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src/assets/typescript.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 10 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src-tauri/src/main.rs: -------------------------------------------------------------------------------- 1 | // Prevents additional console window on Windows in release, DO NOT REMOVE!! 2 | #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] 3 | 4 | use tauri_plugin_store::StoreBuilder; 5 | 6 | mod app; 7 | use app::settings::AppSettings; 8 | 9 | fn main() { 10 | tauri::Builder::default() 11 | .plugin(tauri_plugin_store::Builder::default().build()) 12 | .setup(|app| { 13 | // Init store and load it from disk 14 | let mut store = StoreBuilder::new(app.handle(), "settings.json".parse()?).build(); 15 | 16 | // If there are no saved settings yet, this will return an error so we ignore the return value. 17 | let _ = store.load(); 18 | 19 | let app_settings = AppSettings::load_from_store(&store); 20 | 21 | match app_settings { 22 | Ok(app_settings) => { 23 | let theme = app_settings.theme; 24 | let launch_at_login = app_settings.launch_at_login; 25 | 26 | println!("theme {}", theme); 27 | println!("launch_at_login {}", launch_at_login); 28 | 29 | Ok(()) 30 | } 31 | Err(err) => { 32 | eprintln!("Error loading settings: {}", err); 33 | // Handle the error case if needed 34 | Err(err) // Convert the error to a Box and return Err(err) here 35 | } 36 | } 37 | }) 38 | .run(tauri::generate_context!()) 39 | .expect("error while running tauri application"); 40 | } 41 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Tauri App 8 | 9 | 18 | 19 | 20 | 21 |
22 |

Welcome to Tauri!

23 | 24 | 43 | 44 |

Click on the Tauri logo to learn more about the framework

45 | 46 | 50 | 51 |

52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /examples/AppSettingsManager/src/styles.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, Avenir, Helvetica, Arial, sans-serif; 3 | font-size: 16px; 4 | line-height: 24px; 5 | font-weight: 400; 6 | 7 | color: #0f0f0f; 8 | background-color: #f6f6f6; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | -webkit-text-size-adjust: 100%; 15 | } 16 | 17 | .container { 18 | margin: 0; 19 | padding-top: 10vh; 20 | display: flex; 21 | flex-direction: column; 22 | justify-content: center; 23 | text-align: center; 24 | } 25 | 26 | .logo { 27 | height: 6em; 28 | padding: 1.5em; 29 | will-change: filter; 30 | transition: 0.75s; 31 | } 32 | 33 | .logo.tauri:hover { 34 | filter: drop-shadow(0 0 2em #24c8db); 35 | } 36 | 37 | .row { 38 | display: flex; 39 | justify-content: center; 40 | } 41 | 42 | a { 43 | font-weight: 500; 44 | color: #646cff; 45 | text-decoration: inherit; 46 | } 47 | 48 | a:hover { 49 | color: #535bf2; 50 | } 51 | 52 | h1 { 53 | text-align: center; 54 | } 55 | 56 | input, 57 | button { 58 | border-radius: 8px; 59 | border: 1px solid transparent; 60 | padding: 0.6em 1.2em; 61 | font-size: 1em; 62 | font-weight: 500; 63 | font-family: inherit; 64 | color: #0f0f0f; 65 | background-color: #ffffff; 66 | transition: border-color 0.25s; 67 | box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2); 68 | } 69 | 70 | button { 71 | cursor: pointer; 72 | } 73 | 74 | button:hover { 75 | border-color: #396cd8; 76 | } 77 | button:active { 78 | border-color: #396cd8; 79 | background-color: #e8e8e8; 80 | } 81 | 82 | input, 83 | button { 84 | outline: none; 85 | } 86 | 87 | #greet-input { 88 | margin-right: 5px; 89 | } 90 | 91 | @media (prefers-color-scheme: dark) { 92 | :root { 93 | color: #f6f6f6; 94 | background-color: #2f2f2f; 95 | } 96 | 97 | a:hover { 98 | color: #24c8db; 99 | } 100 | 101 | input, 102 | button { 103 | color: #ffffff; 104 | background-color: #0f0f0f98; 105 | } 106 | button:active { 107 | background-color: #0f0f0f69; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /dist-js/index.mjs.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.mjs","sources":["../guest-js/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;AACA;AACA;AAWA;;AAEG;MACU,KAAK,CAAA;AAEhB,IAAA,WAAA,CAAY,IAAY,EAAA;AACtB,QAAA,IAAI,CAAC,IAAI,GAAG,IAA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CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;AACpC,gBAAA,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC5C;AACF,QAAA,CAAC,CAAC;IACJ;AACD;;;;"} -------------------------------------------------------------------------------- /examples/AppSettingsManager/src/assets/tauri.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /dist-js/index.d.ts: -------------------------------------------------------------------------------- 1 | import { UnlistenFn } from "@tauri-apps/api/event"; 2 | /** 3 | * A key-value store persisted by the backend layer. 4 | */ 5 | export declare class Store { 6 | path: string; 7 | constructor(path: string); 8 | /** 9 | * Inserts a key-value pair into the store. 10 | * 11 | * @param key 12 | * @param value 13 | * @returns 14 | */ 15 | set(key: string, value: unknown): Promise; 16 | /** 17 | * Returns the value for the given `key` or `null` the key does not exist. 18 | * 19 | * @param key 20 | * @returns 21 | */ 22 | get(key: string): Promise; 23 | /** 24 | * Returns `true` if the given `key` exists in the store. 25 | * 26 | * @param key 27 | * @returns 28 | */ 29 | has(key: string): Promise; 30 | /** 31 | * Removes a key-value pair from the store. 32 | * 33 | * @param key 34 | * @returns 35 | */ 36 | delete(key: string): Promise; 37 | /** 38 | * Clears the store, removing all key-value pairs. 39 | * 40 | * Note: To clear the storage and reset it to it's `default` value, use `reset` instead. 41 | * @returns 42 | */ 43 | clear(): Promise; 44 | /** 45 | * Resets the store to it's `default` value. 46 | * 47 | * If no default value has been set, this method behaves identical to `clear`. 48 | * @returns 49 | */ 50 | reset(): Promise; 51 | /** 52 | * Returns a list of all key in the store. 53 | * 54 | * @returns 55 | */ 56 | keys(): Promise; 57 | /** 58 | * Returns a list of all values in the store. 59 | * 60 | * @returns 61 | */ 62 | values(): Promise; 63 | /** 64 | * Returns a list of all entries in the store. 65 | * 66 | * @returns 67 | */ 68 | entries(): Promise>; 69 | /** 70 | * Returns the number of key-value pairs in the store. 71 | * 72 | * @returns 73 | */ 74 | length(): Promise; 75 | /** 76 | * Attempts to load the on-disk state at the stores `path` into memory. 77 | * 78 | * This method is useful if the on-disk state was edited by the user and you want to synchronize the changes. 79 | * 80 | * Note: This method does not emit change events. 81 | * @returns 82 | */ 83 | load(): Promise; 84 | /** 85 | * Saves the store to disk at the stores `path`. 86 | * 87 | * As the store is only persisted to disk before the apps exit, changes might be lost in a crash. 88 | * This method lets you persist the store to disk whenever you deem necessary. 89 | * @returns 90 | */ 91 | save(): Promise; 92 | /** 93 | * Listen to changes on a store key. 94 | * @param key 95 | * @param cb 96 | * @returns A promise resolving to a function to unlisten to the event. 97 | */ 98 | onKeyChange(key: string, cb: (value: T | null) => void): Promise; 99 | /** 100 | * Listen to changes on the store. 101 | * @param cb 102 | * @returns A promise resolving to a function to unlisten to the event. 103 | */ 104 | onChange(cb: (key: string, value: T | null) => void): Promise; 105 | } 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![plugin-store](https://github.com/tauri-apps/plugins-workspace/raw/v1/plugins/store/banner.png) 2 | 3 | Simple, persistent key-value store. 4 | 5 | ## Install 6 | 7 | _This plugin requires a Rust version of at least **1.67**_ 8 | 9 | There are three general methods of installation that we can recommend. 10 | 11 | 1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked) 12 | 2. Pull sources directly from Github using git tags / revision hashes (most secure) 13 | 3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use) 14 | 15 | Install the Core plugin by adding the following to your `Cargo.toml` file: 16 | 17 | `src-tauri/Cargo.toml` 18 | 19 | ```toml 20 | [dependencies] 21 | tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } 22 | ``` 23 | 24 | You can install the JavaScript Guest bindings using your preferred JavaScript package manager: 25 | 26 | > Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use. 27 | 28 | ```sh 29 | pnpm add https://github.com/tauri-apps/tauri-plugin-store#v1 30 | # or 31 | npm add https://github.com/tauri-apps/tauri-plugin-store#v1 32 | # or 33 | yarn add https://github.com/tauri-apps/tauri-plugin-store#v1 34 | ``` 35 | 36 | ## Usage 37 | 38 | First you need to register the core plugin with Tauri: 39 | 40 | `src-tauri/src/main.rs` 41 | 42 | ```rust 43 | fn main() { 44 | tauri::Builder::default() 45 | .plugin(tauri_plugin_store::Builder::default().build()) 46 | .run(tauri::generate_context!()) 47 | .expect("error while running tauri application"); 48 | } 49 | ``` 50 | 51 | Afterwards all the plugin's APIs are available through the JavaScript guest bindings: 52 | 53 | ```typescript 54 | import { Store } from "tauri-plugin-store-api"; 55 | 56 | const store = new Store(".settings.dat"); 57 | 58 | await store.set("some-key", { value: 5 }); 59 | 60 | const val = await store.get<{ value: number }>("some-key"); 61 | 62 | if (val) { 63 | console.log(val); 64 | } else { 65 | console.log("val is null"); 66 | } 67 | 68 | await store.save(); // this manually saves the store, otherwise the store is only saved when your app is closed 69 | ``` 70 | 71 | ### Persisting values 72 | 73 | Values added to the store are not persisted between application loads unless: 74 | 75 | 1. The application is closed gracefully (plugin automatically saves) 76 | 2. The store is manually saved (using `store.save()`) 77 | 78 | ## Usage from Rust 79 | 80 | You can also access Stores from Rust, you can create new stores: 81 | 82 | ```rust 83 | use tauri_plugin_store::StoreBuilder; 84 | use serde_json::json; 85 | 86 | fn main() { 87 | tauri::Builder::default() 88 | .plugin(tauri_plugin_store::Builder::default().build()) 89 | .setup(|app| { 90 | let mut store = StoreBuilder::new(app.handle(), "path/to/store.bin".parse()?).build(); 91 | 92 | store.insert("a".to_string(), json!("b")) // note that values must be serd_json::Value to be compatible with JS 93 | }) 94 | .run(tauri::generate_context!()) 95 | .expect("error while running tauri application"); 96 | } 97 | ``` 98 | 99 | As you may have noticed, the Store created above isn't accessible to the frontend. To interoperate with stores created by JS use the exported `with_store` method: 100 | 101 | ```rust 102 | use tauri::Wry; 103 | use tauri_plugin_store::with_store; 104 | 105 | let stores = app.state::>(); 106 | let path = PathBuf::from("path/to/the/storefile"); 107 | 108 | with_store(app_handle, stores, path, |store| store.insert("a".to_string(), json!("b"))) 109 | ``` 110 | 111 | ## Contributing 112 | 113 | PRs accepted. Please make sure to read the Contributing Guide before making a pull request. 114 | 115 | ## Partners 116 | 117 | 118 | 119 | 120 | 125 | 126 | 127 |
121 | 122 | CrabNebula 123 | 124 |
128 | 129 | For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri). 130 | 131 | ## License 132 | 133 | Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy. 134 | 135 | MIT or MIT/Apache 2.0 where applicable. 136 | -------------------------------------------------------------------------------- /dist-js/index.mjs: -------------------------------------------------------------------------------- 1 | import { invoke } from '@tauri-apps/api/tauri'; 2 | import { listen } from '@tauri-apps/api/event'; 3 | 4 | // Copyright 2021 Tauri Programme within The Commons Conservancy 5 | // SPDX-License-Identifier: Apache-2.0 6 | // SPDX-License-Identifier: MIT 7 | /** 8 | * A key-value store persisted by the backend layer. 9 | */ 10 | class Store { 11 | constructor(path) { 12 | this.path = path; 13 | } 14 | /** 15 | * Inserts a key-value pair into the store. 16 | * 17 | * @param key 18 | * @param value 19 | * @returns 20 | */ 21 | async set(key, value) { 22 | return await invoke("plugin:store|set", { 23 | path: this.path, 24 | key, 25 | value, 26 | }); 27 | } 28 | /** 29 | * Returns the value for the given `key` or `null` the key does not exist. 30 | * 31 | * @param key 32 | * @returns 33 | */ 34 | async get(key) { 35 | return await invoke("plugin:store|get", { 36 | path: this.path, 37 | key, 38 | }); 39 | } 40 | /** 41 | * Returns `true` if the given `key` exists in the store. 42 | * 43 | * @param key 44 | * @returns 45 | */ 46 | async has(key) { 47 | return await invoke("plugin:store|has", { 48 | path: this.path, 49 | key, 50 | }); 51 | } 52 | /** 53 | * Removes a key-value pair from the store. 54 | * 55 | * @param key 56 | * @returns 57 | */ 58 | async delete(key) { 59 | return await invoke("plugin:store|delete", { 60 | path: this.path, 61 | key, 62 | }); 63 | } 64 | /** 65 | * Clears the store, removing all key-value pairs. 66 | * 67 | * Note: To clear the storage and reset it to it's `default` value, use `reset` instead. 68 | * @returns 69 | */ 70 | async clear() { 71 | return await invoke("plugin:store|clear", { 72 | path: this.path, 73 | }); 74 | } 75 | /** 76 | * Resets the store to it's `default` value. 77 | * 78 | * If no default value has been set, this method behaves identical to `clear`. 79 | * @returns 80 | */ 81 | async reset() { 82 | return await invoke("plugin:store|reset", { 83 | path: this.path, 84 | }); 85 | } 86 | /** 87 | * Returns a list of all key in the store. 88 | * 89 | * @returns 90 | */ 91 | async keys() { 92 | return await invoke("plugin:store|keys", { 93 | path: this.path, 94 | }); 95 | } 96 | /** 97 | * Returns a list of all values in the store. 98 | * 99 | * @returns 100 | */ 101 | async values() { 102 | return await invoke("plugin:store|values", { 103 | path: this.path, 104 | }); 105 | } 106 | /** 107 | * Returns a list of all entries in the store. 108 | * 109 | * @returns 110 | */ 111 | async entries() { 112 | return await invoke("plugin:store|entries", { 113 | path: this.path, 114 | }); 115 | } 116 | /** 117 | * Returns the number of key-value pairs in the store. 118 | * 119 | * @returns 120 | */ 121 | async length() { 122 | return await invoke("plugin:store|length", { 123 | path: this.path, 124 | }); 125 | } 126 | /** 127 | * Attempts to load the on-disk state at the stores `path` into memory. 128 | * 129 | * This method is useful if the on-disk state was edited by the user and you want to synchronize the changes. 130 | * 131 | * Note: This method does not emit change events. 132 | * @returns 133 | */ 134 | async load() { 135 | return await invoke("plugin:store|load", { 136 | path: this.path, 137 | }); 138 | } 139 | /** 140 | * Saves the store to disk at the stores `path`. 141 | * 142 | * As the store is only persisted to disk before the apps exit, changes might be lost in a crash. 143 | * This method lets you persist the store to disk whenever you deem necessary. 144 | * @returns 145 | */ 146 | async save() { 147 | return await invoke("plugin:store|save", { 148 | path: this.path, 149 | }); 150 | } 151 | /** 152 | * Listen to changes on a store key. 153 | * @param key 154 | * @param cb 155 | * @returns A promise resolving to a function to unlisten to the event. 156 | */ 157 | async onKeyChange(key, cb) { 158 | return await listen("store://change", (event) => { 159 | if (event.payload.path === this.path && event.payload.key === key) { 160 | cb(event.payload.value); 161 | } 162 | }); 163 | } 164 | /** 165 | * Listen to changes on the store. 166 | * @param cb 167 | * @returns A promise resolving to a function to unlisten to the event. 168 | */ 169 | async onChange(cb) { 170 | return await listen("store://change", (event) => { 171 | if (event.payload.path === this.path) { 172 | cb(event.payload.key, event.payload.value); 173 | } 174 | }); 175 | } 176 | } 177 | 178 | export { Store }; 179 | //# sourceMappingURL=index.mjs.map 180 | -------------------------------------------------------------------------------- /guest-js/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tauri Programme within The Commons Conservancy 2 | // SPDX-License-Identifier: Apache-2.0 3 | // SPDX-License-Identifier: MIT 4 | 5 | import { invoke } from "@tauri-apps/api/tauri"; 6 | import { listen, UnlistenFn } from "@tauri-apps/api/event"; 7 | 8 | interface ChangePayload { 9 | path: string; 10 | key: string; 11 | value: T | null; 12 | } 13 | 14 | /** 15 | * A key-value store persisted by the backend layer. 16 | */ 17 | export class Store { 18 | path: string; 19 | constructor(path: string) { 20 | this.path = path; 21 | } 22 | 23 | /** 24 | * Inserts a key-value pair into the store. 25 | * 26 | * @param key 27 | * @param value 28 | * @returns 29 | */ 30 | async set(key: string, value: unknown): Promise { 31 | return await invoke("plugin:store|set", { 32 | path: this.path, 33 | key, 34 | value, 35 | }); 36 | } 37 | 38 | /** 39 | * Returns the value for the given `key` or `null` the key does not exist. 40 | * 41 | * @param key 42 | * @returns 43 | */ 44 | async get(key: string): Promise { 45 | return await invoke("plugin:store|get", { 46 | path: this.path, 47 | key, 48 | }); 49 | } 50 | 51 | /** 52 | * Returns `true` if the given `key` exists in the store. 53 | * 54 | * @param key 55 | * @returns 56 | */ 57 | async has(key: string): Promise { 58 | return await invoke("plugin:store|has", { 59 | path: this.path, 60 | key, 61 | }); 62 | } 63 | 64 | /** 65 | * Removes a key-value pair from the store. 66 | * 67 | * @param key 68 | * @returns 69 | */ 70 | async delete(key: string): Promise { 71 | return await invoke("plugin:store|delete", { 72 | path: this.path, 73 | key, 74 | }); 75 | } 76 | 77 | /** 78 | * Clears the store, removing all key-value pairs. 79 | * 80 | * Note: To clear the storage and reset it to it's `default` value, use `reset` instead. 81 | * @returns 82 | */ 83 | async clear(): Promise { 84 | return await invoke("plugin:store|clear", { 85 | path: this.path, 86 | }); 87 | } 88 | 89 | /** 90 | * Resets the store to it's `default` value. 91 | * 92 | * If no default value has been set, this method behaves identical to `clear`. 93 | * @returns 94 | */ 95 | async reset(): Promise { 96 | return await invoke("plugin:store|reset", { 97 | path: this.path, 98 | }); 99 | } 100 | 101 | /** 102 | * Returns a list of all key in the store. 103 | * 104 | * @returns 105 | */ 106 | async keys(): Promise { 107 | return await invoke("plugin:store|keys", { 108 | path: this.path, 109 | }); 110 | } 111 | 112 | /** 113 | * Returns a list of all values in the store. 114 | * 115 | * @returns 116 | */ 117 | async values(): Promise { 118 | return await invoke("plugin:store|values", { 119 | path: this.path, 120 | }); 121 | } 122 | 123 | /** 124 | * Returns a list of all entries in the store. 125 | * 126 | * @returns 127 | */ 128 | async entries(): Promise> { 129 | return await invoke("plugin:store|entries", { 130 | path: this.path, 131 | }); 132 | } 133 | 134 | /** 135 | * Returns the number of key-value pairs in the store. 136 | * 137 | * @returns 138 | */ 139 | async length(): Promise { 140 | return await invoke("plugin:store|length", { 141 | path: this.path, 142 | }); 143 | } 144 | 145 | /** 146 | * Attempts to load the on-disk state at the stores `path` into memory. 147 | * 148 | * This method is useful if the on-disk state was edited by the user and you want to synchronize the changes. 149 | * 150 | * Note: This method does not emit change events. 151 | * @returns 152 | */ 153 | async load(): Promise { 154 | return await invoke("plugin:store|load", { 155 | path: this.path, 156 | }); 157 | } 158 | 159 | /** 160 | * Saves the store to disk at the stores `path`. 161 | * 162 | * As the store is only persisted to disk before the apps exit, changes might be lost in a crash. 163 | * This method lets you persist the store to disk whenever you deem necessary. 164 | * @returns 165 | */ 166 | async save(): Promise { 167 | return await invoke("plugin:store|save", { 168 | path: this.path, 169 | }); 170 | } 171 | 172 | /** 173 | * Listen to changes on a store key. 174 | * @param key 175 | * @param cb 176 | * @returns A promise resolving to a function to unlisten to the event. 177 | */ 178 | async onKeyChange( 179 | key: string, 180 | cb: (value: T | null) => void, 181 | ): Promise { 182 | return await listen>("store://change", (event) => { 183 | if (event.payload.path === this.path && event.payload.key === key) { 184 | cb(event.payload.value); 185 | } 186 | }); 187 | } 188 | 189 | /** 190 | * Listen to changes on the store. 191 | * @param cb 192 | * @returns A promise resolving to a function to unlisten to the event. 193 | */ 194 | async onChange( 195 | cb: (key: string, value: T | null) => void, 196 | ): Promise { 197 | return await listen>("store://change", (event) => { 198 | if (event.payload.path === this.path) { 199 | cb(event.payload.key, event.payload.value); 200 | } 201 | }); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tauri Programme within The Commons Conservancy 2 | // SPDX-License-Identifier: Apache-2.0 3 | // SPDX-License-Identifier: MIT 4 | 5 | pub use error::Error; 6 | use log::warn; 7 | use serde::Serialize; 8 | pub use serde_json::Value as JsonValue; 9 | use std::{ 10 | collections::HashMap, 11 | path::{Path, PathBuf}, 12 | sync::Mutex, 13 | }; 14 | pub use store::{Store, StoreBuilder}; 15 | use tauri::{ 16 | plugin::{self, TauriPlugin}, 17 | AppHandle, Manager, RunEvent, Runtime, State, 18 | }; 19 | 20 | mod error; 21 | mod store; 22 | 23 | #[derive(Serialize, Clone)] 24 | struct ChangePayload<'a> { 25 | path: &'a Path, 26 | key: &'a str, 27 | value: &'a JsonValue, 28 | } 29 | 30 | #[derive(Default)] 31 | pub struct StoreCollection { 32 | stores: Mutex>>, 33 | frozen: bool, 34 | } 35 | 36 | pub fn with_store) -> Result>( 37 | app: AppHandle, 38 | collection: State<'_, StoreCollection>, 39 | path: impl AsRef, 40 | f: F, 41 | ) -> Result { 42 | let mut stores = collection.stores.lock().expect("mutex poisoned"); 43 | 44 | let path = path.as_ref(); 45 | if !stores.contains_key(path) { 46 | if collection.frozen { 47 | return Err(Error::NotFound(path.to_path_buf())); 48 | } 49 | let mut store = StoreBuilder::new(app, path.to_path_buf()).build(); 50 | // ignore loading errors, just use the default 51 | if let Err(err) = store.load() { 52 | warn!( 53 | "Failed to load store {:?} from disk: {}. Falling back to default values.", 54 | path, err 55 | ); 56 | } 57 | stores.insert(path.to_path_buf(), store); 58 | } 59 | 60 | f(stores 61 | .get_mut(path) 62 | .expect("failed to retrieve store. This is a bug!")) 63 | } 64 | 65 | #[tauri::command] 66 | async fn set( 67 | app: AppHandle, 68 | stores: State<'_, StoreCollection>, 69 | path: PathBuf, 70 | key: String, 71 | value: JsonValue, 72 | ) -> Result<(), Error> { 73 | with_store(app, stores, path, |store| store.insert(key, value)) 74 | } 75 | 76 | #[tauri::command] 77 | async fn get( 78 | app: AppHandle, 79 | stores: State<'_, StoreCollection>, 80 | path: PathBuf, 81 | key: String, 82 | ) -> Result, Error> { 83 | with_store(app, stores, path, |store| Ok(store.get(key).cloned())) 84 | } 85 | 86 | #[tauri::command] 87 | async fn has( 88 | app: AppHandle, 89 | stores: State<'_, StoreCollection>, 90 | path: PathBuf, 91 | key: String, 92 | ) -> Result { 93 | with_store(app, stores, path, |store| Ok(store.has(key))) 94 | } 95 | 96 | #[tauri::command] 97 | async fn delete( 98 | app: AppHandle, 99 | stores: State<'_, StoreCollection>, 100 | path: PathBuf, 101 | key: String, 102 | ) -> Result { 103 | with_store(app, stores, path, |store| store.delete(key)) 104 | } 105 | 106 | #[tauri::command] 107 | async fn clear( 108 | app: AppHandle, 109 | stores: State<'_, StoreCollection>, 110 | path: PathBuf, 111 | ) -> Result<(), Error> { 112 | with_store(app, stores, path, |store| store.clear()) 113 | } 114 | 115 | #[tauri::command] 116 | async fn reset( 117 | app: AppHandle, 118 | collection: State<'_, StoreCollection>, 119 | path: PathBuf, 120 | ) -> Result<(), Error> { 121 | with_store(app, collection, path, |store| store.reset()) 122 | } 123 | 124 | #[tauri::command] 125 | async fn keys( 126 | app: AppHandle, 127 | stores: State<'_, StoreCollection>, 128 | path: PathBuf, 129 | ) -> Result, Error> { 130 | with_store(app, stores, path, |store| { 131 | Ok(store.keys().cloned().collect()) 132 | }) 133 | } 134 | 135 | #[tauri::command] 136 | async fn values( 137 | app: AppHandle, 138 | stores: State<'_, StoreCollection>, 139 | path: PathBuf, 140 | ) -> Result, Error> { 141 | with_store(app, stores, path, |store| { 142 | Ok(store.values().cloned().collect()) 143 | }) 144 | } 145 | 146 | #[tauri::command] 147 | async fn entries( 148 | app: AppHandle, 149 | stores: State<'_, StoreCollection>, 150 | path: PathBuf, 151 | ) -> Result, Error> { 152 | with_store(app, stores, path, |store| { 153 | Ok(store 154 | .entries() 155 | .map(|(k, v)| (k.to_owned(), v.to_owned())) 156 | .collect()) 157 | }) 158 | } 159 | 160 | #[tauri::command] 161 | async fn length( 162 | app: AppHandle, 163 | stores: State<'_, StoreCollection>, 164 | path: PathBuf, 165 | ) -> Result { 166 | with_store(app, stores, path, |store| Ok(store.len())) 167 | } 168 | 169 | #[tauri::command] 170 | async fn load( 171 | app: AppHandle, 172 | stores: State<'_, StoreCollection>, 173 | path: PathBuf, 174 | ) -> Result<(), Error> { 175 | with_store(app, stores, path, |store| store.load()) 176 | } 177 | 178 | #[tauri::command] 179 | async fn save( 180 | app: AppHandle, 181 | stores: State<'_, StoreCollection>, 182 | path: PathBuf, 183 | ) -> Result<(), Error> { 184 | with_store(app, stores, path, |store| store.save()) 185 | } 186 | 187 | // #[derive(Default)] 188 | pub struct Builder { 189 | stores: HashMap>, 190 | frozen: bool, 191 | } 192 | 193 | impl Default for Builder { 194 | fn default() -> Self { 195 | Self { 196 | stores: Default::default(), 197 | frozen: false, 198 | } 199 | } 200 | } 201 | 202 | impl Builder { 203 | /// Registers a store with the plugin. 204 | /// 205 | /// # Examples 206 | /// 207 | /// ``` 208 | /// # fn main() -> Result<(), Box> { 209 | /// use tauri_plugin_store::{StoreBuilder,PluginBuilder}; 210 | /// 211 | /// let store = StoreBuilder::new("store.bin".parse()?).build(); 212 | /// 213 | /// let builder = PluginBuilder::default().store(store); 214 | /// 215 | /// # Ok(()) 216 | /// # } 217 | /// ``` 218 | pub fn store(mut self, store: Store) -> Self { 219 | self.stores.insert(store.path.clone(), store); 220 | self 221 | } 222 | 223 | /// Registers multiple stores with the plugin. 224 | /// 225 | /// # Examples 226 | /// 227 | /// ``` 228 | /// # fn main() -> Result<(), Box> { 229 | /// use tauri_plugin_store::{StoreBuilder,PluginBuilder}; 230 | /// 231 | /// let store = StoreBuilder::new("store.bin".parse()?).build(); 232 | /// 233 | /// let builder = PluginBuilder::default().stores([store]); 234 | /// 235 | /// # Ok(()) 236 | /// # } 237 | /// ``` 238 | pub fn stores>>(mut self, stores: T) -> Self { 239 | self.stores = stores 240 | .into_iter() 241 | .map(|store| (store.path.clone(), store)) 242 | .collect(); 243 | self 244 | } 245 | 246 | /// Freezes the collection. 247 | /// 248 | /// This causes requests for plugins that haven't been registered to fail 249 | /// 250 | /// # Examples 251 | /// 252 | /// ``` 253 | /// # fn main() -> Result<(), Box> { 254 | /// use tauri_plugin_store::{StoreBuilder,PluginBuilder}; 255 | /// 256 | /// let store = StoreBuilder::new("store.bin".parse()?).build(); 257 | /// 258 | /// let builder = PluginBuilder::default().freeze(); 259 | /// 260 | /// # Ok(()) 261 | /// # } 262 | /// ``` 263 | pub fn freeze(mut self) -> Self { 264 | self.frozen = true; 265 | self 266 | } 267 | 268 | /// Builds the plugin. 269 | /// 270 | /// # Examples 271 | /// 272 | /// ``` 273 | /// # fn main() -> Result<(), Box> { 274 | /// use tauri_plugin_store::{StoreBuilder,PluginBuilder}; 275 | /// use tauri::Wry; 276 | /// 277 | /// let store = StoreBuilder::new("store.bin".parse()?).build(); 278 | /// 279 | /// let plugin = PluginBuilder::default().build::(); 280 | /// 281 | /// # Ok(()) 282 | /// # } 283 | /// ``` 284 | pub fn build(mut self) -> TauriPlugin { 285 | plugin::Builder::new("store") 286 | .invoke_handler(tauri::generate_handler![ 287 | set, get, has, delete, clear, reset, keys, values, length, entries, load, save 288 | ]) 289 | .setup(move |app_handle| { 290 | for (path, store) in self.stores.iter_mut() { 291 | // ignore loading errors, just use the default 292 | if let Err(err) = store.load() { 293 | warn!( 294 | "Failed to load store {:?} from disk: {}. Falling back to default values.", 295 | path, err 296 | ); 297 | } 298 | } 299 | 300 | app_handle.manage(StoreCollection { 301 | stores: Mutex::new(self.stores), 302 | frozen: self.frozen, 303 | }); 304 | 305 | Ok(()) 306 | }) 307 | .on_event(|app_handle, event| { 308 | if let RunEvent::Exit = event { 309 | let collection = app_handle.state::>(); 310 | 311 | for store in collection.stores.lock().expect("mutex poisoned").values() { 312 | if let Err(err) = store.save() { 313 | eprintln!("failed to save store {:?} with error {:?}", store.path, err); 314 | } 315 | } 316 | } 317 | }) 318 | .build() 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /src/store.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Tauri Programme within The Commons Conservancy 2 | // SPDX-License-Identifier: Apache-2.0 3 | // SPDX-License-Identifier: MIT 4 | 5 | use crate::{ChangePayload, Error}; 6 | use serde_json::Value as JsonValue; 7 | use std::{ 8 | collections::HashMap, 9 | fs::{create_dir_all, read, File}, 10 | io::Write, 11 | path::PathBuf, 12 | }; 13 | use tauri::{AppHandle, Manager, Runtime}; 14 | 15 | type SerializeFn = 16 | fn(&HashMap) -> Result, Box>; 17 | type DeserializeFn = 18 | fn(&[u8]) -> Result, Box>; 19 | 20 | fn default_serialize( 21 | cache: &HashMap, 22 | ) -> Result, Box> { 23 | Ok(serde_json::to_vec(&cache)?) 24 | } 25 | 26 | fn default_deserialize( 27 | bytes: &[u8], 28 | ) -> Result, Box> { 29 | serde_json::from_slice(bytes).map_err(Into::into) 30 | } 31 | 32 | /// Builds a [`Store`] 33 | pub struct StoreBuilder { 34 | app: AppHandle, 35 | path: PathBuf, 36 | defaults: Option>, 37 | cache: HashMap, 38 | serialize: SerializeFn, 39 | deserialize: DeserializeFn, 40 | } 41 | 42 | impl StoreBuilder { 43 | /// Creates a new [`StoreBuilder`]. 44 | /// 45 | /// # Examples 46 | /// ``` 47 | /// # fn main() -> Result<(), Box> { 48 | /// use tauri_plugin_store::StoreBuilder; 49 | /// 50 | /// let builder = StoreBuilder::new("store.bin".parse()?); 51 | /// 52 | /// # Ok(()) 53 | /// # } 54 | /// ``` 55 | pub fn new(app: AppHandle, path: PathBuf) -> Self { 56 | Self { 57 | app, 58 | path, 59 | defaults: None, 60 | cache: Default::default(), 61 | serialize: default_serialize, 62 | deserialize: default_deserialize, 63 | } 64 | } 65 | 66 | /// Inserts a default key-value pair. 67 | /// 68 | /// # Examples 69 | /// ``` 70 | /// # fn main() -> Result<(), Box> { 71 | /// use tauri_plugin_store::StoreBuilder; 72 | /// use std::collections::HashMap; 73 | /// 74 | /// let mut defaults = HashMap::new(); 75 | /// 76 | /// defaults.insert("foo".to_string(), "bar".into()); 77 | /// 78 | /// let builder = StoreBuilder::new("store.bin".parse()?) 79 | /// .defaults(defaults); 80 | /// 81 | /// # Ok(()) 82 | /// # } 83 | pub fn defaults(mut self, defaults: HashMap) -> Self { 84 | self.cache.clone_from(&defaults); 85 | self.defaults = Some(defaults); 86 | self 87 | } 88 | 89 | /// Inserts multiple key-value pairs. 90 | /// 91 | /// # Examples 92 | /// ``` 93 | /// # fn main() -> Result<(), Box> { 94 | /// use tauri_plugin_store::StoreBuilder; 95 | /// 96 | /// let builder = StoreBuilder::new("store.bin".parse()?) 97 | /// .default("foo".to_string(), "bar".into()); 98 | /// 99 | /// # Ok(()) 100 | /// # } 101 | pub fn default(mut self, key: String, value: JsonValue) -> Self { 102 | self.cache.insert(key.clone(), value.clone()); 103 | self.defaults 104 | .get_or_insert(HashMap::new()) 105 | .insert(key, value); 106 | self 107 | } 108 | 109 | /// Defines a custom serialization function. 110 | /// 111 | /// # Examples 112 | /// ``` 113 | /// # fn main() -> Result<(), Box> { 114 | /// use tauri_plugin_store::StoreBuilder; 115 | /// 116 | /// let builder = StoreBuilder::new("store.json".parse()?) 117 | /// .serialize(|cache| serde_json::to_vec(&cache).map_err(Into::into)); 118 | /// 119 | /// # Ok(()) 120 | /// # } 121 | pub fn serialize(mut self, serialize: SerializeFn) -> Self { 122 | self.serialize = serialize; 123 | self 124 | } 125 | 126 | /// Defines a custom deserialization function 127 | /// 128 | /// # Examples 129 | /// ``` 130 | /// # fn main() -> Result<(), Box> { 131 | /// use tauri_plugin_store::StoreBuilder; 132 | /// 133 | /// let builder = StoreBuilder::new("store.json".parse()?) 134 | /// .deserialize(|bytes| serde_json::from_slice(&bytes).map_err(Into::into)); 135 | /// 136 | /// # Ok(()) 137 | /// # } 138 | pub fn deserialize(mut self, deserialize: DeserializeFn) -> Self { 139 | self.deserialize = deserialize; 140 | self 141 | } 142 | 143 | /// Builds the [`Store`]. 144 | /// 145 | /// # Examples 146 | /// ``` 147 | /// # fn main() -> Result<(), Box> { 148 | /// use tauri_plugin_store::StoreBuilder; 149 | /// 150 | /// let store = StoreBuilder::new("store.bin".parse()?).build(); 151 | /// 152 | /// # Ok(()) 153 | /// # } 154 | pub fn build(self) -> Store { 155 | Store { 156 | app: self.app, 157 | path: self.path, 158 | defaults: self.defaults, 159 | cache: self.cache, 160 | serialize: self.serialize, 161 | deserialize: self.deserialize, 162 | } 163 | } 164 | } 165 | 166 | #[derive(Clone)] 167 | pub struct Store { 168 | app: AppHandle, 169 | pub(crate) path: PathBuf, 170 | defaults: Option>, 171 | cache: HashMap, 172 | serialize: SerializeFn, 173 | deserialize: DeserializeFn, 174 | } 175 | 176 | impl Store { 177 | /// Update the store from the on-disk state 178 | pub fn load(&mut self) -> Result<(), Error> { 179 | let app_dir = self 180 | .app 181 | .path_resolver() 182 | .app_data_dir() 183 | .expect("failed to resolve app dir"); 184 | let store_path = app_dir.join(&self.path); 185 | 186 | let bytes = read(store_path)?; 187 | 188 | self.cache 189 | .extend((self.deserialize)(&bytes).map_err(Error::Deserialize)?); 190 | 191 | Ok(()) 192 | } 193 | 194 | /// Saves the store to disk 195 | pub fn save(&self) -> Result<(), Error> { 196 | let app_dir = self 197 | .app 198 | .path_resolver() 199 | .app_data_dir() 200 | .expect("failed to resolve app dir"); 201 | let store_path = app_dir.join(&self.path); 202 | 203 | create_dir_all(store_path.parent().expect("invalid store path"))?; 204 | 205 | let bytes = (self.serialize)(&self.cache).map_err(Error::Serialize)?; 206 | let mut f = File::create(&store_path)?; 207 | f.write_all(&bytes)?; 208 | 209 | Ok(()) 210 | } 211 | 212 | pub fn insert(&mut self, key: String, value: JsonValue) -> Result<(), Error> { 213 | self.cache.insert(key.clone(), value.clone()); 214 | self.app.emit_all( 215 | "store://change", 216 | ChangePayload { 217 | path: &self.path, 218 | key: &key, 219 | value: &value, 220 | }, 221 | )?; 222 | 223 | Ok(()) 224 | } 225 | 226 | pub fn get(&self, key: impl AsRef) -> Option<&JsonValue> { 227 | self.cache.get(key.as_ref()) 228 | } 229 | 230 | pub fn has(&self, key: impl AsRef) -> bool { 231 | self.cache.contains_key(key.as_ref()) 232 | } 233 | 234 | pub fn delete(&mut self, key: impl AsRef) -> Result { 235 | let flag = self.cache.remove(key.as_ref()).is_some(); 236 | if flag { 237 | self.app.emit_all( 238 | "store://change", 239 | ChangePayload { 240 | path: &self.path, 241 | key: key.as_ref(), 242 | value: &JsonValue::Null, 243 | }, 244 | )?; 245 | } 246 | Ok(flag) 247 | } 248 | 249 | pub fn clear(&mut self) -> Result<(), Error> { 250 | let keys: Vec = self.cache.keys().cloned().collect(); 251 | self.cache.clear(); 252 | for key in keys { 253 | self.app.emit_all( 254 | "store://change", 255 | ChangePayload { 256 | path: &self.path, 257 | key: &key, 258 | value: &JsonValue::Null, 259 | }, 260 | )?; 261 | } 262 | Ok(()) 263 | } 264 | 265 | pub fn reset(&mut self) -> Result<(), Error> { 266 | let has_defaults = self.defaults.is_some(); 267 | 268 | if has_defaults { 269 | if let Some(defaults) = &self.defaults { 270 | for (key, value) in &self.cache { 271 | if defaults.get(key) != Some(value) { 272 | let _ = self.app.emit_all( 273 | "store://change", 274 | ChangePayload { 275 | path: &self.path, 276 | key, 277 | value: defaults.get(key).unwrap_or(&JsonValue::Null), 278 | }, 279 | ); 280 | } 281 | } 282 | self.cache.clone_from(defaults); 283 | } 284 | Ok(()) 285 | } else { 286 | self.clear() 287 | } 288 | } 289 | 290 | pub fn keys(&self) -> impl Iterator { 291 | self.cache.keys() 292 | } 293 | 294 | pub fn values(&self) -> impl Iterator { 295 | self.cache.values() 296 | } 297 | 298 | pub fn entries(&self) -> impl Iterator { 299 | self.cache.iter() 300 | } 301 | 302 | pub fn len(&self) -> usize { 303 | self.cache.len() 304 | } 305 | 306 | pub fn is_empty(&self) -> bool { 307 | self.cache.is_empty() 308 | } 309 | } 310 | 311 | impl std::fmt::Debug for Store { 312 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 313 | f.debug_struct("Store") 314 | .field("path", &self.path) 315 | .field("defaults", &self.defaults) 316 | .field("cache", &self.cache) 317 | .finish() 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /LICENSE_APACHE-2.0: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /dist-js/index.min.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019-2023 Tauri Programme within The Commons Conservancy 2 | // SPDX-License-Identifier: Apache-2.0 3 | // SPDX-License-Identifier: MIT 4 | /** @ignore */ 5 | function uid() { 6 | return window.crypto.getRandomValues(new Uint32Array(1))[0]; 7 | } 8 | /** 9 | * Transforms a callback function to a string identifier that can be passed to the backend. 10 | * The backend uses the identifier to `eval()` the callback. 11 | * 12 | * @return A unique identifier associated with the callback function. 13 | * 14 | * @since 1.0.0 15 | */ 16 | function transformCallback(callback, once = false) { 17 | const identifier = uid(); 18 | const prop = `_${identifier}`; 19 | Object.defineProperty(window, prop, { 20 | value: (result) => { 21 | if (once) { 22 | Reflect.deleteProperty(window, prop); 23 | } 24 | return callback === null || callback === void 0 ? void 0 : callback(result); 25 | }, 26 | writable: false, 27 | configurable: true 28 | }); 29 | return identifier; 30 | } 31 | /** 32 | * Sends a message to the backend. 33 | * @example 34 | * ```typescript 35 | * import { invoke } from '@tauri-apps/api/tauri'; 36 | * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' }); 37 | * ``` 38 | * 39 | * @param cmd The command name. 40 | * @param args The optional arguments to pass to the command. 41 | * @return A promise resolving or rejecting to the backend response. 42 | * 43 | * @since 1.0.0 44 | */ 45 | async function invoke(cmd, args = {}) { 46 | return new Promise((resolve, reject) => { 47 | const callback = transformCallback((e) => { 48 | resolve(e); 49 | Reflect.deleteProperty(window, `_${error}`); 50 | }, true); 51 | const error = transformCallback((e) => { 52 | reject(e); 53 | Reflect.deleteProperty(window, `_${callback}`); 54 | }, true); 55 | window.__TAURI_IPC__({ 56 | cmd, 57 | callback, 58 | error, 59 | ...args 60 | }); 61 | }); 62 | } 63 | 64 | // Copyright 2019-2023 Tauri Programme within The Commons Conservancy 65 | // SPDX-License-Identifier: Apache-2.0 66 | // SPDX-License-Identifier: MIT 67 | /** @ignore */ 68 | async function invokeTauriCommand(command) { 69 | return invoke('tauri', command); 70 | } 71 | 72 | // Copyright 2019-2023 Tauri Programme within The Commons Conservancy 73 | // SPDX-License-Identifier: Apache-2.0 74 | // SPDX-License-Identifier: MIT 75 | /** 76 | * Unregister the event listener associated with the given name and id. 77 | * 78 | * @ignore 79 | * @param event The event name 80 | * @param eventId Event identifier 81 | * @returns 82 | */ 83 | async function _unlisten(event, eventId) { 84 | return invokeTauriCommand({ 85 | __tauriModule: 'Event', 86 | message: { 87 | cmd: 'unlisten', 88 | event, 89 | eventId 90 | } 91 | }); 92 | } 93 | /** 94 | * Listen to an event from the backend. 95 | * 96 | * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. 97 | * @param handler Event handler callback. 98 | * @return A promise resolving to a function to unlisten to the event. 99 | */ 100 | async function listen$1(event, windowLabel, handler) { 101 | return invokeTauriCommand({ 102 | __tauriModule: 'Event', 103 | message: { 104 | cmd: 'listen', 105 | event, 106 | windowLabel, 107 | handler: transformCallback(handler) 108 | } 109 | }).then((eventId) => { 110 | return async () => _unlisten(event, eventId); 111 | }); 112 | } 113 | 114 | // Copyright 2019-2023 Tauri Programme within The Commons Conservancy 115 | // SPDX-License-Identifier: Apache-2.0 116 | // SPDX-License-Identifier: MIT 117 | /** 118 | * The event system allows you to emit events to the backend and listen to events from it. 119 | * 120 | * This package is also accessible with `window.__TAURI__.event` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. 121 | * @module 122 | */ 123 | /** 124 | * @since 1.1.0 125 | */ 126 | var TauriEvent; 127 | (function (TauriEvent) { 128 | TauriEvent["WINDOW_RESIZED"] = "tauri://resize"; 129 | TauriEvent["WINDOW_MOVED"] = "tauri://move"; 130 | TauriEvent["WINDOW_CLOSE_REQUESTED"] = "tauri://close-requested"; 131 | TauriEvent["WINDOW_CREATED"] = "tauri://window-created"; 132 | TauriEvent["WINDOW_DESTROYED"] = "tauri://destroyed"; 133 | TauriEvent["WINDOW_FOCUS"] = "tauri://focus"; 134 | TauriEvent["WINDOW_BLUR"] = "tauri://blur"; 135 | TauriEvent["WINDOW_SCALE_FACTOR_CHANGED"] = "tauri://scale-change"; 136 | TauriEvent["WINDOW_THEME_CHANGED"] = "tauri://theme-changed"; 137 | TauriEvent["WINDOW_FILE_DROP"] = "tauri://file-drop"; 138 | TauriEvent["WINDOW_FILE_DROP_HOVER"] = "tauri://file-drop-hover"; 139 | TauriEvent["WINDOW_FILE_DROP_CANCELLED"] = "tauri://file-drop-cancelled"; 140 | TauriEvent["MENU"] = "tauri://menu"; 141 | TauriEvent["CHECK_UPDATE"] = "tauri://update"; 142 | TauriEvent["UPDATE_AVAILABLE"] = "tauri://update-available"; 143 | TauriEvent["INSTALL_UPDATE"] = "tauri://update-install"; 144 | TauriEvent["STATUS_UPDATE"] = "tauri://update-status"; 145 | TauriEvent["DOWNLOAD_PROGRESS"] = "tauri://update-download-progress"; 146 | })(TauriEvent || (TauriEvent = {})); 147 | /** 148 | * Listen to an event. The event can be either global or window-specific. 149 | * See {@link Event.windowLabel} to check the event source. 150 | * 151 | * @example 152 | * ```typescript 153 | * import { listen } from '@tauri-apps/api/event'; 154 | * const unlisten = await listen('error', (event) => { 155 | * console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`); 156 | * }); 157 | * 158 | * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted 159 | * unlisten(); 160 | * ``` 161 | * 162 | * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. 163 | * @param handler Event handler callback. 164 | * @returns A promise resolving to a function to unlisten to the event. 165 | * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. 166 | * 167 | * @since 1.0.0 168 | */ 169 | async function listen(event, handler) { 170 | return listen$1(event, null, handler); 171 | } 172 | 173 | // Copyright 2021 Tauri Programme within The Commons Conservancy 174 | // SPDX-License-Identifier: Apache-2.0 175 | // SPDX-License-Identifier: MIT 176 | /** 177 | * A key-value store persisted by the backend layer. 178 | */ 179 | class Store { 180 | constructor(path) { 181 | this.path = path; 182 | } 183 | /** 184 | * Inserts a key-value pair into the store. 185 | * 186 | * @param key 187 | * @param value 188 | * @returns 189 | */ 190 | async set(key, value) { 191 | return await invoke("plugin:store|set", { 192 | path: this.path, 193 | key, 194 | value, 195 | }); 196 | } 197 | /** 198 | * Returns the value for the given `key` or `null` the key does not exist. 199 | * 200 | * @param key 201 | * @returns 202 | */ 203 | async get(key) { 204 | return await invoke("plugin:store|get", { 205 | path: this.path, 206 | key, 207 | }); 208 | } 209 | /** 210 | * Returns `true` if the given `key` exists in the store. 211 | * 212 | * @param key 213 | * @returns 214 | */ 215 | async has(key) { 216 | return await invoke("plugin:store|has", { 217 | path: this.path, 218 | key, 219 | }); 220 | } 221 | /** 222 | * Removes a key-value pair from the store. 223 | * 224 | * @param key 225 | * @returns 226 | */ 227 | async delete(key) { 228 | return await invoke("plugin:store|delete", { 229 | path: this.path, 230 | key, 231 | }); 232 | } 233 | /** 234 | * Clears the store, removing all key-value pairs. 235 | * 236 | * Note: To clear the storage and reset it to it's `default` value, use `reset` instead. 237 | * @returns 238 | */ 239 | async clear() { 240 | return await invoke("plugin:store|clear", { 241 | path: this.path, 242 | }); 243 | } 244 | /** 245 | * Resets the store to it's `default` value. 246 | * 247 | * If no default value has been set, this method behaves identical to `clear`. 248 | * @returns 249 | */ 250 | async reset() { 251 | return await invoke("plugin:store|reset", { 252 | path: this.path, 253 | }); 254 | } 255 | /** 256 | * Returns a list of all key in the store. 257 | * 258 | * @returns 259 | */ 260 | async keys() { 261 | return await invoke("plugin:store|keys", { 262 | path: this.path, 263 | }); 264 | } 265 | /** 266 | * Returns a list of all values in the store. 267 | * 268 | * @returns 269 | */ 270 | async values() { 271 | return await invoke("plugin:store|values", { 272 | path: this.path, 273 | }); 274 | } 275 | /** 276 | * Returns a list of all entries in the store. 277 | * 278 | * @returns 279 | */ 280 | async entries() { 281 | return await invoke("plugin:store|entries", { 282 | path: this.path, 283 | }); 284 | } 285 | /** 286 | * Returns the number of key-value pairs in the store. 287 | * 288 | * @returns 289 | */ 290 | async length() { 291 | return await invoke("plugin:store|length", { 292 | path: this.path, 293 | }); 294 | } 295 | /** 296 | * Attempts to load the on-disk state at the stores `path` into memory. 297 | * 298 | * This method is useful if the on-disk state was edited by the user and you want to synchronize the changes. 299 | * 300 | * Note: This method does not emit change events. 301 | * @returns 302 | */ 303 | async load() { 304 | return await invoke("plugin:store|load", { 305 | path: this.path, 306 | }); 307 | } 308 | /** 309 | * Saves the store to disk at the stores `path`. 310 | * 311 | * As the store is only persisted to disk before the apps exit, changes might be lost in a crash. 312 | * This method lets you persist the store to disk whenever you deem necessary. 313 | * @returns 314 | */ 315 | async save() { 316 | return await invoke("plugin:store|save", { 317 | path: this.path, 318 | }); 319 | } 320 | /** 321 | * Listen to changes on a store key. 322 | * @param key 323 | * @param cb 324 | * @returns A promise resolving to a function to unlisten to the event. 325 | */ 326 | async onKeyChange(key, cb) { 327 | return await listen("store://change", (event) => { 328 | if (event.payload.path === this.path && event.payload.key === key) { 329 | cb(event.payload.value); 330 | } 331 | }); 332 | } 333 | /** 334 | * Listen to changes on the store. 335 | * @param cb 336 | * @returns A promise resolving to a function to unlisten to the event. 337 | */ 338 | async onChange(cb) { 339 | return await listen("store://change", (event) => { 340 | if (event.payload.path === this.path) { 341 | cb(event.payload.key, event.payload.value); 342 | } 343 | }); 344 | } 345 | } 346 | 347 | export { Store }; 348 | //# sourceMappingURL=index.min.js.map 349 | -------------------------------------------------------------------------------- /dist-js/index.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.min.js","sources":["../../../node_modules/.pnpm/@tauri-apps+api@1.6.0/node_modules/@tauri-apps/api/tauri.js","../../../node_modules/.pnpm/@tauri-apps+api@1.6.0/node_modules/@tauri-apps/api/helpers/tauri.js","../../../node_modules/.pnpm/@tauri-apps+api@1.6.0/node_modules/@tauri-apps/api/helpers/event.js","../../../node_modules/.pnpm/@tauri-apps+api@1.6.0/node_modules/@tauri-apps/api/event.js","../guest-js/index.ts"],"sourcesContent":["// Copyright 2019-2023 Tauri Programme within The Commons Conservancy\n// SPDX-License-Identifier: Apache-2.0\n// SPDX-License-Identifier: MIT\n/** @ignore */\nfunction uid() {\n return window.crypto.getRandomValues(new Uint32Array(1))[0];\n}\n/**\n * Transforms a callback function to a string identifier that can be passed to the backend.\n * The backend uses the identifier to `eval()` the callback.\n *\n * @return A unique identifier associated with the callback function.\n *\n * @since 1.0.0\n */\nfunction transformCallback(callback, once = false) {\n const identifier = uid();\n const prop = `_${identifier}`;\n Object.defineProperty(window, prop, {\n value: (result) => {\n if (once) {\n Reflect.deleteProperty(window, prop);\n }\n return callback === null || callback === void 0 ? void 0 : callback(result);\n },\n writable: false,\n configurable: true\n });\n return identifier;\n}\n/**\n * Sends a message to the backend.\n * @example\n * ```typescript\n * import { invoke } from '@tauri-apps/api/tauri';\n * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });\n * ```\n *\n * @param cmd The command name.\n * @param args The optional arguments to pass to the command.\n * @return A promise resolving or rejecting to the backend response.\n *\n * @since 1.0.0\n */\nasync function invoke(cmd, args = {}) {\n return new Promise((resolve, reject) => {\n const callback = transformCallback((e) => {\n resolve(e);\n Reflect.deleteProperty(window, `_${error}`);\n }, true);\n const error = transformCallback((e) => {\n reject(e);\n Reflect.deleteProperty(window, `_${callback}`);\n }, true);\n window.__TAURI_IPC__({\n cmd,\n callback,\n error,\n ...args\n });\n });\n}\n/**\n * Convert a device file path to an URL that can be loaded by the webview.\n * Note that `asset:` and `https://asset.localhost` must be added to [`tauri.security.csp`](https://tauri.app/v1/api/config/#securityconfig.csp) in `tauri.conf.json`.\n * Example CSP value: `\"csp\": \"default-src 'self'; img-src 'self' asset: https://asset.localhost\"` to use the asset protocol on image sources.\n *\n * Additionally, `asset` must be added to [`tauri.allowlist.protocol`](https://tauri.app/v1/api/config/#allowlistconfig.protocol)\n * in `tauri.conf.json` and its access scope must be defined on the `assetScope` array on the same `protocol` object.\n * For example:\n * ```json\n * {\n * \"tauri\": {\n * \"allowlist\": {\n * \"protocol\": {\n * \"asset\": true,\n * \"assetScope\": [\"$APPDATA/assets/*\"]\n * }\n * }\n * }\n * }\n * ```\n *\n * @param filePath The file path.\n * @param protocol The protocol to use. Defaults to `asset`. You only need to set this when using a custom protocol.\n * @example\n * ```typescript\n * import { appDataDir, join } from '@tauri-apps/api/path';\n * import { convertFileSrc } from '@tauri-apps/api/tauri';\n * const appDataDirPath = await appDataDir();\n * const filePath = await join(appDataDirPath, 'assets/video.mp4');\n * const assetUrl = convertFileSrc(filePath);\n *\n * const video = document.getElementById('my-video');\n * const source = document.createElement('source');\n * source.type = 'video/mp4';\n * source.src = assetUrl;\n * video.appendChild(source);\n * video.load();\n * ```\n *\n * @return the URL that can be used as source on the webview.\n *\n * @since 1.0.0\n */\nfunction convertFileSrc(filePath, protocol = 'asset') {\n return window.__TAURI__.convertFileSrc(filePath, protocol);\n}\n\nexport { convertFileSrc, invoke, transformCallback };\n","import { invoke } from '../tauri.js';\n\n// Copyright 2019-2023 Tauri Programme within The Commons Conservancy\n// SPDX-License-Identifier: Apache-2.0\n// SPDX-License-Identifier: MIT\n/** @ignore */\nasync function invokeTauriCommand(command) {\n return invoke('tauri', command);\n}\n\nexport { invokeTauriCommand };\n","import { invokeTauriCommand } from './tauri.js';\nimport { transformCallback } from '../tauri.js';\n\n// Copyright 2019-2023 Tauri Programme within The Commons Conservancy\n// SPDX-License-Identifier: Apache-2.0\n// SPDX-License-Identifier: MIT\n/**\n * Unregister the event listener associated with the given name and id.\n *\n * @ignore\n * @param event The event name\n * @param eventId Event identifier\n * @returns\n */\nasync function _unlisten(event, eventId) {\n return invokeTauriCommand({\n __tauriModule: 'Event',\n message: {\n cmd: 'unlisten',\n event,\n eventId\n }\n });\n}\n/**\n * Emits an event to the backend.\n *\n * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.\n * @param [windowLabel] The label of the window to which the event is sent, if null/undefined the event will be sent to all windows\n * @param [payload] Event payload\n * @returns\n */\nasync function emit(event, windowLabel, payload) {\n await invokeTauriCommand({\n __tauriModule: 'Event',\n message: {\n cmd: 'emit',\n event,\n windowLabel,\n payload\n }\n });\n}\n/**\n * Listen to an event from the backend.\n *\n * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.\n * @param handler Event handler callback.\n * @return A promise resolving to a function to unlisten to the event.\n */\nasync function listen(event, windowLabel, handler) {\n return invokeTauriCommand({\n __tauriModule: 'Event',\n message: {\n cmd: 'listen',\n event,\n windowLabel,\n handler: transformCallback(handler)\n }\n }).then((eventId) => {\n return async () => _unlisten(event, eventId);\n });\n}\n/**\n * Listen to an one-off event from the backend.\n *\n * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.\n * @param handler Event handler callback.\n * @returns A promise resolving to a function to unlisten to the event.\n */\nasync function once(event, windowLabel, handler) {\n return listen(event, windowLabel, (eventData) => {\n handler(eventData);\n _unlisten(event, eventData.id).catch(() => { });\n });\n}\n\nexport { emit, listen, once };\n","import { listen as listen$1, once as once$1, emit as emit$1 } from './helpers/event.js';\n\n// Copyright 2019-2023 Tauri Programme within The Commons Conservancy\n// SPDX-License-Identifier: Apache-2.0\n// SPDX-License-Identifier: MIT\n/**\n * The event system allows you to emit events to the backend and listen to events from it.\n *\n * This package is also accessible with `window.__TAURI__.event` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.\n * @module\n */\n/**\n * @since 1.1.0\n */\nvar TauriEvent;\n(function (TauriEvent) {\n TauriEvent[\"WINDOW_RESIZED\"] = \"tauri://resize\";\n TauriEvent[\"WINDOW_MOVED\"] = \"tauri://move\";\n TauriEvent[\"WINDOW_CLOSE_REQUESTED\"] = \"tauri://close-requested\";\n TauriEvent[\"WINDOW_CREATED\"] = \"tauri://window-created\";\n TauriEvent[\"WINDOW_DESTROYED\"] = \"tauri://destroyed\";\n TauriEvent[\"WINDOW_FOCUS\"] = \"tauri://focus\";\n TauriEvent[\"WINDOW_BLUR\"] = \"tauri://blur\";\n TauriEvent[\"WINDOW_SCALE_FACTOR_CHANGED\"] = \"tauri://scale-change\";\n TauriEvent[\"WINDOW_THEME_CHANGED\"] = \"tauri://theme-changed\";\n TauriEvent[\"WINDOW_FILE_DROP\"] = \"tauri://file-drop\";\n TauriEvent[\"WINDOW_FILE_DROP_HOVER\"] = \"tauri://file-drop-hover\";\n TauriEvent[\"WINDOW_FILE_DROP_CANCELLED\"] = \"tauri://file-drop-cancelled\";\n TauriEvent[\"MENU\"] = \"tauri://menu\";\n TauriEvent[\"CHECK_UPDATE\"] = \"tauri://update\";\n TauriEvent[\"UPDATE_AVAILABLE\"] = \"tauri://update-available\";\n TauriEvent[\"INSTALL_UPDATE\"] = \"tauri://update-install\";\n TauriEvent[\"STATUS_UPDATE\"] = \"tauri://update-status\";\n TauriEvent[\"DOWNLOAD_PROGRESS\"] = \"tauri://update-download-progress\";\n})(TauriEvent || (TauriEvent = {}));\n/**\n * Listen to an event. The event can be either global or window-specific.\n * See {@link Event.windowLabel} to check the event source.\n *\n * @example\n * ```typescript\n * import { listen } from '@tauri-apps/api/event';\n * const unlisten = await listen('error', (event) => {\n * console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`);\n * });\n *\n * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted\n * unlisten();\n * ```\n *\n * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.\n * @param handler Event handler callback.\n * @returns A promise resolving to a function to unlisten to the event.\n * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.\n *\n * @since 1.0.0\n */\nasync function listen(event, handler) {\n return listen$1(event, null, handler);\n}\n/**\n * Listen to an one-off event. See {@link listen} for more information.\n *\n * @example\n * ```typescript\n * import { once } from '@tauri-apps/api/event';\n * interface LoadedPayload {\n * loggedIn: boolean,\n * token: string\n * }\n * const unlisten = await once('loaded', (event) => {\n * console.log(`App is loaded, loggedIn: ${event.payload.loggedIn}, token: ${event.payload.token}`);\n * });\n *\n * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted\n * unlisten();\n * ```\n *\n * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.\n * @returns A promise resolving to a function to unlisten to the event.\n * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.\n *\n * @since 1.0.0\n */\nasync function once(event, handler) {\n return once$1(event, null, handler);\n}\n/**\n * Emits an event to the backend and all Tauri windows.\n * @example\n * ```typescript\n * import { emit } from '@tauri-apps/api/event';\n * await emit('frontend-loaded', { loggedIn: true, token: 'authToken' });\n * ```\n *\n * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.\n *\n * @since 1.0.0\n */\nasync function emit(event, payload) {\n return emit$1(event, undefined, payload);\n}\n\nexport { TauriEvent, emit, listen, once };\n",null],"names":["listen"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SAAS,GAAG,GAAG;AACf,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,QAAQ,EAAE,IAAI,GAAG,KAAK,EAAE;AACnD,IAAI,MAAM,UAAU,GAAG,GAAG,EAAE;AAC5B,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AACjC,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE;AACxC,QAAQ,KAAK,EAAE,CAAC,MAAM,KAAK;AAC3B,YAAY,IAAI,IAAI,EAAE;AACtB,gBAAgB,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC;AACpD,YAAY;AACZ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BAAqB,EAAE;YACzC,IAAI,EAAE,IAAI,CAAC,IAAI;AAChB,SAAA,CAAC;IACJ;AAEA;;;;;;;AAOG;AACH,IAAA,MAAM,IAAI,GAAA;AACR,QAAA,OAAO,MAAM,MAAM,CAAC,mBAAmB,EAAE;YACvC,IAAI,EAAE,IAAI,CAAC,IAAI;AAChB,SAAA,CAAC;IACJ;AAEA;;;;;;AAMG;AACH,IAAA,MAAM,IAAI,GAAA;AACR,QAAA,OAAO,MAAM,MAAM,CAAC,mBAAmB,EAAE;YACvC,IAAI,EAAE,IAAI,CAAC,IAAI;AAChB,SAAA,CAAC;IACJ;AAEA;;;;;AAKG;AACH,IAAA,MAAM,WAAW,CACf,GAAW,EACX,EAA6B,EAAA;QAE7B,OAAO,MAAM,MAAM,CAAmB,gBAAgB,EAAE,CAAC,KAAK,KAAI;AAChE,YAAA,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,GAAG,EAAE;AACjE,gBAAA,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACzB;AACF,QAAA,CAAC,CAAC;IACJ;AAEA;;;;AAIG;IACH,MAAM,QAAQ,CACZ,EAA0C,EAAA;QAE1C,OAAO,MAAM,MAAM,CAAmB,gBAAgB,EAAE,CAAC,KAAK,KAAI;YAChE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;AACpC,gBAAA,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC5C;AACF,QAAA,CAAC,CAAC;IACJ;AACD;;;;","x_google_ignoreList":[0,1,2,3]} --------------------------------------------------------------------------------