Files
Suzu008 a58a5b8917 refactor(sw): bidirectional SW status sync with IndexedDB persistence
Replace fire-and-forget key delivery with a sync-status protocol that
verifies key consistency between main thread and Service Worker using
SHA-256 fingerprints via MessageChannel request-response.

- SW (ts/sw.ts): persist keys in IndexedDB, auto-restore on activate;
  respond to sync-status queries with loaded keys + fingerprints;
  support cryptio-clear-keys to wipe memory + DB.
- New ts/utils/swSync.ts: single entry point for SW registration,
  key sync, and status verification. Controller change listener
  re-syncs on SW restart. Deduplicates concurrent sync calls.
- Deleted ts/utils/swKeySender.ts (replaced by swSync.ts).
- Remove SW registration (~55 lines) from cryptioSaveImage.ts;
  setup() now calls syncSWStatus().
- uploadUtils.ts: drop 5-retry preview loop (~6.4s worst case);
  single attempt with syncSWStatus fallback on failure.
- cryptioSettings.ts: sync after key changes; clearSWKeys() on
  Clear All.
- cryptioUploadImage/Video.ts: syncSWStatus in setup + preview
  fallback.
- types.ts: add SWStatus interface.
2026-05-30 22:29:45 +08:00

76 lines
2.1 KiB
TypeScript

/**
* Custom properties for CryptIO nodes to track resources and state.
*/
export interface CryptIONode {
// Custom properties must be explicitly defined here for safety
_cryptioPreviewUrl?: string | null;
_cryptioBlobUrls?: string[];
updatePreview?: (filename: string) => Promise<void>;
// ComfyUI / LiteGraph properties
size: [number, number];
widgets: any[];
imgs?: HTMLImageElement[];
images?: Array<{
filename: string;
subfolder: string;
type: string;
}>;
node?: CryptIONode; // Some callbacks are called on widgets with a reference to the node
// Methods
addDOMWidget: (name: string, type: string, element: HTMLElement, options?: any) => any;
removeWidget: (widget: any) => void;
addWidget: (type: string, name: string, value: any, callback?: any, options?: any) => any;
// Lifecycle hooks
onExecuted?: (message: any) => void;
onRemoved?: () => void;
onNodeCreated?: () => void;
onDragOver?: (e: DragEvent) => boolean;
onDragDrop?: (e: DragEvent) => Promise<boolean>;
pasteFiles?: (files: File[]) => Promise<boolean | void>;
// Allow for other ComfyUI/LiteGraph properties
[key: string]: any;
}
/**
* Service Worker status reported via sync message.
*/
export interface SWStatus {
ready: boolean;
interceptEnabled: boolean;
keys: {
client: { loaded: boolean; fingerprint: string | null };
server: { loaded: boolean; fingerprint: string | null };
};
lastError: string | null;
}
/**
* Custom properties for Video Preview widgets.
*/
export interface VideoPreviewWidget {
type: string;
name: string;
element: HTMLElement;
value: any;
videoElement?: HTMLVideoElement;
videoUrl?: string;
videoInfo?: any;
computeLayoutSize?: () => { minHeight: number; minWidth: number };
updateLayout?: (width: number, height: number) => void;
[key: string]: any;
}
/**
* ComfyUI App instance with extra methods used in CryptIO.
*/
export interface CryptIOApp {
canvas: any;
rootGraph: any;
registerExtension: (extension: any) => void;
[key: string]: any;
}