* fix(app): keep focused agent timelines live Window focus was conflated with app visibility, so switching OS windows could remove the selected timeline subscription. Separate those signals, grace every visibility-driven removal, and cover retained history until authoritative catch-up completes. * fix(app): keep timeline catch-up failures non-blocking * fix(app): surface timeline catch-up failures * fix(app): preserve file preview refocus * fix(app): preserve optimistic catch-up flow
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { AppState } from "react-native";
|
|
import { isNative } from "@/constants/platform";
|
|
|
|
interface AppVisibilityInput {
|
|
appState: string;
|
|
native: boolean;
|
|
documentVisible: boolean;
|
|
}
|
|
|
|
interface ActiveAppVisibilityInput extends AppVisibilityInput {
|
|
windowFocused: boolean;
|
|
}
|
|
|
|
export function isAppVisible(input: AppVisibilityInput): boolean {
|
|
return input.appState === "active" && (input.native || input.documentVisible);
|
|
}
|
|
|
|
export function isAppActivelyVisible(input: ActiveAppVisibilityInput): boolean {
|
|
return isAppVisible(input) && (input.native || input.windowFocused);
|
|
}
|
|
|
|
function getDocumentVisible(): boolean {
|
|
return typeof document === "undefined" || document.visibilityState === "visible";
|
|
}
|
|
|
|
function getWindowFocused(): boolean {
|
|
return (
|
|
typeof document === "undefined" ||
|
|
typeof document.hasFocus !== "function" ||
|
|
document.hasFocus()
|
|
);
|
|
}
|
|
|
|
export function getIsAppVisible(appState: string = AppState.currentState): boolean {
|
|
return isAppVisible({
|
|
appState,
|
|
native: isNative,
|
|
documentVisible: getDocumentVisible(),
|
|
});
|
|
}
|
|
|
|
export function getIsAppActivelyVisible(appState: string = AppState.currentState): boolean {
|
|
return isAppActivelyVisible({
|
|
appState,
|
|
native: isNative,
|
|
documentVisible: getDocumentVisible(),
|
|
windowFocused: getWindowFocused(),
|
|
});
|
|
}
|