5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-17 09:29:30 +08:00

Update plugin example

This commit is contained in:
Lea Anthony 2024-03-26 21:02:26 +11:00
parent 85b1f909a7
commit c7bd39abc7
7 changed files with 17 additions and 14 deletions

View File

@ -6,7 +6,6 @@ import (
"plugin_demo/plugins/hashes" "plugin_demo/plugins/hashes"
"github.com/wailsapp/wails/v3/pkg/application" "github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/plugins/experimental/server"
"github.com/wailsapp/wails/v3/plugins/kvstore" "github.com/wailsapp/wails/v3/plugins/kvstore"
"github.com/wailsapp/wails/v3/plugins/log" "github.com/wailsapp/wails/v3/plugins/log"
"github.com/wailsapp/wails/v3/plugins/single_instance" "github.com/wailsapp/wails/v3/plugins/single_instance"
@ -35,10 +34,10 @@ func main() {
Filename: "store.json", Filename: "store.json",
AutoSave: true, AutoSave: true,
}), }),
"server": server.NewPlugin(&server.Config{ //"server": server.NewPlugin(&server.Config{
Enabled: true, // Enabled: true,
Port: 34115, // Port: 34115,
}), //}),
"single_instance": single_instance.NewPlugin(&single_instance.Config{ "single_instance": single_instance.NewPlugin(&single_instance.Config{
// When true, the original app will be activated when a second instance is launched // When true, the original app will be activated when a second instance is launched
ActivateAppOnSubsequentLaunch: true, ActivateAppOnSubsequentLaunch: true,

View File

@ -5,6 +5,7 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"github.com/wailsapp/wails/v3/pkg/application"
) )
// ---------------- Plugin Setup ---------------- // ---------------- Plugin Setup ----------------
@ -15,13 +16,13 @@ func NewPlugin() *Plugin {
return &Plugin{} return &Plugin{}
} }
func (r *Plugin) Shutdown() {} func (r *Plugin) Shutdown() error { return nil }
func (r *Plugin) Name() string { func (r *Plugin) Name() string {
return "Hashes Plugin" return "Hashes Plugin"
} }
func (r *Plugin) Init() error { func (r *Plugin) Init(api application.PluginAPI) error {
return nil return nil
} }

View File

@ -53,7 +53,7 @@ func (kvs *KeyValueStore) Name() string {
// Init is called when the plugin is loaded. It is passed the application.App // Init is called when the plugin is loaded. It is passed the application.App
// instance. This is where you should do any setup. // instance. This is where you should do any setup.
func (kvs *KeyValueStore) Init() error { func (kvs *KeyValueStore) Init(api application.PluginAPI) error {
err := kvs.open(kvs.config.Filename) err := kvs.open(kvs.config.Filename)
if err != nil { if err != nil {
return err return err

View File

@ -57,7 +57,7 @@ func (p *Plugin) Name() string {
return "github.com/wailsapp/wails/v3/plugins/log" return "github.com/wailsapp/wails/v3/plugins/log"
} }
func (p *Plugin) Init() error { func (p *Plugin) Init(api application.PluginAPI) error {
return nil return nil
} }

View File

@ -43,8 +43,8 @@ func NewPlugin(config *Config) *Plugin {
} }
// Shutdown is called when the app is shutting down // Shutdown is called when the app is shutting down
func (p *Plugin) Shutdown() { func (p *Plugin) Shutdown() error {
p.lockfile.Close() return p.lockfile.Close()
} }
// Name returns the name of the plugin. // Name returns the name of the plugin.
@ -55,7 +55,7 @@ func (p *Plugin) Name() string {
// Init is called when the app is starting up. You can use this to // Init is called when the app is starting up. You can use this to
// initialise any resources you need. You can also access the application // initialise any resources you need. You can also access the application
// instance via the app property. // instance via the app property.
func (p *Plugin) Init() error { func (p *Plugin) Init(api application.PluginAPI) error {
var err error var err error
lockfileName := p.config.LockFilePath + "/" + p.config.LockFileName lockfileName := p.config.LockFilePath + "/" + p.config.LockFileName
p.lockfile, err = CreateLockFile(lockfileName, application.Get().GetPID()) p.lockfile, err = CreateLockFile(lockfileName, application.Get().GetPID())

View File

@ -5,6 +5,7 @@ import (
_ "embed" _ "embed"
"errors" "errors"
"fmt" "fmt"
"github.com/wailsapp/wails/v3/pkg/application"
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
"strings" "strings"
) )
@ -60,7 +61,7 @@ func (p *Plugin) Name() string {
// Init is called when the app is starting up. You can use this to // Init is called when the app is starting up. You can use this to
// initialise any resources you need. // initialise any resources you need.
func (p *Plugin) Init() error { func (p *Plugin) Init(api application.PluginAPI) error {
p.callableMethods = []string{"Execute", "Select"} p.callableMethods = []string{"Execute", "Select"}
p.js = executeselectjs p.js = executeselectjs
if p.config.CanOpenFromJS { if p.config.CanOpenFromJS {

View File

@ -1,5 +1,7 @@
package start_at_login package start_at_login
import "github.com/wailsapp/wails/v3/pkg/application"
type Plugin struct { type Plugin struct {
disabled bool disabled bool
options Config options Config
@ -27,7 +29,7 @@ func (p *Plugin) Name() string {
return "github.com/wailsapp/wails/v3/plugins/start_at_login" return "github.com/wailsapp/wails/v3/plugins/start_at_login"
} }
func (p *Plugin) Init() error { func (p *Plugin) Init(api application.PluginAPI) error {
// OS specific initialiser // OS specific initialiser
err := p.init() err := p.init()
if err != nil { if err != nil {