Skip to content

Support Tauri(Store Plugin) #748

@hairyf

Description

@hairyf

Describe the feature

import type { StoreOptions } from '@tauri-apps/plugin-store'
import { Store } from '@tauri-apps/plugin-store'
import { defineDriver } from 'unstorage'

export interface TauriStorageDriverOptions {
  path: string
  options?: StoreOptions
}

export const tauriStorageDriver = defineDriver<TauriStorageDriverOptions | undefined, never>(({ path, options }) => {
  const promise = Store.load(path, options)
  return {
    name: 'tauri-storage',
    options,
    async hasItem(key) {
      return promise.then(store => store.has(key))
    },
    async getItem(key) {
      return promise.then(store => store.get(key))
    },
    async setItem(key, value) {
      return promise.then(store => store.set(key, value))
    },
    async removeItem(key) {
      await promise.then(store => store.delete(key))
    },
    async getKeys() {
      return promise.then(store => store.keys())
    },
    async clear() {
      return promise.then(store => store.clear())
    },
    async watch(callback) {
      return promise.then(store => store.onChange(key => callback('update', key)))
    }
  }
})

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions