removed app, reorganized logic into modules
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package frontendbindings
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// FrontendBindings contain any Go functions that are specific to the frontend only and need to be bound
|
||||
type FrontendBindings struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewFrontendBindings() (*FrontendBindings, error) {
|
||||
return &FrontendBindings{}, nil
|
||||
}
|
||||
|
||||
func (fe *FrontendBindings) Init(ctx context.Context) error {
|
||||
fe.ctx = ctx
|
||||
return nil
|
||||
}
|
||||
|
||||
// Open a directory picker
|
||||
func (fe *FrontendBindings) DirectoryPicker() (string, error) {
|
||||
runtime.LogInfo(fe.ctx, "selecting a directory")
|
||||
dir, err := runtime.OpenDirectoryDialog(
|
||||
fe.ctx,
|
||||
runtime.OpenDialogOptions{})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not open directory dialog\n%w", err)
|
||||
}
|
||||
if dir == "" {
|
||||
return "No Library Directory Selected", nil
|
||||
}
|
||||
|
||||
return dir, nil
|
||||
}
|
||||
+20
-10
@@ -3,32 +3,42 @@ package library
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"yellowjacket/backend/logging"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DirectoryPath string
|
||||
}
|
||||
|
||||
func (c *Config) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var DefaultConfig *Config = &Config{
|
||||
DirectoryPath: "",
|
||||
}
|
||||
|
||||
type Library struct {
|
||||
ctx context.Context
|
||||
Conf *Config
|
||||
conf *Config
|
||||
}
|
||||
|
||||
func GetNewLibrary(ctx context.Context, conf *Config) (*Library, error) {
|
||||
func NewLibrary(conf *Config) (*Library, error) {
|
||||
if conf == nil {
|
||||
runtime.LogInfo(ctx, fmt.Sprintf("library config is nil, using default config: %s", logging.PrettyJSON(DefaultConfig)))
|
||||
conf = DefaultConfig
|
||||
return nil, fmt.Errorf("nil config for library")
|
||||
}
|
||||
if err := conf.validate(); err != nil {
|
||||
return nil, fmt.Errorf("invalid library config %s\n%w", conf, err)
|
||||
}
|
||||
runtime.LogInfo(ctx, fmt.Sprintf("creating new library with config: %#v", conf))
|
||||
return &Library{
|
||||
ctx: ctx,
|
||||
Conf: conf,
|
||||
conf: conf,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (l *Library) Init(ctx context.Context) error {
|
||||
l.ctx = ctx
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Library) GetDir() (string, error) {
|
||||
return l.conf.DirectoryPath, nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ const (
|
||||
Stopped
|
||||
)
|
||||
|
||||
func NewPlayer() *Player {
|
||||
return &Player{}
|
||||
func NewPlayer() (*Player, error) {
|
||||
return &Player{}, nil
|
||||
}
|
||||
|
||||
func (p *Player) Init(ctx context.Context) {
|
||||
|
||||
Reference in New Issue
Block a user