Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangarelick committed May 6, 2024
1 parent a706eaf commit 27aa07c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 49 deletions.
2 changes: 1 addition & 1 deletion SoundSeer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@
9B1B0F972BE5A5B800E26B26 /* Models */,
9BD4DCE32BC9EC8B001572F7 /* PlayerViewModel.swift */,
9B1B0F922BE5A54A00E26B26 /* Primitives */,
9B2755892BE960D60007E18B /* Secrets.swift */,
9BE2FA1B2BC97CCC00A7124B /* SoundSeerApp.swift */,
9BAEAEA02BDAE6F200C85936 /* Utils.swift */,
9B1486712BD475DA00D67669 /* WindowAccessor.swift */,
9B2755892BE960D60007E18B /* Secrets.swift */,
);
path = SoundSeer;
sourceTree = "<group>";
Expand Down
51 changes: 11 additions & 40 deletions SoundSeer/Bridges/SpotifyBridge.swift
Original file line number Diff line number Diff line change
@@ -1,55 +1,26 @@
import AppKit
import ScriptingBridge

// MARK: SpotifyEPlS
@objc public enum SpotifyEPlS : AEKeyword {
case stopped = 0x6b505353 /* 'kPSS' */
case playing = 0x6b505350 /* 'kPSP' */
case paused = 0x6b505370 /* 'kPSp' */
}

// MARK: SpotifyApplication
@objc public protocol SpotifyApplication {
@objc optional var currentTrack: SpotifyTrack { get } // The current playing track.
@objc optional var soundVolume: Int { get } // The sound output volume (0 = minimum, 100 = maximum)
@objc optional var playerState: SpotifyEPlS { get } // Is Spotify stopped, paused, or playing?
@objc optional var playerPosition: Double { get } // The player’s position within the currently playing track in seconds.
@objc optional var repeatingEnabled: Bool { get } // Is repeating enabled in the current playback context?
@objc optional var repeating: Bool { get } // Is repeating on or off?
@objc optional var shufflingEnabled: Bool { get } // Is shuffling enabled in the current playback context?
@objc optional var shuffling: Bool { get } // Is shuffling on or off?
@objc optional func nextTrack() // Skip to the next track.
@objc optional func previousTrack() // Skip to the previous track.
@objc optional func playpause() // Toggle play/pause.
@objc optional func pause() // Pause playback.
@objc optional func play() // Resume playback.
@objc optional func playTrack(_ x: String!, inContext: String!) // Start playback of a track in the given context.
@objc optional func setSoundVolume(_ soundVolume: Int) // The sound output volume (0 = minimum, 100 = maximum)
@objc optional func setPlayerPosition(_ playerPosition: Double) // The player’s position within the currently playing track in seconds.
@objc optional func setRepeating(_ repeating: Bool) // Is repeating on or off?
@objc optional func setShuffling(_ shuffling: Bool) // Is shuffling on or off?
@objc optional var name: String { get } // The name of the application.
@objc optional var frontmost: Bool { get } // Is this the frontmost (active) application?
@objc optional var version: String { get } // The version of the application.
@objc optional var playerState: SpotifyEPlS { get }
@objc optional var currentTrack: SpotifyTrack { get }
@objc optional func nextTrack()
}
extension SBApplication: SpotifyApplication {}

// MARK: SpotifyTrack
@objc public protocol SpotifyTrack {
@objc optional var artist: String { get } // The artist of the track.
@objc optional var album: String { get } // The album of the track.
@objc optional var discNumber: Int { get } // The disc number of the track.
@objc optional var duration: Int { get } // The length of the track in seconds.
@objc optional var playedCount: Int { get } // The number of times this track has been played.
@objc optional var trackNumber: Int { get } // The index of the track in its album.
@objc optional var starred: Bool { get } // Is the track starred?
@objc optional var popularity: Int { get } // How popular is this track? 0-100
@objc optional func id() -> String // The ID of the item.
@objc optional var name: String { get } // The name of the track.
@objc optional var artworkUrl: String { get } // The URL of the track%apos;s album cover.
@objc optional var artwork: NSImage { get } // The property is deprecated and will never be set. Use the 'artwork url' instead.
@objc optional var albumArtist: String { get } // That album artist of the track.
@objc optional var spotifyUrl: String { get } // The URL of the track.
@objc optional func setSpotifyUrl(_ spotifyUrl: String!) // The URL of the track.
@objc optional var name: String { get }
@objc optional var artist: String { get }
@objc optional var album: String { get }

// Might need these in the future
@objc optional var spotifyUrl: String { get }
@objc optional func id() -> String
@objc optional func setSpotifyUrl(_ spotifyUrl: String!)
}
extension SBObject: SpotifyTrack {}
22 changes: 14 additions & 8 deletions SoundSeer/PlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class PlayerViewModel: ObservableObject {
private var cancellables = Set<AnyCancellable>()

init?() {
guard let spotifyModel = PlayerModel() else {
guard let playerModel = PlayerModel() else {
// Model handles logging
return nil
}

self.playerModel = spotifyModel
self.playerModel = playerModel

$isAppVisibleInMenuBar
.sink { [weak self] in
Expand All @@ -38,7 +38,7 @@ class PlayerViewModel: ObservableObject {
// FIXED BUG (#26):
// If the user manually clicks play on a song (while currently playing), Spotify will
// send a stopped and playing event in rapid succession. This prevents the UI from flickering
spotifyModel.$playerState
playerModel.$playerState
.map { playerState -> AnyPublisher<PlaybackState, Never> in
if playerState == .stopped {
return Just(playerState)
Expand All @@ -52,19 +52,19 @@ class PlayerViewModel: ObservableObject {
.assign(to: \.playerState, on: self)
.store(in: &cancellables)

spotifyModel.$currentSong
playerModel.$currentSong
.assign(to: \.currentSong, on: self)
.store(in: &cancellables)

spotifyModel.$currentSongId
playerModel.$currentSongId
.assign(to: \.currentSongId, on: self)
.store(in: &cancellables)

spotifyModel.$currentArtist
playerModel.$currentArtist
.assign(to: \.currentArtist, on: self)
.store(in: &cancellables)

spotifyModel.$currentAlbum
playerModel.$currentAlbum
.assign(to: \.currentAlbum, on: self)
.store(in: &cancellables)
}
Expand Down Expand Up @@ -110,7 +110,13 @@ class PlayerViewModel: ObservableObject {
pasteboard.declareTypes([.string], owner: nil)
pasteboard.setString("https://open.spotify.com/track/\(currentSongId)", forType: .string)
}


func copyMusicExternalURL() {
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.string], owner: nil)
// TODO: implement this
}

// MARK: - Dynamic resizing
@Published var isAppVisibleInMenuBar: Bool = false // This will trigger dynamic resizing on startup, just to be safe
@Published var prefixLength = 45
Expand Down

0 comments on commit 27aa07c

Please sign in to comment.