chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)

* chore: adjust prettier config, .gitignore and use taplo to format toml files

This brings the plugins-workspace repository to the same code style of the main tauri repo

* format toml

* ignore examples gen dir

* add .vscode/extensions.json

* remove packageManager field

* fmt

* fix audit

* taplo ignore permissions autogenerated files

* remove create dummy dist

* fix prettier workflow

* install fmt in prettier workflow

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2024-09-04 14:54:23 +03:00
committed by GitHub
parent 72c2ce82c1
commit cf4d7d4e6c
227 changed files with 2534 additions and 2505 deletions
-1
View File
@@ -1 +0,0 @@
node_modules
+3 -3
View File
@@ -10,11 +10,11 @@ repository = { workspace = true }
links = "tauri-plugin-store"
[package.metadata.docs.rs]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
[build-dependencies]
tauri-plugin = { workspace = true, features = [ "build" ] }
tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }
+9 -9
View File
@@ -60,22 +60,22 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```typescript
import { Store } from "@tauri-apps/plugin-store";
import { Store } from '@tauri-apps/plugin-store'
const store = new Store(".settings.dat");
const store = new Store('.settings.dat')
await store.set("some-key", { value: 5 });
await store.set('some-key', { value: 5 })
const val = await store.get<{ value: number }>("some-key");
const val = await store.get<{ value: number }>('some-key')
if (val) {
console.log(val);
console.log(val)
} else {
console.log("val is null");
console.log('val is null')
}
// This manually saves the store.
await store.save();
await store.save()
```
### Persisting Values
@@ -85,14 +85,14 @@ As seen above, values added to the store are not persisted between application l
You can manually save a store with:
```javascript
await store.save();
await store.save()
```
Stores are loaded automatically when used from the JavaScript bindings.
However, you can also load them manually later like so:
```javascript
await store.load();
await store.load()
```
## Usage from Rust
+1 -1
View File
@@ -20,4 +20,4 @@ We prefer to receive reports in English.
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
@@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
window.addEventListener("DOMContentLoaded", () => {
document.querySelector("#greet-form")?.addEventListener("submit", (e) => {
e.preventDefault();
});
});
window.addEventListener('DOMContentLoaded', () => {
document.querySelector('#greet-form')?.addEventListener('submit', (e) => {
e.preventDefault()
})
})
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { defineConfig } from "vite";
import { defineConfig } from 'vite'
// https://vitejs.dev/config/
export default defineConfig(async () => ({
@@ -13,9 +13,9 @@ export default defineConfig(async () => ({
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
strictPort: true
},
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
}));
envPrefix: ['VITE_', 'TAURI_']
}))
+51 -51
View File
@@ -2,23 +2,23 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
import { invoke } from "@tauri-apps/api/core";
import { invoke } from '@tauri-apps/api/core'
interface ChangePayload<T> {
path: string;
key: string;
value: T | null;
path: string
key: string
value: T | null
}
/**
* A key-value store persisted by the backend layer.
*/
export class Store {
path: string;
path: string
constructor(path: string) {
this.path = path;
this.path = path
}
/**
@@ -29,11 +29,11 @@ export class Store {
* @returns
*/
async set(key: string, value: unknown): Promise<void> {
await invoke("plugin:store|set", {
await invoke('plugin:store|set', {
path: this.path,
key,
value,
});
value
})
}
/**
@@ -43,10 +43,10 @@ export class Store {
* @returns
*/
async get<T>(key: string): Promise<T | null> {
return await invoke("plugin:store|get", {
return await invoke('plugin:store|get', {
path: this.path,
key,
});
key
})
}
/**
@@ -56,10 +56,10 @@ export class Store {
* @returns
*/
async has(key: string): Promise<boolean> {
return await invoke("plugin:store|has", {
return await invoke('plugin:store|has', {
path: this.path,
key,
});
key
})
}
/**
@@ -69,10 +69,10 @@ export class Store {
* @returns
*/
async delete(key: string): Promise<boolean> {
return await invoke("plugin:store|delete", {
return await invoke('plugin:store|delete', {
path: this.path,
key,
});
key
})
}
/**
@@ -82,9 +82,9 @@ export class Store {
* @returns
*/
async clear(): Promise<void> {
await invoke("plugin:store|clear", {
path: this.path,
});
await invoke('plugin:store|clear', {
path: this.path
})
}
/**
@@ -94,9 +94,9 @@ export class Store {
* @returns
*/
async reset(): Promise<void> {
await invoke("plugin:store|reset", {
path: this.path,
});
await invoke('plugin:store|reset', {
path: this.path
})
}
/**
@@ -105,9 +105,9 @@ export class Store {
* @returns
*/
async keys(): Promise<string[]> {
return await invoke("plugin:store|keys", {
path: this.path,
});
return await invoke('plugin:store|keys', {
path: this.path
})
}
/**
@@ -116,9 +116,9 @@ export class Store {
* @returns
*/
async values<T>(): Promise<T[]> {
return await invoke("plugin:store|values", {
path: this.path,
});
return await invoke('plugin:store|values', {
path: this.path
})
}
/**
@@ -127,9 +127,9 @@ export class Store {
* @returns
*/
async entries<T>(): Promise<Array<[key: string, value: T]>> {
return await invoke("plugin:store|entries", {
path: this.path,
});
return await invoke('plugin:store|entries', {
path: this.path
})
}
/**
@@ -138,9 +138,9 @@ export class Store {
* @returns
*/
async length(): Promise<number> {
return await invoke("plugin:store|length", {
path: this.path,
});
return await invoke('plugin:store|length', {
path: this.path
})
}
/**
@@ -152,9 +152,9 @@ export class Store {
* @returns
*/
async load(): Promise<void> {
await invoke("plugin:store|load", {
path: this.path,
});
await invoke('plugin:store|load', {
path: this.path
})
}
/**
@@ -165,9 +165,9 @@ export class Store {
* @returns
*/
async save(): Promise<void> {
await invoke("plugin:store|save", {
path: this.path,
});
await invoke('plugin:store|save', {
path: this.path
})
}
/**
@@ -180,13 +180,13 @@ export class Store {
*/
async onKeyChange<T>(
key: string,
cb: (value: T | null) => void,
cb: (value: T | null) => void
): Promise<UnlistenFn> {
return await listen<ChangePayload<T>>("store://change", (event) => {
return await listen<ChangePayload<T>>('store://change', (event) => {
if (event.payload.path === this.path && event.payload.key === key) {
cb(event.payload.value);
cb(event.payload.value)
}
});
})
}
/**
@@ -197,12 +197,12 @@ export class Store {
* @since 2.0.0
*/
async onChange<T>(
cb: (key: string, value: T | null) => void,
cb: (key: string, value: T | null) => void
): Promise<UnlistenFn> {
return await listen<ChangePayload<T>>("store://change", (event) => {
return await listen<ChangePayload<T>>('store://change', (event) => {
if (event.payload.path === this.path) {
cb(event.payload.key, event.payload.value);
cb(event.payload.key, event.payload.value)
}
});
})
}
}
+2 -2
View File
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { createConfig } from "../../shared/rollup.config.js";
import { createConfig } from '../../shared/rollup.config.js'
export default createConfig();
export default createConfig()