@@ -57,14 +57,15 @@ type ComponentStatable interface {
57
57
// App is the central part of the application
58
58
// It contains and manages all components
59
59
type App struct {
60
- parent * App
61
- components []Component
62
- mu sync.RWMutex
63
- startStat Stat
64
- stopStat Stat
65
- deviceState int
66
- versionName string
67
- anySyncVersion string
60
+ parent * App
61
+ components []Component
62
+ mu sync.RWMutex
63
+ startStat Stat
64
+ stopStat Stat
65
+ deviceState int
66
+ versionName string
67
+ anySyncVersion string
68
+ componentListener func (comp Component )
68
69
}
69
70
70
71
// Name returns app name
@@ -130,9 +131,10 @@ func VersionDescription() string {
130
131
// It doesn't call Start on any of the parent's components
131
132
func (app * App ) ChildApp () * App {
132
133
return & App {
133
- parent : app ,
134
- deviceState : app .deviceState ,
135
- anySyncVersion : app .AnySyncVersion (),
134
+ parent : app ,
135
+ deviceState : app .deviceState ,
136
+ anySyncVersion : app .AnySyncVersion (),
137
+ componentListener : app .componentListener ,
136
138
}
137
139
}
138
140
@@ -159,6 +161,7 @@ func (app *App) Component(name string) Component {
159
161
for current != nil {
160
162
for _ , s := range current .components {
161
163
if s .Name () == name {
164
+ app .onComponent (s )
162
165
return s
163
166
}
164
167
}
@@ -184,6 +187,7 @@ func MustComponent[i any](app *App) i {
184
187
for current != nil {
185
188
for _ , s := range current .components {
186
189
if v , ok := s .(i ); ok {
190
+ app .onComponent (s )
187
191
return v
188
192
}
189
193
}
@@ -384,3 +388,9 @@ func (app *App) AnySyncVersion() string {
384
388
})
385
389
return app .anySyncVersion
386
390
}
391
+
392
+ func (app * App ) onComponent (s Component ) {
393
+ if app .componentListener != nil {
394
+ app .componentListener (s )
395
+ }
396
+ }
0 commit comments