Keep focused agent timelines live and catch up instantly (#2196)
* 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
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { isAppActivelyVisible, isAppVisible } from "./app-visibility";
|
||||
|
||||
test("a visible desktop app remains visible when another window has focus", () => {
|
||||
const input = {
|
||||
appState: "active",
|
||||
native: false,
|
||||
documentVisible: true,
|
||||
windowFocused: false,
|
||||
};
|
||||
|
||||
expect(isAppVisible(input)).toBe(true);
|
||||
expect(isAppActivelyVisible(input)).toBe(false);
|
||||
});
|
||||
|
||||
test("a hidden desktop page is neither visible nor actively visible", () => {
|
||||
const input = {
|
||||
appState: "active",
|
||||
native: false,
|
||||
documentVisible: false,
|
||||
windowFocused: true,
|
||||
};
|
||||
|
||||
expect(isAppVisible(input)).toBe(false);
|
||||
expect(isAppActivelyVisible(input)).toBe(false);
|
||||
});
|
||||
@@ -1,20 +1,49 @@
|
||||
import { AppState } from "react-native";
|
||||
import { isNative } from "@/constants/platform";
|
||||
|
||||
export function getIsAppActivelyVisible(appState: string = AppState.currentState): boolean {
|
||||
if (appState !== "active") {
|
||||
return false;
|
||||
}
|
||||
interface AppVisibilityInput {
|
||||
appState: string;
|
||||
native: boolean;
|
||||
documentVisible: boolean;
|
||||
}
|
||||
|
||||
if (isNative) {
|
||||
return true;
|
||||
}
|
||||
interface ActiveAppVisibilityInput extends AppVisibilityInput {
|
||||
windowFocused: boolean;
|
||||
}
|
||||
|
||||
const documentVisible = typeof document === "undefined" || document.visibilityState === "visible";
|
||||
const windowFocused =
|
||||
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();
|
||||
document.hasFocus()
|
||||
);
|
||||
}
|
||||
|
||||
return documentVisible && windowFocused;
|
||||
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(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user