fix: harden AI subtitle fix response parsing

This commit is contained in:
2026-03-08 16:01:40 -07:00
parent 8e319a417d
commit 93cd688625
22 changed files with 641 additions and 55 deletions

View File

@@ -21,13 +21,17 @@ import { WindowGeometry } from '../types';
export type GeometryChangeCallback = (geometry: WindowGeometry) => void;
export type WindowFoundCallback = (geometry: WindowGeometry) => void;
export type WindowLostCallback = () => void;
export type WindowFocusChangeCallback = (focused: boolean) => void;
export abstract class BaseWindowTracker {
protected currentGeometry: WindowGeometry | null = null;
protected windowFound: boolean = false;
protected focusKnown: boolean = false;
protected windowFocused: boolean = false;
public onGeometryChange: GeometryChangeCallback | null = null;
public onWindowFound: WindowFoundCallback | null = null;
public onWindowLost: WindowLostCallback | null = null;
public onWindowFocusChange: WindowFocusChangeCallback | null = null;
abstract start(): void;
abstract stop(): void;
@@ -40,6 +44,19 @@ export abstract class BaseWindowTracker {
return this.windowFound;
}
isFocused(): boolean {
return this.focusKnown ? this.windowFocused : this.windowFound;
}
protected updateFocus(focused: boolean): void {
const changed = !this.focusKnown || this.windowFocused !== focused;
this.focusKnown = true;
this.windowFocused = focused;
if (changed) {
this.onWindowFocusChange?.(focused);
}
}
protected updateGeometry(newGeometry: WindowGeometry | null): void {
if (newGeometry) {
if (!this.windowFound) {
@@ -58,6 +75,12 @@ export abstract class BaseWindowTracker {
if (this.onGeometryChange) this.onGeometryChange(newGeometry);
}
} else {
const focusChanged = this.focusKnown && this.windowFocused;
this.focusKnown = false;
this.windowFocused = false;
if (focusChanged) {
this.onWindowFocusChange?.(false);
}
if (this.windowFound) {
this.windowFound = false;
this.currentGeometry = null;