Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(core/playback/mpv): jukebox mode under windows - #2767 #2774

Merged
merged 11 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/playback/mpv/socket_name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !windows

package mpv

import "github.com/navidrome/navidrome/utils"

func socketName(prefix, suffix string) string {
return utils.TempFileName(prefix, suffix)
}
15 changes: 15 additions & 0 deletions core/playback/mpv/socket_name_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build windows

package mpv

import (
"path/filepath"

"github.com/google/uuid"
)

func socketName(prefix, suffix string) string {
// Windows needs to use a named pipe for the socket
// see https://mpv.io/manual/master#using-mpv-from-other-programs-or-scripts
return filepath.Join(`\\.\pipe\mpvsocket`, prefix+uuid.NewString()+suffix)
}
32 changes: 1 addition & 31 deletions core/playback/mpv/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/dexterlb/mpvipc"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/utils"
)

type MpvTrack struct {
Expand All @@ -32,7 +31,7 @@ func NewTrack(playbackDoneChannel chan bool, deviceName string, mf model.MediaFi
return nil, err
}

tmpSocketName := utils.TempFileName("mpv-ctrl-", ".socket")
tmpSocketName := socketName("mpv-ctrl-", ".socket")

args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName)
exe, err := start(args)
Expand Down Expand Up @@ -103,35 +102,6 @@ func (t *MpvTrack) Pause() {
}
}

func (t *MpvTrack) Close() {
log.Debug("Closing resources", "track", t)
t.CloseCalled = true
// trying to shutdown mpv process using socket
if t.isSocketFilePresent() {
log.Debug("sending shutdown command")
_, err := t.Conn.Call("quit")
if err != nil {
log.Error("Error sending quit command to mpv-ipc socket", err)

if t.Exe != nil {
log.Debug("cancelling executor")
err = t.Exe.Cancel()
if err != nil {
log.Error("Error canceling executor", err)
}
}
}
}

if t.isSocketFilePresent() {
log.Debug("Removing socketfile", "socketfile", t.IPCSocketName)
err := os.Remove(t.IPCSocketName)
if err != nil {
log.Error("Error cleaning up socketfile", "socketfile", t.IPCSocketName, err)
}
}
}

func (t *MpvTrack) isSocketFilePresent() bool {
if len(t.IPCSocketName) < 1 {
return false
Expand Down
38 changes: 38 additions & 0 deletions core/playback/mpv/track_close.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build !windows

package mpv

import (
"os"

"github.com/navidrome/navidrome/log"
)

func (t *MpvTrack) Close() {
log.Debug("Closing resources", "track", t)
t.CloseCalled = true
// trying to shutdown mpv process using socket
if t.isSocketFilePresent() {
log.Debug("sending shutdown command")
_, err := t.Conn.Call("quit")
if err != nil {
log.Error("Error sending quit command to mpv-ipc socket", err)

if t.Exe != nil {
log.Debug("cancelling executor")
err = t.Exe.Cancel()
if err != nil {
log.Error("Error canceling executor", err)
}
}
}
}

if t.isSocketFilePresent() {
log.Debug("Removing socketfile", "socketfile", t.IPCSocketName)
err := os.Remove(t.IPCSocketName)
if err != nil {
log.Error("Error cleaning up socketfile", "socketfile", t.IPCSocketName, err)
}
}
}
8 changes: 8 additions & 0 deletions core/playback/mpv/track_close_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build windows

package mpv

func (t *MpvTrack) Close() {
// Windows automatically handles closing
// and cleaning up named pipe
}
4 changes: 3 additions & 1 deletion ui/src/personal/LastfmScrobbleToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const Progress = (props) => {
)
const callbackUrl = `${window.location.origin}${callbackEndpoint}`
openedTab.current = openInNewTab(
`https://www.last.fm/api/auth/?api_key=${localStorage.getItem('lastfm-apikey')}&cb=${callbackUrl}`,
`https://www.last.fm/api/auth/?api_key=${localStorage.getItem(
'lastfm-apikey',
)}&cb=${callbackUrl}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was required to run prettier before I could push due to git hooks.

)
}, [])

Expand Down