update for new SMTC dll

This commit is contained in:
Drew Weymouth
2025-01-16 18:40:06 -08:00
parent e465180f3d
commit 9fca298a82
10 changed files with 105 additions and 34 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ jobs:
./appimage-build-compat.sh ./appimage-build-compat.sh
- name: upload artifact - name: upload artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic-compat.AppImage name: Supersonic-compat.AppImage
path: Supersonic-x86_64.AppImage path: Supersonic-x86_64.AppImage
+1 -1
View File
@@ -32,7 +32,7 @@ jobs:
./appimage-build.sh ./appimage-build.sh
- name: upload artifact - name: upload artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic.AppImage name: Supersonic.AppImage
path: Supersonic-x86_64.AppImage path: Supersonic-x86_64.AppImage
+1 -1
View File
@@ -44,7 +44,7 @@ jobs:
make zip_macos make zip_macos
- name: Upload package - name: Upload package
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic.zip name: Supersonic.zip
path: Supersonic.zip path: Supersonic.zip
+2 -2
View File
@@ -49,13 +49,13 @@ jobs:
mv Supersonic.zip Supersonic_HighSierra+.zip mv Supersonic.zip Supersonic_HighSierra+.zip
- name: Upload Big Sur+ package - name: Upload Big Sur+ package
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic_mac_x64_BigSur+.zip name: Supersonic_mac_x64_BigSur+.zip
path: Supersonic_BigSur+.zip path: Supersonic_BigSur+.zip
- name: Upload High Sierra+ package - name: Upload High Sierra+ package
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic_mac_x64_HighSierra+.zip name: Supersonic_mac_x64_HighSierra+.zip
path: Supersonic_HighSierra+.zip path: Supersonic_HighSierra+.zip
+1 -1
View File
@@ -33,7 +33,7 @@ jobs:
run: make package_linux run: make package_linux
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic_ubuntu_x64.tar.xz name: Supersonic_ubuntu_x64.tar.xz
path: Supersonic.tar.xz path: Supersonic.tar.xz
+1 -1
View File
@@ -33,7 +33,7 @@ jobs:
run: make package_linux run: make package_linux
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic_ubuntu_x64.tar.xz name: Supersonic_ubuntu_x64.tar.xz
path: Supersonic.tar.xz path: Supersonic.tar.xz
+3 -3
View File
@@ -55,7 +55,7 @@ jobs:
- name: Download smtc dll - name: Download smtc dll
run: > run: >
wget https://github.com/supersonic-app/smtc-dll/releases/download/v0.0.1/SMTC.dll wget https://github.com/supersonic-app/smtc-dll/releases/download/v0.1.0/SMTC.dll
- name: Generate zip bundle - name: Generate zip bundle
run: zip Supersonic-windows.zip Supersonic.exe libmpv-2.dll SMTC.dll run: zip Supersonic-windows.zip Supersonic.exe libmpv-2.dll SMTC.dll
@@ -66,13 +66,13 @@ jobs:
path: win_inno_installscript.iss path: win_inno_installscript.iss
- name: Upload zip - name: Upload zip
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic_windows_x64.zip name: Supersonic_windows_x64.zip
path: Supersonic-windows.zip path: Supersonic-windows.zip
- name: Upload installer - name: Upload installer
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: Supersonic_windows_x64_installer.exe name: Supersonic_windows_x64_installer.exe
path: Output/supersonic-installer.exe path: Output/supersonic-installer.exe
+25 -7
View File
@@ -54,6 +54,7 @@ type App struct {
OnExit func() OnExit func()
appName string appName string
displayAppName string
appVersionTag string appVersionTag string
configDir string configDir string
cacheDir string cacheDir string
@@ -99,6 +100,7 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas
a := &App{ a := &App{
logFile: logFile, logFile: logFile,
appName: appName, appName: appName,
displayAppName: displayAppName,
appVersionTag: appVersionTag, appVersionTag: appVersionTag,
configDir: confDir, configDir: confDir,
cacheDir: cacheDir, cacheDir: cacheDir,
@@ -343,6 +345,7 @@ func (a *App) SetupWindowsSMTC(hwnd uintptr) {
return return
} }
a.WinSMTC = smtc a.WinSMTC = smtc
smtc.UpdateMetadata(a.displayAppName, "")
smtc.OnButtonPressed(func(btn SMTCButton) { smtc.OnButtonPressed(func(btn SMTCButton) {
switch btn { switch btn {
@@ -364,20 +367,35 @@ func (a *App) SetupWindowsSMTC(hwnd uintptr) {
a.PlaybackManager.OnSongChange(func(nowPlaying mediaprovider.MediaItem, _ *mediaprovider.Track) { a.PlaybackManager.OnSongChange(func(nowPlaying mediaprovider.MediaItem, _ *mediaprovider.Track) {
if nowPlaying == nil { if nowPlaying == nil {
smtc.UpdateMetadata("", "") smtc.UpdateMetadata("Supersonic", "")
return return
} }
artist := strings.Join(nowPlaying.Metadata().Artists, ", ") meta := nowPlaying.Metadata()
smtc.UpdateMetadata(nowPlaying.Metadata().Name, artist) smtc.UpdateMetadata(meta.Name, strings.Join(meta.Artists, ", "))
smtc.UpdatePosition(0, nowPlaying.Metadata().Duration*1000) smtc.UpdatePosition(0, meta.Duration*1000)
go func() {
a.ImageManager.GetCoverThumbnail(meta.CoverArtID) // ensure image is cached locally
if path, err := a.ImageManager.GetCoverArtPath(meta.CoverArtID); err == nil {
smtc.SetThumbnail(path)
}
}()
}) })
a.PlaybackManager.OnSeek(func() { a.PlaybackManager.OnSeek(func() {
dur := a.PlaybackManager.NowPlaying().Metadata().Duration dur := a.PlaybackManager.NowPlaying().Metadata().Duration
smtc.UpdatePosition(int(a.PlaybackManager.CurrentPlayer().GetStatus().TimePos*1000), dur*1000) smtc.UpdatePosition(int(a.PlaybackManager.CurrentPlayer().GetStatus().TimePos*1000), dur*1000)
}) })
a.PlaybackManager.OnPlaying(func() { smtc.UpdatePlaybackState(SMTCPlaybackStatePlaying) }) a.PlaybackManager.OnPlaying(func() {
a.PlaybackManager.OnPaused(func() { smtc.UpdatePlaybackState(SMTCPlaybackStatePaused) }) smtc.SetEnabled(true)
a.PlaybackManager.OnStopped(func() { smtc.UpdatePlaybackState(SMTCPlaybackStateStopped) }) smtc.UpdatePlaybackState(SMTCPlaybackStatePlaying)
})
a.PlaybackManager.OnPaused(func() {
smtc.SetEnabled(true)
smtc.UpdatePlaybackState(SMTCPlaybackStatePaused)
})
a.PlaybackManager.OnStopped(func() {
smtc.SetEnabled(false)
smtc.UpdatePlaybackState(SMTCPlaybackStateStopped)
})
} }
func (a *App) LoginToDefaultServer(string) error { func (a *App) LoginToDefaultServer(string) error {
+9
View File
@@ -160,6 +160,15 @@ func (i *ImageManager) GetCoverArtUrl(coverID string) (string, error) {
return "", errors.New("cover not found") return "", errors.New("cover not found")
} }
// GetCoverArtURL returns the file path for the locally cached cover thumbnail, if it exists.
func (i *ImageManager) GetCoverArtPath(coverID string) (string, error) {
path := i.filePathForCover(coverID)
if _, err := os.Stat(path); err == nil {
return path, nil
}
return "", errors.New("cover not found")
}
// GetCachedArtistImage returns the artist image for the given artistID from the on-disc cache, if it exists. // GetCachedArtistImage returns the artist image for the given artistID from the on-disc cache, if it exists.
func (i *ImageManager) GetCachedArtistImage(artistID string) (image.Image, bool) { func (i *ImageManager) GetCachedArtistImage(artistID string) (image.Image, bool) {
return i.loadLocalImage(i.filePathForArtistImage(artistID)) return i.loadLocalImage(i.filePathForArtistImage(artistID))
+50 -6
View File
@@ -93,13 +93,13 @@ func (s *SMTC) UpdatePlaybackState(state SMTCPlaybackState) error {
return errors.New("SMTC DLL not available") return errors.New("SMTC DLL not available")
} }
proc, err := s.dll.FindProc("UpdatePlaybackState") proc, err := s.dll.FindProc("SetPlaybackState")
if err != nil { if err != nil {
return err return err
} }
if hr, _, _ := proc.Call(uintptr(state)); hr < 0 { if hr, _, _ := proc.Call(uintptr(state)); hr < 0 {
return fmt.Errorf("UpdatePlaybackState failed with HRESULT=%d", hr) return fmt.Errorf("SetPlaybackState failed with HRESULT=%d", hr)
} }
return nil return nil
} }
@@ -119,14 +119,14 @@ func (s *SMTC) UpdateMetadata(title, artist string) error {
return err return err
} }
proc, err := s.dll.FindProc("UpdateMetadata") proc, err := s.dll.FindProc("SetMetadata")
if err != nil { if err != nil {
return err return err
} }
hr, _, _ := proc.Call(uintptr(unsafe.Pointer(utfTitle)), uintptr(unsafe.Pointer(utfArtist))) hr, _, _ := proc.Call(uintptr(unsafe.Pointer(utfTitle)), uintptr(unsafe.Pointer(utfArtist)))
if hr < 0 { if hr < 0 {
return fmt.Errorf("UpdateMetadata failed with HRESULT=%d", hr) return fmt.Errorf("SetMetadata failed with HRESULT=%d", hr)
} }
return nil return nil
} }
@@ -136,14 +136,58 @@ func (s *SMTC) UpdatePosition(positionMillis, durationMillis int) error {
return errors.New("SMTC DLL not available") return errors.New("SMTC DLL not available")
} }
proc, err := s.dll.FindProc("UpdatePosition") proc, err := s.dll.FindProc("SetPosition")
if err != nil { if err != nil {
return err return err
} }
hr, _, _ := proc.Call(uintptr(positionMillis), uintptr(durationMillis)) hr, _, _ := proc.Call(uintptr(positionMillis), uintptr(durationMillis))
if hr < 0 { if hr < 0 {
return fmt.Errorf("UpdatePosition failed with HRESULT=%d", hr) return fmt.Errorf("SetPosition failed with HRESULT=%d", hr)
}
return nil
}
func (s *SMTC) SetThumbnail(filepath string) error {
if s.dll == nil {
return errors.New("SMTC DLL not available")
}
proc, err := s.dll.FindProc("SetThumbnailPath")
if err != nil {
return err
}
utfPath, err := windows.UTF16PtrFromString(filepath)
if err != nil {
return err
}
hr, _, _ := proc.Call(uintptr(unsafe.Pointer(utfPath)))
if hr < 0 {
return fmt.Errorf("SetThumbnailPath failed with HRESULT=%d", hr)
}
return nil
}
func (s *SMTC) SetEnabled(enabled bool) error {
if s.dll == nil {
return errors.New("SMTC DLL not available")
}
proc, err := s.dll.FindProc("SetEnabled")
if err != nil {
return err
}
var arg uintptr = 0
if enabled {
arg = 1
}
hr, _, _ := proc.Call(arg)
if hr < 0 {
return fmt.Errorf("SetEnabled failed with HRESULT=%d", hr)
} }
return nil return nil
} }