refactor(ext/popup): extract teardownSettingsCommon (Plan C Phase 5)
DEV-C P2: settings.ts:56-65 and settings-vault.ts:15-22 had near- identical cleanup paths. Single source for closeGeneratorPanel + activeKeyHandler removal. Helper takes the handler as a parameter and returns null so each caller still owns its own module-scoped handler state. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
|||||||
import type { SessionTimeoutConfig } from '../../shared/messages';
|
import type { SessionTimeoutConfig } from '../../shared/messages';
|
||||||
import { relativeTime } from '../../shared/relative-time';
|
import { relativeTime } from '../../shared/relative-time';
|
||||||
import { openGeneratorPanel, closeGeneratorPanel, isGeneratorPanelOpen } from './generator-panel';
|
import { openGeneratorPanel, closeGeneratorPanel, isGeneratorPanelOpen } from './generator-panel';
|
||||||
|
import { teardownSettingsCommon } from './settings';
|
||||||
import { GLYPH_NEXT } from '../../shared/glyphs';
|
import { GLYPH_NEXT } from '../../shared/glyphs';
|
||||||
|
|
||||||
let pendingSettings: VaultSettings | null = null;
|
let pendingSettings: VaultSettings | null = null;
|
||||||
@@ -17,11 +18,7 @@ let pendingSession: SessionTimeoutConfig | null = null;
|
|||||||
let baseSession: SessionTimeoutConfig | null = null;
|
let baseSession: SessionTimeoutConfig | null = null;
|
||||||
|
|
||||||
export function teardown(): void {
|
export function teardown(): void {
|
||||||
closeGeneratorPanel();
|
activeKeyHandler = teardownSettingsCommon(activeKeyHandler);
|
||||||
if (activeKeyHandler) {
|
|
||||||
document.removeEventListener('keydown', activeKeyHandler);
|
|
||||||
activeKeyHandler = null;
|
|
||||||
}
|
|
||||||
pendingSettings = null;
|
pendingSettings = null;
|
||||||
pendingSession = null;
|
pendingSession = null;
|
||||||
baseSession = null;
|
baseSession = null;
|
||||||
|
|||||||
@@ -53,13 +53,29 @@ export async function renderSettings(container: HTMLElement): Promise<void> {
|
|||||||
await renderSection(activeSection);
|
await renderSection(activeSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function teardownSettings(): void {
|
/**
|
||||||
|
* Common cleanup invoked by both the device-settings teardown
|
||||||
|
* (settings.ts) and the vault-settings teardown (settings-vault.ts).
|
||||||
|
* Centralized to avoid the "regression class with known prior leaks"
|
||||||
|
* DEV-C P2 flagged.
|
||||||
|
*
|
||||||
|
* Closes the generator popover and detaches the supplied keydown
|
||||||
|
* handler from the document if present. Returns the new handler value
|
||||||
|
* (always null), so the caller can do `handler = teardownSettingsCommon(handler)`.
|
||||||
|
*/
|
||||||
|
export function teardownSettingsCommon(
|
||||||
|
keyHandler: ((e: KeyboardEvent) => void) | null,
|
||||||
|
): null {
|
||||||
closeGeneratorPanel();
|
closeGeneratorPanel();
|
||||||
teardownSecuritySection();
|
if (keyHandler) {
|
||||||
if (activeKeyHandler) {
|
document.removeEventListener('keydown', keyHandler);
|
||||||
document.removeEventListener('keydown', activeKeyHandler);
|
|
||||||
activeKeyHandler = null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function teardownSettings(): void {
|
||||||
|
activeKeyHandler = teardownSettingsCommon(activeKeyHandler);
|
||||||
|
teardownSecuritySection();
|
||||||
pendingVaultSettings = null;
|
pendingVaultSettings = null;
|
||||||
sessionHandle = null;
|
sessionHandle = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user