mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v3] Tidy up plugin init
This commit is contained in:
@@ -2,7 +2,6 @@ package browser
|
||||
|
||||
import (
|
||||
"github.com/pkg/browser"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
// ---------------- Plugin Setup ----------------
|
||||
@@ -22,7 +21,7 @@ func (p *Plugin) Name() string {
|
||||
return "github.com/wailsapp/wails/v3/plugins/browser"
|
||||
}
|
||||
|
||||
func (p *Plugin) Init(_ *application.App) error {
|
||||
func (p *Plugin) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,10 @@ package kvstore
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/logger"
|
||||
)
|
||||
|
||||
type KeyValueStore struct {
|
||||
@@ -16,7 +14,6 @@ type KeyValueStore struct {
|
||||
data map[string]any
|
||||
unsaved bool
|
||||
lock sync.RWMutex
|
||||
app *application.App
|
||||
}
|
||||
|
||||
func (kvs *KeyValueStore) InjectJS() string {
|
||||
@@ -54,8 +51,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(app *application.App) error {
|
||||
kvs.app = app
|
||||
func (kvs *KeyValueStore) Init() error {
|
||||
err := kvs.open(kvs.config.Filename)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -92,13 +88,9 @@ func (kvs *KeyValueStore) open(filename string) (err error) {
|
||||
defer func() {
|
||||
err2 := file.Close()
|
||||
if err2 != nil {
|
||||
application.Get().Logger.Error("Key/Value Store Plugin Error:", "error", err.Error())
|
||||
if err == nil {
|
||||
err = err2
|
||||
} else {
|
||||
kvs.app.Log(&logger.Message{
|
||||
Level: "error",
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -28,7 +28,6 @@ type Plugin struct {
|
||||
}
|
||||
|
||||
func NewPluginWithConfig(config *Config) *Plugin {
|
||||
|
||||
if config.Logger == nil {
|
||||
config.Logger = application.DefaultLogger()
|
||||
}
|
||||
@@ -52,8 +51,7 @@ func (p *Plugin) Name() string {
|
||||
return "github.com/wailsapp/wails/v3/plugins/log"
|
||||
}
|
||||
|
||||
func (p *Plugin) Init(app *application.App) error {
|
||||
p.app = app
|
||||
func (p *Plugin) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ func (p *Plugin) Name() string {
|
||||
return "github.com/wailsapp/wails/v3/plugins/oauth"
|
||||
}
|
||||
|
||||
func (p *Plugin) Init(_ *application.App) error {
|
||||
func (p *Plugin) Init() error {
|
||||
|
||||
store := sessions.NewCookieStore([]byte(p.config.SessionSecret))
|
||||
store.MaxAge(p.config.MaxAge)
|
||||
|
||||
@@ -16,7 +16,6 @@ type Config struct {
|
||||
|
||||
type Plugin struct {
|
||||
config *Config
|
||||
app *application.App
|
||||
lockfile *os.File
|
||||
}
|
||||
|
||||
@@ -55,12 +54,10 @@ 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(app *application.App) error {
|
||||
p.app = app
|
||||
|
||||
func (p *Plugin) Init() error {
|
||||
var err error
|
||||
lockfileName := p.config.LockFilePath + "/" + p.config.LockFileName
|
||||
p.lockfile, err = CreateLockFile(lockfileName, p.app.GetPID())
|
||||
p.lockfile, err = CreateLockFile(lockfileName, application.Get().GetPID())
|
||||
if err != nil {
|
||||
if p.config.ActivateAppOnSubsequentLaunch {
|
||||
pid, err := GetLockFilePid(lockfileName)
|
||||
|
||||
@@ -15,7 +15,6 @@ func enumWindowsProc(hwnd syscall.Handle, lParam uintptr) uintptr {
|
||||
if uint32(processID) == targetProcessID {
|
||||
// Bring the window forward
|
||||
w32.SetForegroundWindow(w32.HWND(hwnd))
|
||||
println("Found window: ", hwnd)
|
||||
}
|
||||
|
||||
// Continue enumeration
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
_ "modernc.org/sqlite"
|
||||
"strings"
|
||||
)
|
||||
@@ -33,7 +32,6 @@ type Config struct {
|
||||
|
||||
type Plugin struct {
|
||||
config *Config
|
||||
app *application.App
|
||||
conn *sql.DB
|
||||
callableMethods []string
|
||||
js string
|
||||
@@ -60,10 +58,8 @@ 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(app *application.App) error {
|
||||
p.app = app
|
||||
// initialise any resources you need.
|
||||
func (p *Plugin) Init() error {
|
||||
p.callableMethods = []string{"Execute", "Select"}
|
||||
p.js = executeselectjs
|
||||
if p.config.CanOpenFromJS {
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package start_at_login
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
app *application.App
|
||||
disabled bool
|
||||
options Config
|
||||
}
|
||||
@@ -32,8 +27,7 @@ func (p *Plugin) Name() string {
|
||||
return "github.com/wailsapp/wails/v3/plugins/start_at_login"
|
||||
}
|
||||
|
||||
func (p *Plugin) Init(app *application.App) error {
|
||||
p.app = app
|
||||
func (p *Plugin) Init() error {
|
||||
// OS specific initialiser
|
||||
err := p.init()
|
||||
if err != nil {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/samber/lo"
|
||||
"github.com/wailsapp/wails/v3/pkg/logger"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/mac"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -17,10 +17,7 @@ import (
|
||||
func (p *Plugin) init() error {
|
||||
bundleID := mac.GetBundleID()
|
||||
if bundleID == "" {
|
||||
p.app.Log(&logger.Message{
|
||||
Level: "INFO",
|
||||
Message: "Application is not in bundle. StartAtLogin will not work.",
|
||||
})
|
||||
application.Get().Logger.Warn("StartAtLogin Plugin: Application is not in bundle. StartAtLogin will not work.")
|
||||
p.disabled = true
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user