Skip to content

Commit 72373d1

Browse files
fix(web): recover Android fold controls after request failures
1 parent 8d53b16 commit 72373d1

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

‎apps/web/src/components/device/DeviceAndroidFoldControls.tsx‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ export function DeviceAndroidFoldControls(props: {
3636
if (!props.visible || !props.enabled || pending || !props.screenWidth || !props.screenHeight)
3737
return;
3838
const controller = new AbortController();
39-
void readAndroidFold(props.access, props.deviceId, controller.signal)
40-
.then((next) => {
41-
if (!controller.signal.aborted) setFold(next);
42-
})
43-
.catch(() => {
44-
if (!controller.signal.aborted) setFold(null);
45-
});
46-
return () => controller.abort();
39+
let retry: number | undefined;
40+
const read = () => {
41+
void readAndroidFold(props.access, props.deviceId, controller.signal)
42+
.then((next) => {
43+
if (!controller.signal.aborted) setFold(next);
44+
})
45+
.catch(() => {
46+
if (!controller.signal.aborted) retry = window.setTimeout(read, 3_000);
47+
});
48+
};
49+
read();
50+
return () => {
51+
controller.abort();
52+
window.clearTimeout(retry);
53+
};
4754
}, [
4855
props.access,
4956
props.deviceId,
@@ -61,15 +68,24 @@ export function DeviceAndroidFoldControls(props: {
6168
busy.current = true;
6269
setPending(true);
6370
setError(null);
64-
void setAndroidFold(props.access, props.deviceId, posture)
71+
const controller = new AbortController();
72+
const timeout = window.setTimeout(() => controller.abort(), 12_000);
73+
void setAndroidFold(props.access, props.deviceId, posture, controller.signal)
6574
.then((next) => {
6675
if (mounted.current) setFold(next);
6776
})
6877
.catch((cause: unknown) => {
6978
if (mounted.current)
70-
setError(cause instanceof Error ? cause.message : "Could not change fold posture.");
79+
setError(
80+
controller.signal.aborted
81+
? "Fold command timed out."
82+
: cause instanceof Error
83+
? cause.message
84+
: "Could not change fold posture.",
85+
);
7186
})
7287
.finally(() => {
88+
window.clearTimeout(timeout);
7389
busy.current = false;
7490
if (mounted.current) setPending(false);
7591
});

‎apps/web/src/components/device/deviceFold.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ export const setAndroidFold = (
6868
access: DeviceHubAccess,
6969
deviceId: string,
7070
posture: AndroidFoldPosture,
71-
) => foldRequest(access, deviceId, posture);
71+
signal?: AbortSignal,
72+
) => foldRequest(access, deviceId, posture, signal);

0 commit comments

Comments
 (0)