@neoskola/auto-play 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -51,13 +51,14 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
|
|
|
51
51
|
_ templateToPush: CPTemplate,
|
|
52
52
|
animated: Bool
|
|
53
53
|
) async throws -> Bool {
|
|
54
|
-
// CPNowPlayingTemplate
|
|
54
|
+
// CPNowPlayingTemplate.shared must NEVER be pushed via pushTemplate().
|
|
55
|
+
// Apple's CarPlay framework throws an uncatchable NSException (Objective-C)
|
|
56
|
+
// when attempting to push this singleton. The Now Playing UI appears
|
|
57
|
+
// automatically when MPNowPlayingInfoCenter is configured and playbackState
|
|
58
|
+
// is set to .playing.
|
|
55
59
|
if templateToPush is CPNowPlayingTemplate {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
print("[AutoPlay] CPNowPlayingTemplate already in stack, skipping push")
|
|
59
|
-
return true
|
|
60
|
-
}
|
|
60
|
+
print("[AutoPlay] CPNowPlayingTemplate cannot be pushed — skipping. Configure MPNowPlayingInfoCenter instead.")
|
|
61
|
+
return true
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
return try await interfaceController.pushTemplate(
|
|
@@ -20,11 +20,18 @@ class NowPlayingTemplate: AutoPlayTemplate {
|
|
|
20
20
|
template = CPNowPlayingTemplate.shared
|
|
21
21
|
initTemplate(template: template, id: config.id)
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
23
|
+
// Constructor runs on the JS thread. Dispatch all CarPlay UI setup to main thread.
|
|
24
|
+
// CPNowPlayingTemplate.shared is Apple's singleton — must be modified on main thread.
|
|
25
|
+
// This also ensures MPNowPlayingInfoCenter and MPRemoteCommandCenter are configured
|
|
26
|
+
// even if push() is never called (CarPlay shows "Now Playing" bar automatically).
|
|
27
|
+
DispatchQueue.main.async { [weak self] in
|
|
28
|
+
guard let self = self else { return }
|
|
29
|
+
self.setupNowPlayingButtons()
|
|
30
|
+
self.updateNowPlayingInfo()
|
|
31
|
+
if let image = config.image {
|
|
32
|
+
self.loadImageAsync(image: image)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
private func setupNowPlayingButtons() {
|