Files
discord-decomp/modules/collectibles/profile_effects/useClock.tsx
T
2026-11-01 12:12:55 +02:00

95 lines
2.9 KiB
TypeScript

// Metro module 8064 (f8065).
import { useRef, useCallback, useEffect } from "react";
import Module38 from "../../../_bundle/Module38";
import useMountEffect from "../../../hooks/useMountEffect";
export default function _default(a0) {
let callback2, callback3;
let c16232_0 = a0;
let r4 = arguments[1];
if (r4 === void 0) {
r4 = {};
}
let minInterval = r4.minInterval;
if (minInterval === void 0) {
minInterval = 41.666666666666664;
}
const current = minInterval;
const { allowableMinInterval, droppedFramesCallbackThreshold, droppedFramesCallback, droppedFramesResetTime = 3000 } = r4;
let c16232_5 = droppedFramesResetTime;
callback2 = void 0;
callback3 = void 0;
const ref = useRef(current);
const ref2 = useRef(0);
const ref3 = useRef(void 0);
const ref4 = useRef(void 0);
const ref5 = useRef(true);
const ref6 = useRef(0);
const ref7 = useRef(void 0);
const callback = useCallback(() => {
ref6.current = 0;
if (ref7.current != null) {
clearTimeout(ref7.current);
ref7.current = void 0;
}
}, []);
callback2 = useCallback(() => {
ref5.current = false;
cancelAnimationFrame(ref2.current);
clearTimeout(ref7.current);
}, []);
callback3 = useCallback((a0) => {
if (ref5.current) {
if (ref3.current == null) {
ref3.current = a0;
}
if (ref4.current == null) {
ref4.current = a0;
}
const r6 = a0 - ref4.current;
const r10 = a0 - ref3.current;
const r14 = Math;
let r12 = allowableMinInterval;
if (allowableMinInterval == null) {
r12 = 120;
}
if (r10 > 1.5 * r14.min(r12, ref.current)) {
ref6.current = ref6.current + 1;
if (ref7.current != null) {
clearTimeout(ref7.current);
}
ref7.current = setTimeout(callback, c16232_5);
if (droppedFramesCallbackThreshold != null && ref6.current > droppedFramesCallbackThreshold) {
Module38(droppedFramesCallback != null, "useClock - If you set a dropped frames threshold, you must provide a droppedFramesCallback to do something when that threshold is hit");
if (droppedFramesCallback()) {
ref6.current = 0;
}
}
}
ref3.current = a0;
if (r6 >= ref.current - 3) {
ref4.current = a0;
c16232_0(r6);
}
ref2.current = requestAnimationFrame(callback3);
}
}, [allowableMinInterval, callback, droppedFramesResetTime, droppedFramesCallbackThreshold, droppedFramesCallback, a0]);
const callback4 = useCallback(() => {
ref5.current = true;
ref4.current = void 0;
cancelAnimationFrame(ref2.current);
ref2.current = requestAnimationFrame(callback3);
}, [callback3]);
useEffect(() => {
ref.current = current;
}, [current]);
useMountEffect(() => {
ref2.current = requestAnimationFrame(callback3);
return () => callback2();
});
return {
stop: callback2,
reset: callback4,
ticking: ref5
};
};