feat(ext/popup): fetch vault_settings on unlock; add to PopupState
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/// Popup entry point — state machine with view routing.
|
||||
///
|
||||
/// Views: setup | locked | list | detail | add | edit
|
||||
/// Views: setup | locked | list | detail | add | edit | settings | settings-vault
|
||||
/// Navigation works by updating `currentState` and calling `render()`.
|
||||
|
||||
import type { Request, Response } from '../shared/messages';
|
||||
@@ -23,7 +23,7 @@ export function escapeHtml(str: string): string {
|
||||
|
||||
// --- State ---
|
||||
|
||||
export type View = 'locked' | 'list' | 'detail' | 'add' | 'edit' | 'settings';
|
||||
export type View = 'locked' | 'list' | 'detail' | 'add' | 'edit' | 'settings' | 'settings-vault';
|
||||
|
||||
export interface PopupState {
|
||||
view: View;
|
||||
@@ -42,6 +42,8 @@ export interface PopupState {
|
||||
capturedTabId: number | null;
|
||||
capturedUrl: string;
|
||||
newType: import('../shared/types').ItemType | null;
|
||||
vaultSettings: import('../shared/types').VaultSettings | null;
|
||||
generatorDefaults: import('../shared/types').GeneratorRequest | null;
|
||||
}
|
||||
|
||||
let currentState: PopupState = {
|
||||
@@ -57,6 +59,8 @@ let currentState: PopupState = {
|
||||
capturedTabId: null,
|
||||
capturedUrl: '',
|
||||
newType: null,
|
||||
vaultSettings: null,
|
||||
generatorDefaults: null,
|
||||
};
|
||||
|
||||
export function getState(): PopupState {
|
||||
@@ -175,6 +179,16 @@ async function init(): Promise<void> {
|
||||
const listResp = await sendMessage({ type: 'list_items' });
|
||||
if (listResp.ok) {
|
||||
const listData = listResp.data as { items: Array<[ItemId, ManifestEntry]> };
|
||||
// Fetch vault settings so subsequent screens (generator popover,
|
||||
// settings-vault) can show current values without a round-trip.
|
||||
// Failures swallow silently — list view still renders; consumers
|
||||
// can show "settings not loaded" if needed.
|
||||
const vsResp = await sendMessage({ type: 'get_vault_settings' });
|
||||
if (vsResp.ok) {
|
||||
const vs = (vsResp.data as { settings: import('../shared/types').VaultSettings }).settings;
|
||||
currentState.vaultSettings = vs;
|
||||
currentState.generatorDefaults = vs.generator_defaults;
|
||||
}
|
||||
navigate('list', { entries: listData.items });
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user