@vasakgroup/plugin-config-manager 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Tauri Plugin config-manager
2
+
3
+ Un plugin de Tauri para gestionar la configuración de la aplicación de forma persistente. Permite leer y escribir un archivo de configuración y notifica a la aplicación cuando el archivo cambia externamente.
4
+
5
+ ## Plataformas Soportadas
6
+
7
+ - [ ] Windows
8
+ - [ ] macOS
9
+ - [x] Linux
10
+
11
+ El archivo de configuración se almacena en: `~/.config/vasak/vasak.conf`
12
+
13
+ ## Instalación
14
+
15
+ Añade lo siguiente a tu `Cargo.toml`:
16
+
17
+ ```toml
18
+ [dependencies]
19
+ tauri-plugin-config-manager = { git = "https://github.com/Vasak-OS/tauri-plugin-config-manager" } # O la versión de crates.io si está publicado
20
+ ```
21
+
22
+ Y registra el plugin en tu `main.rs`:
23
+
24
+ ```rust
25
+ // src-tauri/src/main.rs
26
+ fn main() {
27
+ tauri::Builder::default()
28
+ .plugin(tauri_plugin_config_manager::init())
29
+ .run(tauri::generate_context!())
30
+ .expect("error while running tauri application");
31
+ }
32
+ ```
33
+
34
+ Instala la libreria del cliente:
35
+
36
+ ```bash
37
+ bun install @vasak-group/plugin-config-manager
38
+ ```
39
+
40
+ ## Uso
41
+
42
+ El plugin expone funciones para interactuar con la configuración desde el frontend.
43
+
44
+ `App.vue`
45
+
46
+ ```vue
47
+ <script lang="ts" setup>
48
+ import { listen } from "@tauri-apps/api/event";
49
+ import { useConfigStore } from "@vasak-group/plugin-config-manager";
50
+
51
+ const configStore = useConfigStore();
52
+ let unlistenConfig: Function | null = null;
53
+
54
+ onMounted(async () => {
55
+ configStore.loadConfig();
56
+ unlistenConfig = await listen("config-changed", async () => {
57
+ configStore.loadConfig();
58
+ });
59
+ });
60
+
61
+ onUnmounted(() => {
62
+ if (unlistenConfig !== null) {
63
+ unlistenConfig();
64
+ }
65
+ });
66
+ </script>
67
+ ```
68
+
69
+ `style.css`
70
+
71
+ ```css
72
+ :root {
73
+ --primary-color: #4caf50;
74
+ --border-radius: 4px;
75
+ }
76
+ ```
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tauri-apps/api/core');
4
+ var pinia = require('pinia');
5
+ var vue = require('vue');
6
+
7
+ async function writeConfig(value) {
8
+ await core.invoke("plugin:config-manager|write_config", {
9
+ payload: JSON.stringify(value), // Serializar VSKConfig y enviarlo como 'payload'
10
+ });
11
+ }
12
+ async function readConfig() {
13
+ const jsonString = await core.invoke(// Esperar que invoke resuelva directamente con la cadena JSON
14
+ "plugin:config-manager|read_config");
15
+ if (jsonString) {
16
+ try {
17
+ return JSON.parse(jsonString); // Parsear la cadena JSON
18
+ }
19
+ catch (error) {
20
+ console.error("Failed to parse config JSON:", error, "Raw string:", jsonString);
21
+ return null;
22
+ }
23
+ }
24
+ return null;
25
+ }
26
+ const useConfigStore = pinia.defineStore("config", () => {
27
+ const config = vue.ref(null);
28
+ const loadConfig = async () => {
29
+ config.value = await readConfig();
30
+ setMode();
31
+ setProperties();
32
+ };
33
+ const setMode = () => {
34
+ if (config.value?.style?.darkmode) {
35
+ document.documentElement.classList.add("dark");
36
+ }
37
+ else {
38
+ document.documentElement.classList.remove("dark");
39
+ }
40
+ };
41
+ const setProperties = () => {
42
+ if (config.value?.style) {
43
+ const { primarycolor, radius } = config.value.style;
44
+ // Manejar primarycolor
45
+ if (primarycolor && primarycolor.trim() !== "") {
46
+ document.documentElement.style.setProperty("--primary-color", primarycolor);
47
+ }
48
+ document.documentElement.style.setProperty("--border-radius", `${radius}px`);
49
+ }
50
+ };
51
+ return {
52
+ config,
53
+ loadConfig
54
+ };
55
+ });
56
+
57
+ exports.readConfig = readConfig;
58
+ exports.useConfigStore = useConfigStore;
59
+ exports.writeConfig = writeConfig;
@@ -0,0 +1,76 @@
1
+ export declare function writeConfig(value: VSKConfig): Promise<void>;
2
+ export declare function readConfig(): Promise<VSKConfig | null>;
3
+ export type VSKConfig = {
4
+ style: {
5
+ darkmode: boolean;
6
+ primarycolor: string;
7
+ radius: number;
8
+ };
9
+ info: {
10
+ logo: string;
11
+ };
12
+ };
13
+ export declare const useConfigStore: import("pinia").StoreDefinition<"config", Pick<{
14
+ config: import("vue").Ref<{
15
+ style: {
16
+ darkmode: boolean;
17
+ primarycolor: string;
18
+ radius: number;
19
+ };
20
+ info: {
21
+ logo: string;
22
+ };
23
+ } | null, VSKConfig | {
24
+ style: {
25
+ darkmode: boolean;
26
+ primarycolor: string;
27
+ radius: number;
28
+ };
29
+ info: {
30
+ logo: string;
31
+ };
32
+ } | null>;
33
+ loadConfig: () => Promise<void>;
34
+ }, "config">, Pick<{
35
+ config: import("vue").Ref<{
36
+ style: {
37
+ darkmode: boolean;
38
+ primarycolor: string;
39
+ radius: number;
40
+ };
41
+ info: {
42
+ logo: string;
43
+ };
44
+ } | null, VSKConfig | {
45
+ style: {
46
+ darkmode: boolean;
47
+ primarycolor: string;
48
+ radius: number;
49
+ };
50
+ info: {
51
+ logo: string;
52
+ };
53
+ } | null>;
54
+ loadConfig: () => Promise<void>;
55
+ }, never>, Pick<{
56
+ config: import("vue").Ref<{
57
+ style: {
58
+ darkmode: boolean;
59
+ primarycolor: string;
60
+ radius: number;
61
+ };
62
+ info: {
63
+ logo: string;
64
+ };
65
+ } | null, VSKConfig | {
66
+ style: {
67
+ darkmode: boolean;
68
+ primarycolor: string;
69
+ radius: number;
70
+ };
71
+ info: {
72
+ logo: string;
73
+ };
74
+ } | null>;
75
+ loadConfig: () => Promise<void>;
76
+ }, "loadConfig">>;
@@ -0,0 +1,55 @@
1
+ import { invoke } from '@tauri-apps/api/core';
2
+ import { defineStore } from 'pinia';
3
+ import { ref } from 'vue';
4
+
5
+ async function writeConfig(value) {
6
+ await invoke("plugin:config-manager|write_config", {
7
+ payload: JSON.stringify(value), // Serializar VSKConfig y enviarlo como 'payload'
8
+ });
9
+ }
10
+ async function readConfig() {
11
+ const jsonString = await invoke(// Esperar que invoke resuelva directamente con la cadena JSON
12
+ "plugin:config-manager|read_config");
13
+ if (jsonString) {
14
+ try {
15
+ return JSON.parse(jsonString); // Parsear la cadena JSON
16
+ }
17
+ catch (error) {
18
+ console.error("Failed to parse config JSON:", error, "Raw string:", jsonString);
19
+ return null;
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ const useConfigStore = defineStore("config", () => {
25
+ const config = ref(null);
26
+ const loadConfig = async () => {
27
+ config.value = await readConfig();
28
+ setMode();
29
+ setProperties();
30
+ };
31
+ const setMode = () => {
32
+ if (config.value?.style?.darkmode) {
33
+ document.documentElement.classList.add("dark");
34
+ }
35
+ else {
36
+ document.documentElement.classList.remove("dark");
37
+ }
38
+ };
39
+ const setProperties = () => {
40
+ if (config.value?.style) {
41
+ const { primarycolor, radius } = config.value.style;
42
+ // Manejar primarycolor
43
+ if (primarycolor && primarycolor.trim() !== "") {
44
+ document.documentElement.style.setProperty("--primary-color", primarycolor);
45
+ }
46
+ document.documentElement.style.setProperty("--border-radius", `${radius}px`);
47
+ }
48
+ };
49
+ return {
50
+ config,
51
+ loadConfig
52
+ };
53
+ });
54
+
55
+ export { readConfig, useConfigStore, writeConfig };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@vasakgroup/plugin-config-manager",
3
+ "version": "2.0.0",
4
+ "author": "Joaquin (Pato) Decima <jdecima@vasak.net.ar>",
5
+ "description": "A tauri plugin for managing configuration in a Vue 3 application using Pinia.",
6
+ "type": "module",
7
+ "types": "./dist-js/index.d.ts",
8
+ "main": "./dist-js/index.cjs",
9
+ "module": "./dist-js/index.js",
10
+ "exports": {
11
+ "types": "./dist-js/index.d.ts",
12
+ "import": "./dist-js/index.js",
13
+ "require": "./dist-js/index.cjs"
14
+ },
15
+ "files": [
16
+ "dist-js",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "rollup -c",
21
+ "prepublishOnly": "bun run build",
22
+ "pretest": "bun run build"
23
+ },
24
+ "dependencies": {
25
+ "@tauri-apps/api": ">=2.0.0-beta.6",
26
+ "pinia": "^3.0.3",
27
+ "vue": "^3.5.16"
28
+ },
29
+ "devDependencies": {
30
+ "@rollup/plugin-typescript": "^11.1.6",
31
+ "rollup": "^4.9.6",
32
+ "typescript": "^5.3.3",
33
+ "tslib": "^2.6.2"
34
+ }
35
+ }