= {
connecting: 'Connecting…',
connected: 'Connected',
disconnected: 'Disconnected — retrying',
'auth-error': 'Sign-in failed — retrying',
};
function renderConnection(status: ConnectionStatus): void {
connectionEl.innerHTML = ` ${CONNECTION_LABELS[status]}`;
}
function renderStatus(state: LockState): void {
statusEl.innerHTML = state.locked
? `🔒 Locked
${escapeHtml(state.reason ?? 'No reason provided.')}
Scope: ${escapeHtml(state.scope)}
`
: `Unlocked
`;
}
async function loadLockState(): Promise {
const message: NexaMessage = { type: 'nexa:get-lock-state' };
const state = (await browser.runtime.sendMessage(message)) as LockState | undefined;
return state ?? DEFAULT_LOCK_STATE;
}
async function loadConnectionStatus(): Promise {
const message: NexaMessage = { type: 'nexa:get-connection-status' };
const status = (await browser.runtime.sendMessage(message)) as ConnectionStatus | undefined;
return status ?? DEFAULT_CONNECTION_STATUS;
}
loadLockState().then(renderStatus);
loadConnectionStatus().then(renderConnection);
browser.runtime.onMessage.addListener((message: NexaMessage) => {
if (message?.type === 'nexa:lock-state-changed') {
renderStatus(message.state);
} else if (message?.type === 'nexa:connection-status-changed') {
renderConnection(message.status);
}
});