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

Update: fix Use '#selector' instead of explicitly constructing a 'Selector' warning #49

Merged
merged 5 commits into from
Aug 13, 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
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## TheBoringNotch v epic.potato🥔 is Here! 🎉
## TheBoringNotch v Romantic Lady is Here! 🎉

<img width="150" src="https://github.com/user-attachments/assets/e96f6110-ffad-4d8b-a02d-ead87b7edbe1" />

Expand Down Expand Up @@ -96,7 +96,7 @@ We’re all about good vibes and awesome contributions! Here’s how you can joi

## 📝 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. Share the love, keep it free!
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

## 🎉 Acknowledgments

Expand Down
30 changes: 12 additions & 18 deletions boringNotch/managers/MusicManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
// Created by Harsh Vardhan Goswami on 03/08/24.
//


import SwiftUI
import Combine
import AppKit

class MusicManager: ObservableObject {
private var cancellables = Set<AnyCancellable>()
private var vm: BoringViewModel
@Published var songTitle: String = "I;m Handome"
@Published var songTitle: String = "I'm Handsome"
@Published var artistName: String = "Me"
@Published var albumArt: NSImage = NSImage(
systemSymbolName: "heart.fill",
Expand All @@ -29,17 +28,16 @@ class MusicManager: ObservableObject {
@Published var album: String = "Self Love"
@Published var playbackManager = PlaybackManager()
@Published var lastUpdated: Date = Date()
@Published var isPlayerIdle:Bool = false
@Published var animations:BoringAnimations = BoringAnimations()
@Published var isPlayerIdle: Bool = false
@Published var animations: BoringAnimations = BoringAnimations()
@Published var avgColor: NSColor = .white

init(vm: BoringViewModel) {
self.vm = vm;
self.vm = vm
setupNowPlayingObserver()
fetchNowPlayingInfo()
}


private func setupNowPlayingObserver() {
// every 3 seconds, fetch now playing info
Timer.publish(every: 3, on: .main, in: .common)
Expand Down Expand Up @@ -81,15 +79,14 @@ class MusicManager: ObservableObject {
typealias MRNowPlayingClientGetBundleIdentifierFunction = @convention(c) (AnyObject?) -> String
let MRNowPlayingClientGetBundleIdentifier = unsafeBitCast(MRNowPlayingClientGetBundleIdentifierPointer, to: MRNowPlayingClientGetBundleIdentifierFunction.self)


// Get song info
MRMediaRemoteGetNowPlayingInfo(DispatchQueue.main) { [weak self] information in
guard let self = self else { self?.isPlaying = false; return }

// check if the song is paused
// Check if the song is paused
if let state = information["kMRMediaRemoteNowPlayingInfoPlaybackRate"] as? Int {

// don't update lastUpdated if the song is paused and the state is same as the previous one
// Don't update lastUpdated if the song is paused and the state is the same as the previous one
if !self.isPlaying && state == 0 {
self.isPlayerIdle = true
return
Expand All @@ -109,13 +106,12 @@ class MusicManager: ObservableObject {
self.playbackManager.isPlaying = false
}

// check what app is playing media
// Check what app is playing media
if let bundleIdentifier = information["kMRMediaRemoteNowPlayingInfoClientIdentifier"] as? String {
print("App playing music: \(bundleIdentifier)")
}


// check if the song is same as the previous one
// Check if the song is the same as the previous one
if let title = information["kMRMediaRemoteNowPlayingInfoTitle"] as? String,
title == self.songTitle {
return
Expand Down Expand Up @@ -148,8 +144,10 @@ class MusicManager: ObservableObject {
// Get bundle identifier
let _MRNowPlayingClientProtobuf: AnyClass? = NSClassFromString("MRClient")
let handle: UnsafeMutableRawPointer! = dlopen("/usr/lib/libobjc.A.dylib", RTLD_NOW)
let object = unsafeBitCast(dlsym(handle, "objc_msgSend"), to: (@convention(c) (AnyClass?, Selector?) -> AnyObject).self)(_MRNowPlayingClientProtobuf, Selector(("alloc")))
unsafeBitCast(dlsym(handle, "objc_msgSend"), to: (@convention(c) (AnyObject?, Selector?, Any?) -> Void).self)(object, Selector(("initWithData:")), information["kMRMediaRemoteNowPlayingInfoClientPropertiesData"] as AnyObject?)
let allocSelector = NSSelectorFromString("alloc")
let initSelector = NSSelectorFromString("init")
let object = unsafeBitCast(dlsym(handle, "objc_msgSend"), to: (@convention(c) (AnyClass?, Selector?) -> AnyObject).self)(_MRNowPlayingClientProtobuf, allocSelector)
unsafeBitCast(dlsym(handle, "objc_msgSend"), to: (@convention(c) (AnyObject?, Selector?, Any?) -> Void).self)(object, initSelector, information["kMRMediaRemoteNowPlayingInfoClientPropertiesData"] as AnyObject?)
let bundleIdentifier = MRNowPlayingClientGetBundleIdentifier(object)
dlclose(handle)
}
Expand All @@ -171,16 +169,13 @@ class MusicManager: ObservableObject {
}
}


func updateAlbumArt(newAlbumArt: NSImage) {
withAnimation {
self.albumArt = newAlbumArt
if(vm.coloredSpectrogram) {
calculateAverageColor()
}
}


}

func calculateAverageColor() {
Expand All @@ -200,5 +195,4 @@ class MusicManager: ObservableObject {
playbackManager.previousTrack()
fetchNowPlayingInfo()
}

}