Skip to content

Commit

Permalink
fix: connect to pulseaudio timeout
Browse files Browse the repository at this point in the history
Waiting for the services to active

Bug: https://pms.uniontech.com/bug-view-275185.html
  • Loading branch information
zsien committed Oct 11, 2024
1 parent 37a294a commit 8f702f3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion audio1/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@ func startAudioServer(service *dbusutil.Service) error {
}
}

var wg sync.WaitGroup
sessionBus, err := dbus.SessionBus()
if err != nil {
return err
}
sigLoop := dbusutil.NewSignalLoop(sessionBus, 10)
sigLoop.Start()
defer sigLoop.Stop()

for _, activeService := range activeServices {
activeServicePath, err := systemd.GetUnit(0, activeService)
if err == nil {
Expand All @@ -423,13 +432,29 @@ func startAudioServer(service *dbusutil.Service) error {
return err
}

wg.Add(1)
actived := false
serverSystemdUnit.InitSignalExt(sigLoop, true)
serverSystemdUnit.Unit().ActiveState().ConnectChanged(func(hasValue bool, value string) {
if !hasValue {
return
}

if value == "active" && !actived {
wg.Done()
}
})

state, err := serverSystemdUnit.Unit().ActiveState().Get(0)
if err != nil {
logger.Warning("failed to get audio server active state", err)
return err
}

if state != "active" {
if state == "active" {
actived = true
wg.Done()
} else {
go func() {
_, err := serverSystemdUnit.Unit().Start(0, "replace")
if err != nil {
Expand All @@ -441,6 +466,7 @@ func startAudioServer(service *dbusutil.Service) error {

}
}
wg.Wait()

return nil
}
Expand Down

0 comments on commit 8f702f3

Please sign in to comment.