ilabs-flir 2.3.4 → 2.3.6

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.
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.WritableMap
10
10
  import com.facebook.react.modules.core.DeviceEventManagerModule
11
11
  import com.facebook.react.uimanager.ThemedReactContext
12
12
  import com.flir.thermalsdk.live.Identity
13
+ import com.flir.thermalsdk.image.Palette
13
14
  import com.flir.thermalsdk.image.PaletteManager
14
15
  import java.io.File
15
16
  import java.io.FileOutputStream
@@ -463,20 +464,41 @@ object FlirManager {
463
464
  Log.d(TAG, "Updated Var.cool to $shaderIdx via reflection (raw=$rawIdx)")
464
465
 
465
466
  // If we are in FLIR mode, also notify the SDK palette using the official SDK palette list
466
- val sdkPalettes = PaletteManager.getDefaultPalettes()
467
- val paletteNames = sdkPalettes.map { it.name }
468
- Log.d(TAG, "True FLIR Palettes: $paletteNames")
469
-
470
- val maxEff = sdkPalettes.size
471
- val paletteIdx = rawIdx % maxEff
472
- val safeIdx = if (paletteIdx < 0) paletteIdx + maxEff else paletteIdx
473
-
474
- val targetPaletteName = paletteNames[safeIdx]
475
- Log.d(TAG, "Applying true FLIR palette: $targetPaletteName (index: $safeIdx, max: $maxEff)")
476
-
477
- sdkManager?.setPalette(targetPaletteName)
467
+ var sdkPalettes: List<*>? = null
468
+ try {
469
+ sdkPalettes = PaletteManager.getDefaultPalettes()
470
+ } catch (t: Throwable) {
471
+ try {
472
+ val altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager")
473
+ val method = altClazz.getMethod("getDefaultPalettes")
474
+ sdkPalettes = method.invoke(null) as? List<*>
475
+ } catch (t2: Throwable) {
476
+ Log.w(TAG, "Palette discovery failed in updateAcol", t2)
477
+ }
478
+ }
479
+
480
+ val currentPalettes = sdkPalettes
481
+ if (currentPalettes != null && currentPalettes.isNotEmpty()) {
482
+ val paletteNames = currentPalettes.map { p ->
483
+ try {
484
+ p?.let { it::class.java.getMethod("getName").invoke(it) as? String } ?: p?.toString() ?: ""
485
+ } catch (e: Exception) {
486
+ p?.toString() ?: ""
487
+ }
488
+ }
489
+ Log.d(TAG, "True FLIR Palettes: $paletteNames")
490
+
491
+ val maxEff = currentPalettes.size
492
+ val paletteIdx = rawIdx % maxEff
493
+ val safeIdx = if (paletteIdx < 0) paletteIdx + maxEff else paletteIdx
494
+
495
+ val targetPaletteName = paletteNames[safeIdx]
496
+ Log.d(TAG, "Applying true FLIR palette: $targetPaletteName (index: $safeIdx, max: $maxEff)")
497
+
498
+ sdkManager?.setPalette(targetPaletteName)
499
+ }
478
500
 
479
- } catch (e: Exception) {
501
+ } catch (e: Throwable) {
480
502
  Log.w(TAG, "Could not update Var.cool via reflection: ${e.message}")
481
503
  }
482
504
  }
