5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-17 01:19:29 +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"
"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/log"
"github.com/wailsapp/wails/v3/plugins/single_instance"
@ -35,10 +34,10 @@ func main() {
Filename: "store.json",
AutoSave: true,
}),
"server": server.NewPlugin(&server.Config{
Enabled: true,
Port: 34115,
}),
//"server": server.NewPlugin(&server.Config{
// Enabled: true,
// Port: 34115,
//}),
"single_instance": single_instance.NewPlugin(&single_instance.Config{
// When true, the original app will be activated when a second instance is launched
ActivateAppOnSubsequentLaunch: true,

View File

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

View File

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

View File

@ -43,8 +43,8 @@ func NewPlugin(config *Config) *Plugin {
}
// Shutdown is called when the app is shutting down
func (p *Plugin) Shutdown() {
p.lockfile.Close()
func (p *Plugin) Shutdown() error {
return p.lockfile.Close()
}
// 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
// initialise any resources you need. You can also access the application
// instance via the app property.
func (p *Plugin) Init() error {
func (p *Plugin) Init(api application.PluginAPI) error {
var err error
lockfileName := p.config.LockFilePath + "/" + p.config.LockFileName
p.lockfile, err = CreateLockFile(lockfileName, application.Get().GetPID())

View File

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

View File

@ -1,5 +1,7 @@
package start_at_login
import "github.com/wailsapp/wails/v3/pkg/application"
type Plugin struct {
disabled bool
options Config
@ -27,7 +29,7 @@ func (p *Plugin) Name() string {
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
err := p.init()
if err != nil {