Spaces:
Running

michdubai commited on
Commit
dd86ef3
·
verified ·
1 Parent(s): 7910bbe

Update frontend/js/ui-controller.js

Browse files
Files changed (1) hide show
  1. frontend/js/ui-controller.js +101 -0
frontend/js/ui-controller.js CHANGED
@@ -44,6 +44,8 @@ export class UIController {
44
  this.initTheme();
45
  this.initLayoutControls();
46
  this.initAdvancedPanel();
 
 
47
  }
48
 
49
  /**
@@ -298,6 +300,105 @@ export class UIController {
298
  });
299
  }
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  setIndicatorState(name, active, pulsing = false) {
302
  const el = this.elements[`${name}Indicator`];
303
  if (!el) return;
 
44
  this.initTheme();
45
  this.initLayoutControls();
46
  this.initAdvancedPanel();
47
+ this.loadSettings();
48
+ this.initSettingsPersistence();
49
  }
50
 
51
  /**
 
300
  });
301
  }
302
 
303
+ /**
304
+ * Load persisted settings from localStorage
305
+ */
306
+ loadSettings() {
307
+ try {
308
+ const raw = localStorage.getItem('gemini_live_settings');
309
+ if (!raw) return;
310
+ const settings = JSON.parse(raw);
311
+
312
+ if (settings.systemPrompt !== undefined && this.elements.systemPrompt) {
313
+ this.elements.systemPrompt.value = settings.systemPrompt;
314
+ }
315
+ if (settings.voice !== undefined && this.elements.voice) {
316
+ this.elements.voice.value = settings.voice;
317
+ }
318
+ if (settings.model !== undefined && this.elements.modelSelect) {
319
+ this.elements.modelSelect.value = settings.model;
320
+ }
321
+ if (settings.googleSearch !== undefined && this.elements.enableGoogleSearch) {
322
+ this.elements.enableGoogleSearch.checked = settings.googleSearch;
323
+ }
324
+ if (settings.allowInterruptions !== undefined && this.elements.allowInterruptions) {
325
+ this.elements.allowInterruptions.checked = settings.allowInterruptions;
326
+ }
327
+ if (settings.modalityAudio !== undefined && this.elements.modalityAudio) {
328
+ this.elements.modalityAudio.checked = settings.modalityAudio;
329
+ }
330
+ if (settings.modalityText !== undefined && this.elements.modalityText) {
331
+ this.elements.modalityText.checked = settings.modalityText;
332
+ }
333
+ if (settings.toolExecutionMode !== undefined && this.elements.toolExecutionMode) {
334
+ this.elements.toolExecutionMode.value = settings.toolExecutionMode;
335
+ }
336
+ if (settings.toolsJson !== undefined && this.elements.toolsJson) {
337
+ this.elements.toolsJson.value = settings.toolsJson;
338
+ }
339
+ } catch (e) {
340
+ console.warn('Failed to load settings:', e);
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Persist current settings to localStorage
346
+ */
347
+ saveSettings() {
348
+ try {
349
+ const settings = {
350
+ systemPrompt: this.elements.systemPrompt ? this.elements.systemPrompt.value : '',
351
+ voice: this.elements.voice ? this.elements.voice.value : '',
352
+ model: this.elements.modelSelect ? this.elements.modelSelect.value : '',
353
+ googleSearch: this.elements.enableGoogleSearch ? this.elements.enableGoogleSearch.checked : false,
354
+ allowInterruptions: this.elements.allowInterruptions ? this.elements.allowInterruptions.checked : false,
355
+ modalityAudio: this.elements.modalityAudio ? this.elements.modalityAudio.checked : true,
356
+ modalityText: this.elements.modalityText ? this.elements.modalityText.checked : true,
357
+ toolExecutionMode: this.elements.toolExecutionMode ? this.elements.toolExecutionMode.value : '',
358
+ toolsJson: this.elements.toolsJson ? this.elements.toolsJson.value : '',
359
+ };
360
+ localStorage.setItem('gemini_live_settings', JSON.stringify(settings));
361
+ } catch (e) {
362
+ console.warn('Failed to save settings:', e);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Attach auto-save listeners to all setting inputs
368
+ */
369
+ initSettingsPersistence() {
370
+ const inputs = [
371
+ this.elements.systemPrompt,
372
+ this.elements.voice,
373
+ this.elements.modelSelect,
374
+ this.elements.enableGoogleSearch,
375
+ this.elements.allowInterruptions,
376
+ this.elements.modalityAudio,
377
+ this.elements.modalityText,
378
+ this.elements.toolExecutionMode,
379
+ this.elements.toolsJson,
380
+ ];
381
+
382
+ const save = () => this.saveSettings();
383
+ const debouncedSave = this._debounce(save, 500);
384
+
385
+ inputs.forEach(el => {
386
+ if (!el) return;
387
+ el.addEventListener('change', save);
388
+ if (el.tagName === 'TEXTAREA' || el.type === 'text') {
389
+ el.addEventListener('input', debouncedSave);
390
+ }
391
+ });
392
+ }
393
+
394
+ _debounce(fn, ms) {
395
+ let timer;
396
+ return () => {
397
+ clearTimeout(timer);
398
+ timer = setTimeout(fn, ms);
399
+ };
400
+ }
401
+
402
  setIndicatorState(name, active, pulsing = false) {
403
  const el = this.elements[`${name}Indicator`];
404
  if (!el) return;