ext(sw): add list_groups popup handler

This commit is contained in:
adlee-was-taken
2026-05-01 18:08:34 -04:00
parent 61dbb4d3a3
commit 5fbdd30a19
3 changed files with 40 additions and 1 deletions

View File

@@ -972,3 +972,31 @@ describe('get_active_tab_url', () => {
expect(resp.data).toBeNull(); expect(resp.data).toBeNull();
}); });
}); });
// --- list_groups ---
describe('list_groups', () => {
it('list_groups returns deduplicated sorted groups from manifest', async () => {
const state = makeState();
state.manifest = {
schema_version: 2,
items: {
a: { id: 'a', title: 't1', type: 'login', group: 'work', tags: [], modified: 0, created: 0, favorite: false, attachment_summaries: [] },
b: { id: 'b', title: 't2', type: 'login', group: 'personal', tags: [], modified: 0, created: 0, favorite: false, attachment_summaries: [] },
c: { id: 'c', title: 't3', type: 'login', group: 'work', tags: [], modified: 0, created: 0, favorite: false, attachment_summaries: [] },
d: { id: 'd', title: 't4', type: 'login', tags: [], modified: 0, created: 0, favorite: false, attachment_summaries: [] }, // no group
},
};
const resp = await route({ type: 'list_groups' } as any, state, makePopupSender());
expect(resp.ok).toBe(true);
expect(resp.data).toEqual({ groups: ['personal', 'work'] });
});
it('list_groups returns empty array when manifest is null', async () => {
const state = makeState();
state.manifest = null;
const resp = await route({ type: 'list_groups' } as any, state, makePopupSender());
expect(resp.ok).toBe(true);
expect(resp.data).toEqual({ groups: [] });
});
});

View File

@@ -159,6 +159,16 @@ export async function handle(
return { ok: true, data: { url: tab.url, title: tab.title ?? '' } }; return { ok: true, data: { url: tab.url, title: tab.title ?? '' } };
} }
case 'list_groups': {
if (!state.manifest) return { ok: true, data: { groups: [] } };
const set = new Set<string>();
for (const id in state.manifest.items) {
const g = state.manifest.items[id].group;
if (g) set.add(g);
}
return { ok: true, data: { groups: Array.from(set).sort() } };
}
case 'generate_password': { case 'generate_password': {
const password = state.wasm.generate_password(JSON.stringify(msg.request)); const password = state.wasm.generate_password(JSON.stringify(msg.request));
return { ok: true, data: { password } }; return { ok: true, data: { password } };

View File

@@ -37,6 +37,7 @@ export type PopupMessage =
| { type: 'get_blacklist' } | { type: 'get_blacklist' }
| { type: 'remove_blacklist'; hostname: string } | { type: 'remove_blacklist'; hostname: string }
| { type: 'get_active_tab_url' } | { type: 'get_active_tab_url' }
| { type: 'list_groups' }
| { type: 'upload_attachment'; itemId: string; filename: string; mimeType: string; bytes: ArrayBuffer } | { type: 'upload_attachment'; itemId: string; filename: string; mimeType: string; bytes: ArrayBuffer }
| { type: 'download_attachment'; itemId: string; attachmentId: string } | { type: 'download_attachment'; itemId: string; attachmentId: string }
| { type: 'list_devices' } | { type: 'list_devices' }
@@ -158,7 +159,7 @@ export const POPUP_ONLY_TYPES: ReadonlySet<PopupMessage['type']> = new Set([
'fill_credentials', 'fill_credentials',
'ack_autofill_origin', 'get_settings', 'update_settings', 'ack_autofill_origin', 'get_settings', 'update_settings',
'get_vault_settings', 'update_vault_settings', 'get_blacklist', 'get_vault_settings', 'update_vault_settings', 'get_blacklist',
'remove_blacklist', 'get_active_tab_url', 'upload_attachment', 'download_attachment', 'remove_blacklist', 'get_active_tab_url', 'list_groups', 'upload_attachment', 'download_attachment',
'list_devices', 'add_device', 'register_this_device', 'revoke_device', 'list_devices', 'add_device', 'register_this_device', 'revoke_device',
'list_trashed', 'restore_item', 'purge_item', 'purge_all_trash', 'list_trashed', 'restore_item', 'purge_item', 'purge_all_trash',
'get_field_history', 'get_field_history',