@@ -30,6 +30,7 @@ type App struct {
3030 client *http.Client
3131
3232 resolver *apresolve.ApResolver
33+ zeroconf *zeroconf.Zeroconf
3334
3435 deviceId string
3536 deviceType devicespb.DeviceType
@@ -129,6 +130,18 @@ func New(opts *Options) (*App, error) {
129130 return app, nil
130131}
131132
133+ func (app *App) SetDeviceName(name string) {
134+ if app.cfg.DeviceName == name {
135+ return
136+ }
137+
138+ app.cfg.DeviceName = name
139+
140+ if app.zeroconf != nil {
141+ app.zeroconf.SetDeviceName(name)
142+ }
143+ }
144+
132145// Run starts the daemon. It blocks until ctx is cancelled or an unrecoverable
133146// error occurs. The credential type configured in cfg.Credentials.Type
134147// determines which login flow is used.
@@ -306,7 +319,7 @@ func (app *App) withAppPlayer(ctx context.Context, appPlayerFunc func(context.Co
306319 return fmt.Errorf("failed getting endpoints from resolver: %w", err)
307320 }
308321
309- z , err : = zeroconf.NewZeroconf(app.log, app.cfg.ZeroconfPort, app.cfg.DeviceName, app.deviceId, app.deviceType, app.cfg.ZeroconfInterfacesToAdvertise, app.cfg.ZeroconfBackend == "avahi")
322+ app.zeroconf , err = zeroconf.NewZeroconf(app.log, app.cfg.ZeroconfPort, app.cfg.DeviceName, app.deviceId, app.deviceType, app.cfg.ZeroconfInterfacesToAdvertise, app.cfg.ZeroconfBackend == "avahi")
310323 if err != nil {
311324 return fmt.Errorf("failed initializing zeroconf: %w", err)
312325 }
@@ -325,7 +338,7 @@ func (app *App) withAppPlayer(ctx context.Context, appPlayerFunc func(context.Co
325338 apiCh = make(chan ApiRequest)
326339 go currentPlayer.Run(ctx, apiCh, app.mpris.Receive())
327340
328- z .SetCurrentUser(currentPlayer.sess.Username())
341+ app.zeroconf .SetCurrentUser(currentPlayer.sess.Username())
329342 }
330343
331344 go func() {
@@ -363,16 +376,16 @@ func (app *App) withAppPlayer(ctx context.Context, appPlayerFunc func(context.Co
363376 if err != nil {
364377 app.log.WithError(err).Errorf("failed restoring session after logout")
365378
366- z .SetCurrentUser("")
379+ app.zeroconf .SetCurrentUser("")
367380 } else if newAppPlayer == nil {
368- z .SetCurrentUser("")
381+ app.zeroconf .SetCurrentUser("")
369382 } else {
370383 apiCh = make(chan ApiRequest)
371384 currentPlayer = newAppPlayer
372385
373386 go newAppPlayer.Run(ctx, apiCh, app.mpris.Receive())
374387
375- z .SetCurrentUser(newAppPlayer.sess.Username())
388+ app.zeroconf .SetCurrentUser(newAppPlayer.sess.Username())
376389
377390 app.log.WithField("username", librespot.ObfuscateUsername(currentPlayer.sess.Username())).
378391 Debugf("restored session after logout")
@@ -381,7 +394,7 @@ func (app *App) withAppPlayer(ctx context.Context, appPlayerFunc func(context.Co
381394 }
382395 }()
383396
384- return z .Serve(func(req zeroconf.NewUserRequest) bool {
397+ return app.zeroconf .Serve(func(req zeroconf.NewUserRequest) bool {
385398 if currentPlayer != nil {
386399 currentPlayer.Close()
387400 currentPlayer = nil
0 commit comments