-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.go
78 lines (69 loc) · 1.87 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"github.com/StarAurryon/lpedit-lib/controller"
"github.com/StarAurryon/lpedit-lib/model/pod"
"github.com/StarAurryon/lpedit-lib/status"
"github.com/StarAurryon/lpedit/model"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
controller.Controller
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{
Controller: controller.New(),
}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
a.SetNotify(a.notif)
}
func (a *App) notif(n status.St, obj interface{}, err error) {
switch n {
case status.ActiveChange:
runtime.EventsEmit(a.ctx, "activeChange")
case status.NormalStart:
runtime.EventsEmit(a.ctx, "start")
case status.NormalStop:
runtime.EventsEmit(a.ctx, "stop")
case status.ErrorStop:
runtime.EventsEmit(a.ctx, "stop", err.Error())
case status.InitDone:
runtime.EventsEmit(a.ctx, "initDone")
case status.ParameterChange:
runtime.EventsEmit(a.ctx, "parameterChange", func() interface{} {
obj := obj.(pod.Parameter)
obj.LockData()
defer obj.UnlockData()
return model.ToParameter(obj)
}())
case status.PresetLoad:
fallthrough
case status.PresetChange:
runtime.EventsEmit(a.ctx, "presetChange", func() interface{} {
obj := obj.(*pod.Preset)
obj.LockData()
defer obj.UnlockData()
return model.ToPreset(obj)
}())
case status.Progress:
runtime.EventsEmit(a.ctx, "statusProgress", obj.(int))
case status.SetLoad:
fallthrough
case status.SetChange:
runtime.EventsEmit(a.ctx, "setChange", func() interface{} {
obj := obj.(*pod.Set)
obj.LockData()
defer obj.UnlockData()
return model.ToSet(obj)
}())
// case status.TypeChange:
// runtime.EventsEmit(a.ctx, "typeChange", obj.(pod.PedalBoardItem))
}
}