Suppose, right now it is 1:04 PM. First, 10 mins slot is 1:04 PM to 1:14 PM, the screenshot will be taken at any time randomly between 1:04 PM and 1:14 PM and once we reach 1:14 PM a new slot is from 1:14 PM to 1:24 PM and a random screenshot is taken between 1:14 PM and 1:24 PM. How do I achieve this, I am a beginner and struggling to build the logic required.
I want to make changes to setTimeout to make it execute randomly any time in a span of 10 minutes, just like how Upwork screen tracker works.
Here is my code.
const uploadFiles = (img) => {
// logic
const storageRef = ref(storage,
`/screenshots/${uuidv4()}`);
uploadString(storageRef, img,
"data_url").then((snapshot) => {
console.log("Uploaded a data_url string!");
});
};
let newTimeoutId;
const screenshot = async () => {
setTimeoutId(true);
const newTimeoutId = setTimeout(async () => {
const screenshotData = await
ipcRenderer.invoke("capture");
const string = new
Buffer.from(screenshotData).toString("base64");
const img = `data:image/png;base64,${string}`;
console.log(img);
uploadFiles(img);
screenshot();
}, 600000);
};
const stopScreenshot = () => {
setTimeoutId(false);
clearTimeout(newTimeoutId);
};