@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.
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/AutoPlayError.kt +5 -0
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +2 -2
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/AndroidAutoTemplate.kt +3 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/utils/ErrorUtil.d.ts +3 -0
- package/lib/utils/ErrorUtil.js +19 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/utils/ErrorUtil.ts +25 -0
package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
@@ -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
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 };
|