mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-21 00:11:27 -07:00
fix: harden AI subtitle fix response parsing
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user