feat(admin): rewire launch-app to check-for-updates UI nav + frontend polling

This commit is contained in:
Leo
2026-06-02 18:20:04 -04:00
parent 7a2d283379
commit fb98de229d
4 changed files with 62 additions and 6 deletions
+7 -4
View File
@@ -2841,11 +2841,14 @@ async def admin_msfs_sync_task(task_id: str):
@app.post("/api/admin/msfs-sync/launch-app") @app.post("/api/admin/msfs-sync/launch-app")
async def admin_msfs_sync_launch(): 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: try:
async with httpx.AsyncClient(timeout=15) as client: async with httpx.AsyncClient(timeout=30) as client:
resp = await client.post(f"{EXTRACTION_SYNC_BASE}/api/sync/start") resp = await client.post(f"{EXTRACTION_SYNC_BASE}/api/sync/check-for-updates")
# The start endpoint already launches the app
return resp.json() return resp.json()
except httpx.RequestError as e: except httpx.RequestError as e:
raise HTTPException(502, f"Extraction server unreachable: {e}") raise HTTPException(502, f"Extraction server unreachable: {e}")
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+55 -2
View File
@@ -5679,8 +5679,61 @@ async function pollMsfsTask() {
async function launchMsfsApp() { async function launchMsfsApp() {
try { try {
await api('/api/admin/msfs-sync/launch-app', { method: 'POST' }); const result = await api('/api/admin/msfs-sync/launch-app', { method: 'POST' });
showToast('📱 Sync started — Field Service app launched on phone, wait for it to complete'); 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) { } catch (e) {
showToast(e.message, true); showToast(e.message, true);
} }