@iternio/react-native-auto-play 0.5.0 → 0.5.1

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.
@@ -0,0 +1,5 @@
1
+ package com.margelo.nitro.swe.iternio.reactnativeautoplay
2
+
3
+ class TemplateNotFoundException(templateId: String): Exception(templateId) {
4
+ override fun toString(): String = "templateNotFound($message)"
5
+ }
@@ -100,7 +100,7 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
100
100
  override fun setRootTemplate(templateId: String): Promise<Unit> {
101
101
  return Promise.async {
102
102
  val template = AndroidAutoTemplate.getTemplate(templateId)
103
- ?: throw IllegalArgumentException("setRootTemplate failed, $templateId template not found")
103
+ ?: throw TemplateNotFoundException(templateId)
104
104
 
105
105
  if (template.isRenderTemplate) {
106
106
  val screen = AndroidAutoScreen.getScreen(templateId)
@@ -148,7 +148,7 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
148
148
  val context = AndroidAutoSession.getRootContext()
149
149
  ?: throw IllegalArgumentException("pushTemplate failed, carContext not found")
150
150
  val template = AndroidAutoTemplate.getTemplate(templateId)
151
- ?: throw IllegalArgumentException("pushTemplate failed, template $templateId not found")
151
+ ?: throw TemplateNotFoundException(templateId)
152
152
  val screenManager = AndroidAutoScreen.getScreenManager()
153
153
  ?: throw IllegalArgumentException("pushTemplate failed, screenManager not found")
154
154
 
@@ -5,6 +5,7 @@ import androidx.car.app.Screen
5
5
  import androidx.car.app.model.Template
6
6
  import com.margelo.nitro.swe.iternio.reactnativeautoplay.AndroidAutoScreen
7
7
  import com.margelo.nitro.swe.iternio.reactnativeautoplay.NitroAction
8
+ import com.margelo.nitro.swe.iternio.reactnativeautoplay.TemplateNotFoundException
8
9
  import java.util.concurrent.ConcurrentHashMap
9
10
 
10
11
  abstract class AndroidAutoTemplate<T>(val context: CarContext, var config: T) {
@@ -31,7 +32,7 @@ abstract class AndroidAutoTemplate<T>(val context: CarContext, var config: T) {
31
32
  val templates = ConcurrentHashMap<String, AndroidAutoTemplate<*>>()
32
33
 
33
34
  fun <T> setTemplate(id: String, template: AndroidAutoTemplate<T>) {
34
- templates.put(id, template)
35
+ templates[id] = template
35
36
  }
36
37
 
37
38
  fun getTemplate(id: String): AndroidAutoTemplate<*>? {
@@ -40,7 +41,7 @@ abstract class AndroidAutoTemplate<T>(val context: CarContext, var config: T) {
40
41
 
41
42
  inline fun <reified T> getTemplate(id: String): T {
42
43
  val template = templates[id] as? T
43
- return template ?: throw IllegalArgumentException()
44
+ return template ?: throw TemplateNotFoundException(id)
44
45
  }
45
46
 
46
47
  inline fun <reified T> hasTemplate(id: String): Boolean {
package/lib/index.d.ts CHANGED
@@ -41,6 +41,7 @@ export * from './types/Telemetry';
41
41
  export * from './types/Text';
42
42
  export * from './types/Trip';
43
43
  export type { VoiceInputChunk, VoiceInputOptions, VoiceInputResult } from './types/Voice';
44
+ export * from './utils/ErrorUtil';
44
45
  export type { AlertPriority, NavigationAlert as Alert, NavigationAlertAction as AlertAction, } from './utils/NitroAlert';
45
46
  export type { ThemedColor } from './utils/NitroColor';
46
47
  export type { GridButton } from './utils/NitroGrid';
package/lib/index.js CHANGED
@@ -45,4 +45,5 @@ export * from './types/SignInMethod';
45
45
  export * from './types/Telemetry';
46
46
  export * from './types/Text';
47
47
  export * from './types/Trip';
48
+ export * from './utils/ErrorUtil';
48
49
  export { setIconFont } from './utils/NitroImage';
@@ -0,0 +1,3 @@
1
+ export declare const ErrorUtil: {
2
+ isTemplateNotFoundError: (error: unknown) => error is Error;
3
+ };
@@ -0,0 +1,19 @@
1
+ const isTemplateNotFoundError = (error) => {
2
+ if (error == null) {
3
+ return false;
4
+ }
5
+ if (typeof error !== 'object') {
6
+ return false;
7
+ }
8
+ if (!('message' in error && 'name' in error)) {
9
+ return false;
10
+ }
11
+ if (error.name !== 'Error') {
12
+ return false;
13
+ }
14
+ if (typeof error.message !== 'string') {
15
+ return false;
16
+ }
17
+ return error.message.startsWith('templateNotFound');
18
+ };
19
+ export const ErrorUtil = { isTemplateNotFoundError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
package/src/index.ts CHANGED
@@ -56,6 +56,7 @@ export * from './types/Telemetry';
56
56
  export * from './types/Text';
57
57
  export * from './types/Trip';
58
58
  export type { VoiceInputChunk, VoiceInputOptions, VoiceInputResult } from './types/Voice';
59
+ export * from './utils/ErrorUtil';
59
60
  export type {
60
61
  AlertPriority,
61
62
  NavigationAlert as Alert,
@@ -0,0 +1,25 @@
1
+ const isTemplateNotFoundError = (error: unknown): error is Error => {
2
+ if (error == null) {
3
+ return false;
4
+ }
5
+
6
+ if (typeof error !== 'object') {
7
+ return false;
8
+ }
9
+
10
+ if (!('message' in error && 'name' in error)) {
11
+ return false;
12
+ }
13
+
14
+ if (error.name !== 'Error') {
15
+ return false;
16
+ }
17
+
18
+ if (typeof error.message !== 'string') {
19
+ return false;
20
+ }
21
+
22
+ return error.message.startsWith('templateNotFound');
23
+ };
24
+
25
+ export const ErrorUtil = { isTemplateNotFoundError };