capacitor-microphone 0.1.14 → 0.1.15
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.
|
@@ -319,49 +319,65 @@ private void startListeningInternal(PluginCall call, String lang) {
|
|
|
319
319
|
|
|
320
320
|
@PluginMethod
|
|
321
321
|
public void restartListening(PluginCall call) {
|
|
322
|
-
// 1.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
final String lang;
|
|
327
|
-
if (currentCall != null && currentCall != call) {
|
|
328
|
-
lang = currentCall.getString("lang", "es-MX");
|
|
322
|
+
// 1. Obtener lenguaje actual o del parámetro
|
|
323
|
+
String currentLang = "es-MX";
|
|
324
|
+
if (currentCall != null) {
|
|
325
|
+
currentLang = currentCall.getString("lang", "es-MX");
|
|
329
326
|
} else {
|
|
330
|
-
|
|
327
|
+
currentLang = call.getString("lang", "es-MX");
|
|
331
328
|
}
|
|
332
329
|
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
// Crear call temporal para stopListening
|
|
336
|
-
PluginCall stopCall = new PluginCall(
|
|
337
|
-
this,
|
|
338
|
-
"temp_stop_" + System.currentTimeMillis(),
|
|
339
|
-
"capacitor-microphone",
|
|
340
|
-
"stopListening",
|
|
341
|
-
new JSObject()
|
|
342
|
-
);
|
|
343
|
-
stopListening(stopCall);
|
|
344
|
-
} else {
|
|
345
|
-
// Si no estaba escuchando, limpiar manualmente
|
|
346
|
-
destroyEverything();
|
|
347
|
-
}
|
|
330
|
+
// 2. Guardar para usar después
|
|
331
|
+
final String lang = currentLang;
|
|
348
332
|
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
333
|
+
// 3. Enviar respuesta INMEDIATA
|
|
334
|
+
call.resolve(new JSObject().put("success", true));
|
|
335
|
+
|
|
336
|
+
// 4. En el background, hacer el restart REAL
|
|
337
|
+
new Thread(() -> {
|
|
338
|
+
try {
|
|
339
|
+
// 4.1 Detener completamente
|
|
340
|
+
if (isListening) {
|
|
341
|
+
getActivity().runOnUiThread(() -> {
|
|
342
|
+
isListening = false;
|
|
343
|
+
isDestroyed = true;
|
|
344
|
+
|
|
345
|
+
if (delayedStartRunnable != null) {
|
|
346
|
+
getActivity()
|
|
347
|
+
.getWindow()
|
|
348
|
+
.getDecorView()
|
|
349
|
+
.removeCallbacks(delayedStartRunnable);
|
|
350
|
+
delayedStartRunnable = null;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (speechRecognizer != null) {
|
|
354
|
+
speechRecognizer.cancel();
|
|
355
|
+
speechRecognizer.destroy();
|
|
356
|
+
speechRecognizer = null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
currentCall = null;
|
|
360
|
+
speechIntent = null;
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// 4.2 Esperar 500ms
|
|
364
|
+
Thread.sleep(500);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// 4.3 Reiniciar
|
|
368
|
+
getActivity().runOnUiThread(() -> {
|
|
369
|
+
isListening = true;
|
|
370
|
+
isDestroyed = false;
|
|
371
|
+
|
|
372
|
+
// Usar el call ORIGINAL pero solo para startListeningInternal
|
|
373
|
+
// No hay problema porque ya fue resuelto
|
|
374
|
+
startListeningInternal(call, lang);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
} catch (Exception e) {
|
|
378
|
+
// Log error si es necesario
|
|
379
|
+
}
|
|
380
|
+
}).start();
|
|
365
381
|
}
|
|
366
382
|
|
|
367
383
|
private void destroyEverything() {
|