5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 05:19:11 +08:00
wails/v3/plugins/kvstore
Lea Anthony 5949e305ea
Reorder startup sequence
Add plugin scripts to asset server
Add InjectJS support in plugins
2023-03-24 08:43:00 +11:00
..
kvstore.go Reorder startup sequence 2023-03-24 08:43:00 +11:00
plugin.js Fix Bug with nil parameters. 2023-03-20 20:28:33 +11:00
plugin.toml Fix Bug with nil parameters. 2023-03-20 20:28:33 +11:00
README.md Fix Bug with nil parameters. 2023-03-20 20:28:33 +11:00

KVStore Plugin

This plugin provides a simple key/value store for your Wails applications.

Installation

Add the plugin to the Plugins option in the Applications options:

package main

import (
	"github.com/wailsapp/wails/v3/pkg/application"
	"github.com/wailsapp/wails/v3/plugins/kvstore"
)

func main() {
	kvstorePlugin := kvstore.NewPlugin(&kvstore.Config{
		Filename: "myapp.db",
	})
	app := application.New(application.Options{
		// ...
		Plugins: map[string]application.Plugin{
			"kvstore": kvstorePlugin,
		},
	})

Usage

Go

You can call the methods exported by the plugin directly:

    err := kvstore.Set("url", "https://www.google.com")
    if err != nil {
        // handle error
    }
    url := kvstore.Get("url").(string)
    
	// If you have not enables AutoSave, you will need to call Save() to persist the changes
    err = kvstore.Save()
    if err != nil {
        // handle error
    }

Javascript

You can call the methods from the frontend using the Plugin method:

    wails.Plugin("kvstore","Set", "url", "https://www.google.com")
    wails.Plugin("kvstore","Get", "url").then((url) => {
        
    })
    
    // or
    wails.Plugin("browser","OpenFile","/path/to/file")

Support

If you find a bug in this plugin, please raise a ticket on the Wails Issue Tracker.