@@ -487,12 +509,35 @@ object FlirManager {
487
509
  fun generatePaletteIcons(context: Context): List<Map<String, String>> {
488
510
  val results = mutableListOf<Map<String, String>>()
489
511
  try {
490
- val rawPalettes = PaletteManager.getDefaultPalettes()
491
- val palettes = rawPalettes.toMutableList()
512
+ var rawPalettes: List<*>? = null
513
+ try {
514
+ rawPalettes = PaletteManager.getDefaultPalettes()
515
+ } catch (t: Throwable) {
516
+ Log.e(TAG, "PaletteManager.getDefaultPalettes() failed in icon generation", t)
517
+ try {
518
+ val altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager")
519
+ val method = altClazz.getMethod("getDefaultPalettes")
520
+ rawPalettes = method.invoke(null) as? List<*>
521
+ } catch (t2: Throwable) {
522
+ Log.e(TAG, "Alternative package search also failed in icon generation", t2)
523
+ }
524
+ }
525
+
526
+ val currentPalettes = rawPalettes
527
+ if (currentPalettes == null) {
528
+ Log.e(TAG, "Failed to retrieve any palettes from SDK")
529
+ return emptyList()
530
+ }
531
+
532
+ val palettes = currentPalettes.toMutableList()
492
533
 
493
534
  // Reorder: Move WhiteHot/Gray to the front
494
- val grayIdx = palettes.indexOfFirst {
495
- it.name.equals("WhiteHot", ignoreCase = true) || it.name.equals("Gray", ignoreCase = true) || it.name.contains("gray", ignoreCase = true)
535
+ val grayIdx = palettes.indexOfFirst { p ->
536
+ val name = try {
537
+ p?.let { it::class.java.getMethod("getName").invoke(it) as? String } ?: p?.toString() ?: ""
538
+ } catch (e: Exception) { p?.toString() ?: "" }
539
+
540
+ name.equals("WhiteHot", ignoreCase = true) || name.equals("Gray", ignoreCase = true) || name.contains("gray", ignoreCase = true)
496
541
  }
497
542
  if (grayIdx > 0) {
498
543
  val gray = palettes.removeAt(grayIdx)
@@ -503,17 +548,21 @@ object FlirManager {
503
548
  if (!dir.exists()) dir.mkdirs()
504
549
 
505
550
  for (palette in palettes) {
506
- val iconFile = File(dir, "${palette.name.lowercase()}.png")
551
+ val name = try {
552
+ palette?.let { it::class.java.getMethod("getName").invoke(it) as? String } ?: palette?.toString() ?: "unknown"
553
+ } catch (e: Exception) { palette?.toString() ?: "unknown" }
554
+
555
+ val iconFile = File(dir, "${name.lowercase()}.png")
507
556
  if (!iconFile.exists()) {
508
557
  try {
509
558
  // Common method names for palette preview in FLIR SDK: getBitmap(), getIcon()
510
559
  val bitmap = try {
511
- val m = palette.javaClass.getMethod("getBitmap")
512
- m.invoke(palette) as? Bitmap
560
+ val m = palette?.let { it::class.java.getMethod("getBitmap") }
561
+ m?.invoke(palette) as? Bitmap
513
562
  } catch (e: Exception) {
514
563
  try {
515
- val m = palette.javaClass.getMethod("getIcon")
516
- m.invoke(palette) as? Bitmap
564
+ val m = palette?.let { it::class.java.getMethod("getIcon") }
565
+ m?.invoke(palette) as? Bitmap
517
566
  } catch (e2: Exception) { null }
518
567
  }
519
568
 
@@ -523,11 +572,11 @@ object FlirManager {
523
572
  }
524
573
  }
525
574
  } catch (e: Exception) {
526
- Log.w(TAG, "Failed to save icon for ${palette.name}: ${e.message}")
575
+ Log.w(TAG, "Failed to save icon for $name: ${e.message}")
527
576
  }
528
577
  }
529
578
  results.add(mapOf(
530
- "name" to palette.name,
579
+ "name" to name,
531
580
  "uri" to if (iconFile.exists()) "file://${iconFile.absolutePath}" else ""
532
581
  ))
533
582
  }
@@ -144,7 +144,7 @@ class FlirModule(private val reactContext: ReactApplicationContext) : ReactConte
144
144
  val result = com.facebook.react.bridge.Arguments.createArray()
145
145
  palettes.forEach { result.pushString(it) }
146
146
  promise?.resolve(result)
147
- } catch (e: Exception) {
147
+ } catch (e: Throwable) {
148
148
  promise?.reject("ERR_FLIR_PALETTES", e)
149
149
  }
150
150
  }
@@ -162,7 +162,7 @@ class FlirModule(private val reactContext: ReactApplicationContext) : ReactConte
162
162
  result.pushMap(map)
163
163
  }
164
164
  promise?.resolve(result)
165
- } catch (e: Exception) {
165
+ } catch (e: Throwable) {
166
166
  promise?.reject("ERR_FLIR_PALETTE_ICONS", e)
167
167
  }
168
168
  }
@@ -306,7 +306,7 @@ class FlirModule(private val reactContext: ReactApplicationContext) : ReactConte
306
306
  try {
307
307
  FlirManager.updateAcol(value)
308
308
  promise?.resolve(true)
309
- } catch (e: Exception) {
309
+ } catch (e: Throwable) {
310
310
  promise?.reject("ERR_FLIR_ACOL", e)
311
311
  }
312
312
  }
@@ -318,7 +318,7 @@ class FlirModule(private val reactContext: ReactApplicationContext) : ReactConte
318
318
  FlirManager.setPalette(name)
319
319
  }
320
320
  promise?.resolve(true)
321
- } catch (e: Exception) {
321
+ } catch (e: Throwable) {
322
322
  promise?.reject("ERR_FLIR_PALETTE", e)
323
323
  }
324
324
  }
@@ -101,8 +101,25 @@ public class FlirSdkManager {
101
101
  if (isInitialized)
102
102
  return;
103
103
  try {
104
+ try {
105
+ // Explicitly load the native library to ensure JNI methods are linked
106
+ try {
107
+ System.loadLibrary("atlas_native");
108
+ Log.i(TAG, "Successfully loaded atlas_native library manually");
109
+ } catch (UnsatisfiedLinkError e) {
110
+ Log.w(TAG, "System.loadLibrary(atlas_native) failed (might be loaded by SDK): " + e.getMessage());
111
+ }
112
+
104
113
  ThermalSdkAndroid.init(context);
114
+
115
+ // Small delay to ensure JNI linkage is stable
116
+ try { Thread.sleep(100); } catch (InterruptedException ignored) {}
117
+
105
118
  isInitialized = true;
119
+ Log.i(TAG, "FLIR SDK initialized successfully. Arch: " + System.getProperty("os.arch"));
120
+ } catch (Throwable e) {
121
+ Log.e(TAG, "Critical failure during FLIR SDK initialization", e);
122
+ }
106
123
  Log.d(TAG, "SDK initialized");
107
124
  } catch (Exception e) {
108
125
  Log.e(TAG, "SDK init failed", e);
@@ -358,13 +375,36 @@ public class FlirSdkManager {
358
375
  if (paletteToApply != null) {
359
376
  try {
360
377
  Palette palette = null;
361
- // Try modern way if available (via image's palette manager)
362
- // Otherwise fallback to static PaletteManager
363
- List<Palette> sdkPalettes = PaletteManager.getDefaultPalettes();
364
- for (Palette p : sdkPalettes) {
365
- if (p.name.equalsIgnoreCase(paletteToApply)) {
366
- palette = p;
367
- break;
378
+ // 1. Try to get default palettes list safely
379
+ List<?> sdkPalettes = null;
380
+ try {
381
+ sdkPalettes = PaletteManager.getDefaultPalettes();
382
+ } catch (Throwable t) {
383
+ Log.e(TAG, "PaletteManager.getDefaultPalettes() failed (Linkage Error?)", t);
384
+ // Fallback: Try to use reflection for alternative package if suggested
385
+ try {
386
+ Class<?> altClazz = Class.forName("com.flir.thermalsdk.image.palettes.PaletteManager");
387
+ java.lang.reflect.Method method = altClazz.getMethod("getDefaultPalettes");
388
+ sdkPalettes = (List<?>) method.invoke(null);
389
+ Log.i(TAG, "Successfully retrieved palettes using alternative package");
390
+ } catch (Throwable t2) {
391
+ Log.e(TAG, "Alternative PaletteManager search also failed", t2);
392
+ }
393
+ }
394
+
395
+ if (sdkPalettes != null) {
396
+ for (Object p : sdkPalettes) {
397
+ String pName = "";
398
+ try {
399
+ pName = (String) p.getClass().getMethod("getName").invoke(p);
400
+ } catch (Exception e) {
401
+ pName = p.toString();
402
+ }
403
+
404
+ if (pName != null && pName.equalsIgnoreCase(paletteToApply)) {
405
+ palette = (Palette) p;
406
+ break;
407
+ }
368
408
  }
369
409
  }
370
410
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilabs-flir",
3
- "version": "2.3.4",
3
+ "version": "2.3.6",
4
4
  "description": "FLIR Thermal SDK for React Native - iOS & Android (bundled at compile time via postinstall)",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",