feat(admin): rewire launch-app to check-for-updates UI nav + frontend polling
This commit is contained in:
+7
-4
@@ -2841,11 +2841,14 @@ async def admin_msfs_sync_task(task_id: str):
|
||||
|
||||
@app.post("/api/admin/msfs-sync/launch-app")
|
||||
async def admin_msfs_sync_launch():
|
||||
"""Launch the MS Field Service app on the connected phone."""
|
||||
"""Launch MS Field Service app, navigate to Check for Updates via UI nav.
|
||||
|
||||
Taps globe icon in top-right, waits 15s, taps Check for Updates button,
|
||||
then waits for the phone's offline DB to stabilize.
|
||||
"""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=15) as client:
|
||||
resp = await client.post(f"{EXTRACTION_SYNC_BASE}/api/sync/start")
|
||||
# The start endpoint already launches the app
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
resp = await client.post(f"{EXTRACTION_SYNC_BASE}/api/sync/check-for-updates")
|
||||
return resp.json()
|
||||
except httpx.RequestError as e:
|
||||
raise HTTPException(502, f"Extraction server unreachable: {e}")
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+55
-2
@@ -5679,8 +5679,61 @@ async function pollMsfsTask() {
|
||||
|
||||
async function launchMsfsApp() {
|
||||
try {
|
||||
await api('/api/admin/msfs-sync/launch-app', { method: 'POST' });
|
||||
showToast('📱 Sync started — Field Service app launched on phone, wait for it to complete');
|
||||
const result = await api('/api/admin/msfs-sync/launch-app', { method: 'POST' });
|
||||
showToast('📱 App launched — navigating to Check for Updates...');
|
||||
|
||||
const taskId = result.task_id;
|
||||
if (!taskId) {
|
||||
showToast('⚠️ No task_id returned — check extraction server', true);
|
||||
return;
|
||||
}
|
||||
|
||||
syncTaskId = taskId;
|
||||
document.getElementById('msfsLaunchBtn').disabled = true;
|
||||
document.getElementById('msfsProgressCard').style.display = '';
|
||||
document.getElementById('msfsProgressResult').style.display = 'none';
|
||||
document.getElementById('msfsProgressMsg').textContent = 'Launching app...';
|
||||
document.getElementById('msfsCancelBtn').style.display = '';
|
||||
|
||||
syncPollInterval = setInterval(async () => {
|
||||
try {
|
||||
const task = await api(`/api/admin/msfs-sync/task/${taskId}`);
|
||||
document.getElementById('msfsProgressMsg').textContent = task.message || 'Working...';
|
||||
|
||||
if (task.status === 'completed') {
|
||||
clearInterval(syncPollInterval);
|
||||
syncPollInterval = null;
|
||||
document.getElementById('msfsLaunchBtn').disabled = false;
|
||||
document.getElementById('msfsCancelBtn').style.display = 'none';
|
||||
document.getElementById('msfsProgressResult').style.display = '';
|
||||
document.getElementById('msfsProgressResult').innerHTML =
|
||||
`<div style="color:var(--green);font-size:13px;">✅ Updates check complete — phone finished syncing</div>`;
|
||||
showToast('✅ Phone check-for-updates complete');
|
||||
loadMsfsSync(); // refresh
|
||||
} else if (task.status === 'warning') {
|
||||
clearInterval(syncPollInterval);
|
||||
syncPollInterval = null;
|
||||
document.getElementById('msfsLaunchBtn').disabled = false;
|
||||
document.getElementById('msfsCancelBtn').style.display = 'none';
|
||||
document.getElementById('msfsProgressResult').style.display = '';
|
||||
document.getElementById('msfsProgressResult').innerHTML =
|
||||
`<div style="color:var(--amber);font-size:13px;">⚠️ ${esc(task.message)}</div>`;
|
||||
showToast('⚠️ Check-for-updates completed with warnings', true);
|
||||
loadMsfsSync();
|
||||
} else if (task.status === 'failed') {
|
||||
clearInterval(syncPollInterval);
|
||||
syncPollInterval = null;
|
||||
document.getElementById('msfsLaunchBtn').disabled = false;
|
||||
document.getElementById('msfsCancelBtn').style.display = 'none';
|
||||
document.getElementById('msfsProgressResult').style.display = '';
|
||||
document.getElementById('msfsProgressResult').innerHTML =
|
||||
`<div style="color:var(--red);font-size:13px;">❌ ${esc(task.message)}</div>`;
|
||||
showToast(`❌ ${task.message}`, true);
|
||||
}
|
||||
} catch (e) {
|
||||
// Keep polling
|
||||
}
|
||||
}, 2000);
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user