mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Fix jukebox mode under Windows (#2774)
* bug(core/playback/mpv): jukebox mode under windows - #2767 Use named pipe for socket path under windows during mpv playback, change function name, unexport function Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - #2767 Fix typo Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - navidrome#2767 Early return for Close on Windows Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - navidrome#2767 Update import and run prettier Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - navidrome#2767 Update function name Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - navidrome#2767 Create track_close files for both platforms and move MpvTrack Close into new file Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - navidrome#2767 Create SocketName function for both platforms, restore name of TempFileName Signed-off-by: apkatsikas <apkatsikas@gmail.com> * bug(core/playback/mpv): jukebox mode under windows - navidrome#2767 Add missing params to SocketName on windows Signed-off-by: apkatsikas <apkatsikas@gmail.com> * Unexport SocketName, use socketName in NewTrack --------- Signed-off-by: apkatsikas <apkatsikas@gmail.com>
This commit is contained in:
parent
d968f7f530
commit
c2f932c21c
6 changed files with 74 additions and 32 deletions
9
core/playback/mpv/socket_name.go
Normal file
9
core/playback/mpv/socket_name.go
Normal file
|
@ -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
core/playback/mpv/socket_name_win.go
Normal file
15
core/playback/mpv/socket_name_win.go
Normal file
|
@ -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)
|
||||||
|
}
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/dexterlb/mpvipc"
|
"github.com/dexterlb/mpvipc"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MpvTrack struct {
|
type MpvTrack struct {
|
||||||
|
@ -32,7 +31,7 @@ func NewTrack(playbackDoneChannel chan bool, deviceName string, mf model.MediaFi
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpSocketName := utils.TempFileName("mpv-ctrl-", ".socket")
|
tmpSocketName := socketName("mpv-ctrl-", ".socket")
|
||||||
|
|
||||||
args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName)
|
args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName)
|
||||||
exe, err := start(args)
|
exe, err := start(args)
|
||||||
|
@ -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 {
|
func (t *MpvTrack) isSocketFilePresent() bool {
|
||||||
if len(t.IPCSocketName) < 1 {
|
if len(t.IPCSocketName) < 1 {
|
||||||
return false
|
return false
|
||||||
|
|
38
core/playback/mpv/track_close.go
Normal file
38
core/playback/mpv/track_close.go
Normal file
|
@ -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
core/playback/mpv/track_close_win.go
Normal file
8
core/playback/mpv/track_close_win.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package mpv
|
||||||
|
|
||||||
|
func (t *MpvTrack) Close() {
|
||||||
|
// Windows automatically handles closing
|
||||||
|
// and cleaning up named pipe
|
||||||
|
}
|
|
@ -23,7 +23,9 @@ const Progress = (props) => {
|
||||||
)
|
)
|
||||||
const callbackUrl = `${window.location.origin}${callbackEndpoint}`
|
const callbackUrl = `${window.location.origin}${callbackEndpoint}`
|
||||||
openedTab.current = openInNewTab(
|
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}`,
|
||||||
)
|
)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue