@neoskola/auto-play 0.2.6 → 0.2.7

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.
@@ -19,7 +19,7 @@ extension CPTemplate {
19
19
  initTemplate(template: self, id: id)
20
20
  }
21
21
  @objc var id: String {
22
- return (self.userInfo as? [String: Any])?["id"] as! String
22
+ return (self.userInfo as? [String: Any])?["id"] as? String ?? ""
23
23
  }
24
24
  }
25
25
 
@@ -38,11 +38,13 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
38
38
  }
39
39
 
40
40
  var topTemplateId: String? {
41
- return interfaceController.topTemplate?.id
41
+ let id = interfaceController.topTemplate?.id
42
+ return (id?.isEmpty == true) ? nil : id
42
43
  }
43
44
 
44
45
  var rootTemplateId: String? {
45
- return interfaceController.rootTemplate.id
46
+ let id = interfaceController.rootTemplate.id
47
+ return id.isEmpty ? nil : id
46
48
  }
47
49
 
48
50
  func pushTemplate(
@@ -179,6 +181,7 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
179
181
  animated: Bool
180
182
  ) {
181
183
  let templateId = aTemplate.id
184
+ guard !templateId.isEmpty else { return }
182
185
 
183
186
  TemplateStore.getTemplate(templateId: templateId)?.onWillAppear(
184
187
  animated: animated
@@ -190,6 +193,7 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
190
193
  animated: Bool
191
194
  ) {
192
195
  let templateId = aTemplate.id
196
+ guard !templateId.isEmpty else { return }
193
197
 
194
198
  if rootTemplateId == templateId {
195
199
  // this makes sure we purge outdated CPSearchTemplate since that one can be popped on with a CarPlay native button we can not intercept
@@ -206,6 +210,7 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
206
210
  animated: Bool
207
211
  ) {
208
212
  let templateId = aTemplate.id
213
+ guard !templateId.isEmpty else { return }
209
214
 
210
215
  TemplateStore.getTemplate(templateId: templateId)?.onWillDisappear(
211
216
  animated: animated
@@ -217,6 +222,7 @@ class AutoPlayInterfaceController: NSObject, CPInterfaceControllerDelegate {
217
222
  animated: Bool
218
223
  ) {
219
224
  let templateId = aTemplate.id
225
+ guard !templateId.isEmpty else { return }
220
226
 
221
227
  TemplateStore.getTemplate(templateId: templateId)?.onDidDisappear(
222
228
  animated: animated
@@ -20,12 +20,11 @@ class NowPlayingTemplate: AutoPlayTemplate {
20
20
  template = CPNowPlayingTemplate.shared
21
21
  initTemplate(template: template, id: config.id)
22
22
 
23
- setupNowPlayingButtons()
24
- updateNowPlayingInfo()
25
-
26
- if let image = config.image {
27
- loadImageAsync(image: image)
28
- }
23
+ // Do NOT call setupNowPlayingButtons(), updateNowPlayingInfo(), or loadImageAsync() here.
24
+ // This constructor runs on the JS thread (not main thread).
25
+ // CPNowPlayingTemplate.shared is a system singleton — modifying it off the main thread
26
+ // causes a thread safety crash. All UI setup is deferred to invalidate() which runs
27
+ // on @MainActor during push.
29
28
  }
30
29
 
31
30
  private func setupNowPlayingButtons() {
@@ -123,6 +122,10 @@ class NowPlayingTemplate: AutoPlayTemplate {
123
122
  func invalidate() {
124
123
  setupNowPlayingButtons()
125
124
  updateNowPlayingInfo()
125
+
126
+ if loadedImage == nil, let image = config.image {
127
+ loadImageAsync(image: image)
128
+ }
126
129
  }
127
130
 
128
131
  func onWillAppear(animated: Bool) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neoskola/auto-play",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",