()
| 77 | } |
| 78 | |
| 79 | func (p *TimerPlayer) Start() error { |
| 80 | id := strconv.Itoa(int(time.Now().UnixMicro()))[8:] |
| 81 | conn, err := dbus.SessionBus() |
| 82 | if err != nil { |
| 83 | return fmt.Errorf("connect to session bus: %w", err) |
| 84 | } |
| 85 | |
| 86 | p.conn = conn |
| 87 | p.serviceName = fmt.Sprintf("org.mpris.MediaPlayer2.%s.run-%s", AppId, id) |
| 88 | |
| 89 | reply, err := conn.RequestName(p.serviceName, dbus.NameFlagAllowReplacement) |
| 90 | if err != nil || reply != dbus.RequestNameReplyPrimaryOwner { |
| 91 | return fmt.Errorf("request bus: %v", err) |
| 92 | } |
| 93 | |
| 94 | if err = p.exportInterfaces(); err != nil { |
| 95 | return fmt.Errorf("export interfaces: %w", err) |
| 96 | } |
| 97 | |
| 98 | p.startTime = time.Now() |
| 99 | go p.runTicker() |
| 100 | go p.emitLoop() |
| 101 | |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | func (p *TimerPlayer) Destroy() { |
| 106 | defer func() { _ = p.conn.Close() }() |
no test coverage detected