happy path working with stub companion app
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
import { queryDomainStatus, reportSecurityError } from './api.js';
|
||||
import { abortRun, cleanupRun, confirmPin, dismissRunError, startRun } from './run.js';
|
||||
import { clearSessionActive, getSessionActive, setSessionActive } from './session-status.js';
|
||||
import { registerSdkPort, unregisterSdkPort } from './sdk-ports.js';
|
||||
import { clearTabState, getTabState, setTabState } from './state.js';
|
||||
import { verifyRegistrationCert } from './verify.js';
|
||||
@@ -91,10 +92,30 @@ async function handleInit(port: chrome.runtime.Port, tabId: number, originUrl: s
|
||||
return;
|
||||
}
|
||||
|
||||
await setTabState(tabId, { kind: 'idle', origin: result.domain, features: result.features });
|
||||
await setTabState(tabId, {
|
||||
kind: 'idle',
|
||||
origin: result.domain,
|
||||
features: result.features,
|
||||
sessionActive: getSessionActive(tabId),
|
||||
});
|
||||
respond(port, { type: 'verification', status: 'valid', features: result.features });
|
||||
}
|
||||
|
||||
/**
|
||||
* SDK `session_status` — advisory only (types.ts's SessionStatusMessage).
|
||||
* Remembered even outside `idle` (e.g. reported before verification
|
||||
* finishes, or during an unrelated run) so the *next* time `idle` is
|
||||
* entered it reflects the latest report, not just whichever one happened
|
||||
* to arrive while already idle.
|
||||
*/
|
||||
async function handleSessionStatus(tabId: number, active: boolean): Promise<void> {
|
||||
setSessionActive(tabId, active);
|
||||
const state = await getTabState(tabId);
|
||||
if (state.kind === 'idle') {
|
||||
await setTabState(tabId, { ...state, sessionActive: active });
|
||||
}
|
||||
}
|
||||
|
||||
function respond(port: chrome.runtime.Port, message: VerificationMessage): void {
|
||||
try {
|
||||
port.postMessage(message);
|
||||
@@ -140,6 +161,9 @@ chrome.runtime.onConnectExternal.addListener((port) => {
|
||||
registerSdkPort(tabId, port);
|
||||
port.onDisconnect.addListener(() => unregisterSdkPort(tabId, port));
|
||||
|
||||
// A fresh connection is a fresh page load — any session hint from a
|
||||
// previous page at this tab is stale until this page re-reports it.
|
||||
clearSessionActive(tabId);
|
||||
void setTabState(tabId, { kind: 'unverified' });
|
||||
|
||||
port.onMessage.addListener((raw: unknown) => {
|
||||
@@ -150,6 +174,8 @@ chrome.runtime.onConnectExternal.addListener((port) => {
|
||||
void handleRequestCredential(tabId, windowId);
|
||||
} else if (message.type === 'abort') {
|
||||
void handleAbort(tabId);
|
||||
} else if (message.type === 'session_status') {
|
||||
void handleSessionStatus(tabId, message.active);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -170,6 +196,9 @@ chrome.runtime.onMessage.addListener((raw: unknown) => {
|
||||
async function handlePopupAction(message: PopupActionMessage): Promise<void> {
|
||||
const { tabId, action } = message;
|
||||
const state = await getTabState(tabId);
|
||||
// Diagnostic: distinguishes "message never arrived" from "arrived but
|
||||
// no-opped because state didn't match" — both looked identical before.
|
||||
console.log(`[locqr] popup_action received: action=${action} tabId=${tabId} currentState=${state.kind}`);
|
||||
|
||||
switch (action) {
|
||||
case 'start_run':
|
||||
|
||||
Reference in New Issue
Block a user