Skip to content

Commit

Permalink
update for new SMTC dll
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jan 17, 2025
1 parent e465180 commit 9fca298
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-appimage-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
./appimage-build-compat.sh
- name: upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic-compat.AppImage
path: Supersonic-x86_64.AppImage
2 changes: 1 addition & 1 deletion .github/workflows/build-appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
./appimage-build.sh
- name: upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic.AppImage
path: Supersonic-x86_64.AppImage
2 changes: 1 addition & 1 deletion .github/workflows/build-macos-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
make zip_macos
- name: Upload package
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic.zip
path: Supersonic.zip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-macos-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ jobs:
mv Supersonic.zip Supersonic_HighSierra+.zip
- name: Upload Big Sur+ package
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic_mac_x64_BigSur+.zip
path: Supersonic_BigSur+.zip

- name: Upload High Sierra+ package
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic_mac_x64_HighSierra+.zip
path: Supersonic_HighSierra+.zip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-ubuntu-22.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: make package_linux

- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic_ubuntu_x64.tar.xz
path: Supersonic.tar.xz
2 changes: 1 addition & 1 deletion .github/workflows/build-ubuntu-24.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: make package_linux

- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic_ubuntu_x64.tar.xz
path: Supersonic.tar.xz
6 changes: 3 additions & 3 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Download smtc dll
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
run: zip Supersonic-windows.zip Supersonic.exe libmpv-2.dll SMTC.dll
Expand All @@ -66,13 +66,13 @@ jobs:
path: win_inno_installscript.iss

- name: Upload zip
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic_windows_x64.zip
path: Supersonic-windows.zip

- name: Upload installer
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Supersonic_windows_x64_installer.exe
path: Output/supersonic-installer.exe
54 changes: 36 additions & 18 deletions backend/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ type App struct {
OnReactivate func()
OnExit func()

appName string
appVersionTag string
configDir string
cacheDir string
portableMode bool
appName string
displayAppName string
appVersionTag string
configDir string
cacheDir string
portableMode bool

isFirstLaunch bool // set by config file reader
bgrndCtx context.Context
Expand Down Expand Up @@ -97,12 +98,13 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas
}

a := &App{
logFile: logFile,
appName: appName,
appVersionTag: appVersionTag,
configDir: confDir,
cacheDir: cacheDir,
portableMode: portableMode,
logFile: logFile,
appName: appName,
displayAppName: displayAppName,
appVersionTag: appVersionTag,
configDir: confDir,
cacheDir: cacheDir,
portableMode: portableMode,
}
a.bgrndCtx, a.cancel = context.WithCancel(context.Background())
a.readConfig()
Expand Down Expand Up @@ -343,6 +345,7 @@ func (a *App) SetupWindowsSMTC(hwnd uintptr) {
return
}
a.WinSMTC = smtc
smtc.UpdateMetadata(a.displayAppName, "")

smtc.OnButtonPressed(func(btn SMTCButton) {
switch btn {
Expand All @@ -364,20 +367,35 @@ func (a *App) SetupWindowsSMTC(hwnd uintptr) {

a.PlaybackManager.OnSongChange(func(nowPlaying mediaprovider.MediaItem, _ *mediaprovider.Track) {
if nowPlaying == nil {
smtc.UpdateMetadata("", "")
smtc.UpdateMetadata("Supersonic", "")
return
}
artist := strings.Join(nowPlaying.Metadata().Artists, ", ")
smtc.UpdateMetadata(nowPlaying.Metadata().Name, artist)
smtc.UpdatePosition(0, nowPlaying.Metadata().Duration*1000)
meta := nowPlaying.Metadata()
smtc.UpdateMetadata(meta.Name, strings.Join(meta.Artists, ", "))
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)

Check failure on line 379 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetThumbnail undefined (type *SMTC has no field or method SetThumbnail)

Check failure on line 379 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetThumbnail undefined (type *SMTC has no field or method SetThumbnail)

Check failure on line 379 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetThumbnail undefined (type *SMTC has no field or method SetThumbnail)

Check failure on line 379 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetThumbnail undefined (type *SMTC has no field or method SetThumbnail)
}
}()
})
a.PlaybackManager.OnSeek(func() {
dur := a.PlaybackManager.NowPlaying().Metadata().Duration
smtc.UpdatePosition(int(a.PlaybackManager.CurrentPlayer().GetStatus().TimePos*1000), dur*1000)
})
a.PlaybackManager.OnPlaying(func() { smtc.UpdatePlaybackState(SMTCPlaybackStatePlaying) })
a.PlaybackManager.OnPaused(func() { smtc.UpdatePlaybackState(SMTCPlaybackStatePaused) })
a.PlaybackManager.OnStopped(func() { smtc.UpdatePlaybackState(SMTCPlaybackStateStopped) })
a.PlaybackManager.OnPlaying(func() {
smtc.SetEnabled(true)

Check failure on line 388 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 388 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 388 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 388 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)
smtc.UpdatePlaybackState(SMTCPlaybackStatePlaying)
})
a.PlaybackManager.OnPaused(func() {
smtc.SetEnabled(true)

Check failure on line 392 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 392 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 392 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 392 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)
smtc.UpdatePlaybackState(SMTCPlaybackStatePaused)
})
a.PlaybackManager.OnStopped(func() {
smtc.SetEnabled(false)

Check failure on line 396 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 396 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 396 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)

Check failure on line 396 in backend/app.go

View workflow job for this annotation

GitHub Actions / build

smtc.SetEnabled undefined (type *SMTC has no field or method SetEnabled)
smtc.UpdatePlaybackState(SMTCPlaybackStateStopped)
})
}

func (a *App) LoginToDefaultServer(string) error {
Expand Down
9 changes: 9 additions & 0 deletions backend/imagemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ func (i *ImageManager) GetCoverArtUrl(coverID string) (string, error) {
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.
func (i *ImageManager) GetCachedArtistImage(artistID string) (image.Image, bool) {
return i.loadLocalImage(i.filePathForArtistImage(artistID))
Expand Down
56 changes: 50 additions & 6 deletions backend/smtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func (s *SMTC) UpdatePlaybackState(state SMTCPlaybackState) error {
return errors.New("SMTC DLL not available")
}

proc, err := s.dll.FindProc("UpdatePlaybackState")
proc, err := s.dll.FindProc("SetPlaybackState")
if err != nil {
return err
}

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
}
Expand All @@ -119,14 +119,14 @@ func (s *SMTC) UpdateMetadata(title, artist string) error {
return err
}

proc, err := s.dll.FindProc("UpdateMetadata")
proc, err := s.dll.FindProc("SetMetadata")
if err != nil {
return err
}

hr, _, _ := proc.Call(uintptr(unsafe.Pointer(utfTitle)), uintptr(unsafe.Pointer(utfArtist)))
if hr < 0 {
return fmt.Errorf("UpdateMetadata failed with HRESULT=%d", hr)
return fmt.Errorf("SetMetadata failed with HRESULT=%d", hr)
}
return nil
}
Expand All @@ -136,14 +136,58 @@ func (s *SMTC) UpdatePosition(positionMillis, durationMillis int) error {
return errors.New("SMTC DLL not available")
}

proc, err := s.dll.FindProc("UpdatePosition")
proc, err := s.dll.FindProc("SetPosition")
if err != nil {
return err
}

hr, _, _ := proc.Call(uintptr(positionMillis), uintptr(durationMillis))
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
}
Expand Down

0 comments on commit 9fca298

Please sign in to comment.