Skip to content

Commit

Permalink
Fix media player recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkarthik10 committed Nov 13, 2024
1 parent 32dbe19 commit 6898d58
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions PodPals/PodPalsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ struct PodPalsApp: App {

init () {
UserDefaults.registerDefaults()

let availability = MediaPlayerChecker.checkAvailability()
if availability == .neither {
DispatchQueue.main.async {
let alert = NSAlert()
alert.messageText = "No Media Player Available"
alert.informativeText = "PodPals requires either Spotify or Apple Music to be installed and running. Please launch one of these applications to use PodPals."
alert.alertStyle = .critical
alert.addButton(withTitle: "Quit")

alert.runModal()
NSApplication.shared.terminate(nil)
}
}
}

var body: some Scene {
Expand Down Expand Up @@ -104,6 +90,17 @@ class AppState: ObservableObject {
self.trackingEnabled = UserDefaults.standard.bool(forKey: "trackingEnabled")
self.mediaPlayerAvailability = MediaPlayerChecker.checkAvailability()

Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { [weak self] _ in
let availability = MediaPlayerChecker.checkAvailability()
DispatchQueue.main.async {
self?.mediaPlayerAvailability = availability

if availability == .neither {
self?.showNoMediaPlayerAlert()
}
}
}

headphoneMotionDetector.onUpdate = { [self] in
quaternion = self.headphoneMotionDetector.correctedQuaternion
}
Expand All @@ -121,7 +118,16 @@ class AppState: ObservableObject {
}
}
}

private func showNoMediaPlayerAlert() {
let alert = NSAlert()
alert.messageText = "No Media Player Available"
alert.informativeText = "PodPals requires either Spotify or Apple Music to be installed and running. Please launch one of these applications to use PodPals."
alert.alertStyle = .critical
alert.addButton(withTitle: "Quit")

alert.runModal()
NSApplication.shared.terminate(nil)
}
}

extension UserDefaults {
Expand Down

0 comments on commit 6898d58

Please sign in to comment.