da03 commited on
Commit
aa4dda5
·
1 Parent(s): 7bbe40c
Files changed (1) hide show
  1. static/index.html +74 -7
static/index.html CHANGED
@@ -112,7 +112,7 @@
112
 
113
  <div class="form-check form-switch">
114
  <input class="form-check-input" type="checkbox" role="switch" id="autoInputToggle" checked>
115
- <label class="form-check-label" for="autoInputToggle">Auto Input</label>
116
  </div>
117
  </div>
118
  </div>
@@ -129,7 +129,7 @@
129
  <li>Use your keyboard to type within the simulated environment</li>
130
  <li>Adjust sampling steps to control quality/speed tradeoff</li>
131
  <li>Toggle "Use RNN" to switch between RNN and diffusion mode</li>
132
- <li>Toggle "Auto Input" to enable/disable automatic frame generation during idle periods</li>
133
  </ul>
134
  </div>
135
  </div>
@@ -257,8 +257,11 @@
257
 
258
  // Auto-input mechanism
259
  let lastUserInputTime = 0;
 
260
  let autoInputInterval = null;
261
- const AUTO_INPUT_DELAY = 1000; // Send auto-input after 1 second of no user input
 
 
262
  let autoInputEnabled = true; // Default to enabled
263
 
264
  // Track currently pressed keys
@@ -271,8 +274,31 @@
271
 
272
  autoInputInterval = setInterval(() => {
273
  const currentTime = Date.now();
274
- if (autoInputEnabled && currentTime - lastUserInputTime >= AUTO_INPUT_DELAY && lastSentPosition && isConnected) {
275
- console.log("Sending auto-input (no user activity for 1 second)");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  try {
277
  socket.send(JSON.stringify({
278
  "x": lastSentPosition.x,
@@ -283,7 +309,7 @@
283
  "keys_up": [],
284
  "is_auto_input": true // Flag to identify auto-generated inputs
285
  }));
286
- updateLastUserInputTime();
287
  } catch (error) {
288
  console.error("Error sending auto-input:", error);
289
  }
@@ -296,10 +322,26 @@
296
  clearInterval(autoInputInterval);
297
  autoInputInterval = null;
298
  }
 
299
  }
300
 
301
  function updateLastUserInputTime() {
302
  lastUserInputTime = Date.now();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  }
304
 
305
  function sendInputState(x, y, isLeftClick = false, isRightClick = false) {
@@ -477,8 +519,33 @@
477
  console.log(`Auto-input ${autoInputEnabled ? 'enabled' : 'disabled'}`);
478
 
479
  if (autoInputEnabled) {
480
- // Reset the timer when enabling
481
  updateLastUserInputTime();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  }
483
  });
484
  </script>
 
112
 
113
  <div class="form-check form-switch">
114
  <input class="form-check-input" type="checkbox" role="switch" id="autoInputToggle" checked>
115
+ <label class="form-check-label" for="autoInputToggle" id="autoInputLabel">Auto Input</label>
116
  </div>
117
  </div>
118
  </div>
 
129
  <li>Use your keyboard to type within the simulated environment</li>
130
  <li>Adjust sampling steps to control quality/speed tradeoff</li>
131
  <li>Toggle "Use RNN" to switch between RNN and diffusion mode</li>
132
+ <li>Toggle "Auto Input" to enable automatic frame generation (starts after 5s idle, then runs every 1s)</li>
133
  </ul>
134
  </div>
135
  </div>
 
257
 
258
  // Auto-input mechanism
259
  let lastUserInputTime = 0;
260
+ let lastAutoInputTime = 0;
261
  let autoInputInterval = null;
262
+ let autoInputActive = false; // Track if auto-input mode is active
263
+ const INITIAL_AUTO_INPUT_DELAY = 5000; // Start auto-input after 5 seconds of no user input
264
+ const AUTO_INPUT_INTERVAL = 1000; // Send auto-input every 1 second once active
265
  let autoInputEnabled = true; // Default to enabled
266
 
267
  // Track currently pressed keys
 
274
 
275
  autoInputInterval = setInterval(() => {
276
  const currentTime = Date.now();
277
+
278
+ if (!autoInputEnabled || !lastSentPosition || !isConnected) {
279
+ return;
280
+ }
281
+
282
+ // Check if we should start auto-input mode
283
+ if (!autoInputActive && currentTime - lastUserInputTime >= INITIAL_AUTO_INPUT_DELAY) {
284
+ console.log("Starting auto-input mode (no user activity for 5 seconds)");
285
+ autoInputActive = true;
286
+ lastAutoInputTime = currentTime;
287
+ // Update UI to show auto-input is active
288
+ try {
289
+ const label = document.getElementById('autoInputLabel');
290
+ if (label) {
291
+ label.textContent = "Auto Input (Active)";
292
+ label.style.color = "#28a745";
293
+ }
294
+ } catch (error) {
295
+ console.error("Error updating auto-input UI:", error);
296
+ }
297
+ }
298
+
299
+ // Send auto-input if mode is active and enough time has passed
300
+ if (autoInputActive && currentTime - lastAutoInputTime >= AUTO_INPUT_INTERVAL) {
301
+ console.log("Sending auto-input (auto-input mode active)");
302
  try {
303
  socket.send(JSON.stringify({
304
  "x": lastSentPosition.x,
 
309
  "keys_up": [],
310
  "is_auto_input": true // Flag to identify auto-generated inputs
311
  }));
312
+ lastAutoInputTime = currentTime;
313
  } catch (error) {
314
  console.error("Error sending auto-input:", error);
315
  }
 
322
  clearInterval(autoInputInterval);
323
  autoInputInterval = null;
324
  }
325
+ autoInputActive = false; // Reset auto-input mode
326
  }
327
 
328
  function updateLastUserInputTime() {
329
  lastUserInputTime = Date.now();
330
+ // Reset auto-input mode when user provides input
331
+ if (autoInputActive) {
332
+ console.log("User activity detected, stopping auto-input mode");
333
+ autoInputActive = false;
334
+ // Reset UI indicator
335
+ try {
336
+ const label = document.getElementById('autoInputLabel');
337
+ if (label) {
338
+ label.textContent = "Auto Input";
339
+ label.style.color = "";
340
+ }
341
+ } catch (error) {
342
+ console.error("Error updating auto-input UI:", error);
343
+ }
344
+ }
345
  }
346
 
347
  function sendInputState(x, y, isLeftClick = false, isRightClick = false) {
 
519
  console.log(`Auto-input ${autoInputEnabled ? 'enabled' : 'disabled'}`);
520
 
521
  if (autoInputEnabled) {
522
+ // Reset the timers when enabling to start fresh
523
  updateLastUserInputTime();
524
+ lastAutoInputTime = 0;
525
+ autoInputActive = false;
526
+ // Reset UI indicator
527
+ try {
528
+ const label = document.getElementById('autoInputLabel');
529
+ if (label) {
530
+ label.textContent = "Auto Input";
531
+ label.style.color = "";
532
+ }
533
+ } catch (error) {
534
+ console.error("Error updating auto-input UI:", error);
535
+ }
536
+ } else {
537
+ // Stop auto-input mode when disabling
538
+ autoInputActive = false;
539
+ // Reset UI indicator
540
+ try {
541
+ const label = document.getElementById('autoInputLabel');
542
+ if (label) {
543
+ label.textContent = "Auto Input";
544
+ label.style.color = "";
545
+ }
546
+ } catch (error) {
547
+ console.error("Error updating auto-input UI:", error);
548
+ }
549
  }
550
  });
551
  </script>