Fix mobile app bugs: package name, deprecated API, server check
- Fix AudioRecordingService ACTION_STOP to use com.pedshub.scribe - Fix deprecated stopForeground(true) to STOP_FOREGROUND_REMOVE - Fix launcher.js testServer: prevent double callback, fix onerror always reporting success (now correctly fails on unreachable servers) - Update service comment from TWA to Capacitor
This commit is contained in:
parent
bf586daf4d
commit
d079c6d6c9
4 changed files with 42 additions and 39 deletions
|
|
@ -80,22 +80,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function testServer(url, callback) {
|
function testServer(url, callback) {
|
||||||
// Try to reach the health endpoint
|
var done = false;
|
||||||
var controller = new AbortController();
|
function respond(ok) {
|
||||||
var timeout = setTimeout(function() { controller.abort(); }, 8000);
|
if (done) return;
|
||||||
|
done = true;
|
||||||
|
callback(ok);
|
||||||
|
}
|
||||||
|
|
||||||
fetch(url + '/api/health', { signal: controller.signal, mode: 'no-cors' })
|
// Try to reach the health endpoint (no-cors: opaque response = server exists)
|
||||||
.then(function() { clearTimeout(timeout); callback(true); })
|
fetch(url + '/api/health', { mode: 'no-cors', signal: AbortSignal.timeout(8000) })
|
||||||
|
.then(function() { respond(true); })
|
||||||
.catch(function() {
|
.catch(function() {
|
||||||
clearTimeout(timeout);
|
// Fetch failed — try image load as a fallback connectivity check
|
||||||
// no-cors mode always succeeds for reachable servers (opaque response)
|
var fallbackTimer = setTimeout(function() { respond(false); }, 5000);
|
||||||
// If it fails, the server is truly unreachable
|
|
||||||
// Try again with a simple image load as fallback
|
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function() { callback(true); };
|
img.onload = function() { clearTimeout(fallbackTimer); respond(true); };
|
||||||
img.onerror = function() { callback(true); }; // Even errors mean server responded
|
img.onerror = function() { clearTimeout(fallbackTimer); respond(false); };
|
||||||
img.src = url + '/favicon.ico?t=' + Date.now();
|
img.src = url + '/favicon.ico?t=' + Date.now();
|
||||||
setTimeout(function() { callback(false); }, 5000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import androidx.core.app.NotificationCompat;
|
||||||
/**
|
/**
|
||||||
* Foreground service that keeps the app alive during audio recording.
|
* Foreground service that keeps the app alive during audio recording.
|
||||||
* Acquires a partial wake lock to prevent CPU sleep during recording.
|
* Acquires a partial wake lock to prevent CPU sleep during recording.
|
||||||
* The TWA web app sends a message to start/stop this service when recording.
|
* The Capacitor web app sends a message to start/stop this service when recording.
|
||||||
*/
|
*/
|
||||||
public class AudioRecordingService extends Service {
|
public class AudioRecordingService extends Service {
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ public class AudioRecordingService extends Service {
|
||||||
private static final int NOTIFICATION_ID = 1;
|
private static final int NOTIFICATION_ID = 1;
|
||||||
private static final String WAKE_LOCK_TAG = "PedScribe:AudioRecording";
|
private static final String WAKE_LOCK_TAG = "PedScribe:AudioRecording";
|
||||||
|
|
||||||
public static final String ACTION_STOP = "com.pediatricscribe.twa.STOP_RECORDING";
|
public static final String ACTION_STOP = "com.pedshub.scribe.STOP_RECORDING";
|
||||||
|
|
||||||
private PowerManager.WakeLock wakeLock;
|
private PowerManager.WakeLock wakeLock;
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ public class AudioRecordingService extends Service {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
wakeLock = null;
|
wakeLock = null;
|
||||||
}
|
}
|
||||||
stopForeground(true);
|
stopForeground(STOP_FOREGROUND_REMOVE);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,22 +80,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function testServer(url, callback) {
|
function testServer(url, callback) {
|
||||||
// Try to reach the health endpoint
|
var done = false;
|
||||||
var controller = new AbortController();
|
function respond(ok) {
|
||||||
var timeout = setTimeout(function() { controller.abort(); }, 8000);
|
if (done) return;
|
||||||
|
done = true;
|
||||||
|
callback(ok);
|
||||||
|
}
|
||||||
|
|
||||||
fetch(url + '/api/health', { signal: controller.signal, mode: 'no-cors' })
|
// Try to reach the health endpoint (no-cors: opaque response = server exists)
|
||||||
.then(function() { clearTimeout(timeout); callback(true); })
|
fetch(url + '/api/health', { mode: 'no-cors', signal: AbortSignal.timeout(8000) })
|
||||||
|
.then(function() { respond(true); })
|
||||||
.catch(function() {
|
.catch(function() {
|
||||||
clearTimeout(timeout);
|
// Fetch failed — try image load as a fallback connectivity check
|
||||||
// no-cors mode always succeeds for reachable servers (opaque response)
|
var fallbackTimer = setTimeout(function() { respond(false); }, 5000);
|
||||||
// If it fails, the server is truly unreachable
|
|
||||||
// Try again with a simple image load as fallback
|
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function() { callback(true); };
|
img.onload = function() { clearTimeout(fallbackTimer); respond(true); };
|
||||||
img.onerror = function() { callback(true); }; // Even errors mean server responded
|
img.onerror = function() { clearTimeout(fallbackTimer); respond(false); };
|
||||||
img.src = url + '/favicon.ico?t=' + Date.now();
|
img.src = url + '/favicon.ico?t=' + Date.now();
|
||||||
setTimeout(function() { callback(false); }, 5000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,22 +80,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function testServer(url, callback) {
|
function testServer(url, callback) {
|
||||||
// Try to reach the health endpoint
|
var done = false;
|
||||||
var controller = new AbortController();
|
function respond(ok) {
|
||||||
var timeout = setTimeout(function() { controller.abort(); }, 8000);
|
if (done) return;
|
||||||
|
done = true;
|
||||||
|
callback(ok);
|
||||||
|
}
|
||||||
|
|
||||||
fetch(url + '/api/health', { signal: controller.signal, mode: 'no-cors' })
|
// Try to reach the health endpoint (no-cors: opaque response = server exists)
|
||||||
.then(function() { clearTimeout(timeout); callback(true); })
|
fetch(url + '/api/health', { mode: 'no-cors', signal: AbortSignal.timeout(8000) })
|
||||||
|
.then(function() { respond(true); })
|
||||||
.catch(function() {
|
.catch(function() {
|
||||||
clearTimeout(timeout);
|
// Fetch failed — try image load as a fallback connectivity check
|
||||||
// no-cors mode always succeeds for reachable servers (opaque response)
|
var fallbackTimer = setTimeout(function() { respond(false); }, 5000);
|
||||||
// If it fails, the server is truly unreachable
|
|
||||||
// Try again with a simple image load as fallback
|
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function() { callback(true); };
|
img.onload = function() { clearTimeout(fallbackTimer); respond(true); };
|
||||||
img.onerror = function() { callback(true); }; // Even errors mean server responded
|
img.onerror = function() { clearTimeout(fallbackTimer); respond(false); };
|
||||||
img.src = url + '/favicon.ico?t=' + Date.now();
|
img.src = url + '/favicon.ico?t=' + Date.now();
|
||||||
setTimeout(function() { callback(false); }, 5000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue