From 15fd15415305bf609bd8c66d6760ada92199ae78 Mon Sep 17 00:00:00 2001 From: zsien Date: Thu, 20 Jun 2024 16:45:49 +0800 Subject: [PATCH] fix: no logout sound Issues: linuxdeepin/developer-center#9370 --- sound-theme-player/main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sound-theme-player/main.go b/sound-theme-player/main.go index afa2ed2..73fc6fe 100644 --- a/sound-theme-player/main.go +++ b/sound-theme-player/main.go @@ -125,6 +125,9 @@ func (m *Manager) Play(theme, event, device string) *dbus.Error { go func() { m.player.Volume = cfg.Volume + if device == "" { + device = generateDevice(cfg.Card, cfg.Device) + } logger.Info("volume: ", m.player.Volume) m.doPlaySound(theme, event, device) os.Exit(0) @@ -151,10 +154,7 @@ func (m *Manager) PrepareShutdownSound(uid int) *dbus.Error { return dbusutil.ToError(err) } - device := "default" - if cfg.Card != "" && cfg.Device != "" { - device = fmt.Sprintf("plughw:CARD=%s,DEV=%s", cfg.Card, cfg.Device) - } + device := generateDevice(cfg.Card, cfg.Device) shutdownCfg.CanPlay = true shutdownCfg.Theme = cfg.Theme shutdownCfg.Event = soundutils.EventSystemShutdown @@ -166,6 +166,14 @@ func (m *Manager) PrepareShutdownSound(uid int) *dbus.Error { return dbusutil.ToError(err) } +func generateDevice(card, device string) string { + if card != "" && device != "" { + return fmt.Sprintf("plughw:CARD=%s,DEV=%s", card, device) + } + + return "default" +} + func (*Manager) GetInterfaceName() string { return dbusInterface }