@@ -27,6 +27,9 @@ const screenIcon = document.getElementById('screen-icon');
27
27
const screenContainer = document . getElementById ( 'screen-container' ) ;
28
28
const screenPreview = document . getElementById ( 'screen-preview' ) ;
29
29
const inputAudioVisualizer = document . getElementById ( 'input-audio-visualizer' ) ;
30
+ const apiKeyContainer = document . getElementById ( 'api-key-container' ) ;
31
+ const apiKeyInput = document . getElementById ( 'api-key-input' ) ;
32
+ const saveApiKeyButton = document . getElementById ( 'save-api-key' ) ;
30
33
31
34
// State variables
32
35
let isRecording = false ;
@@ -40,6 +43,7 @@ let isScreenSharing = false;
40
43
let screenRecorder = null ;
41
44
let isUsingTool = false ;
42
45
let client = null ;
46
+ let apiKey = localStorage . getItem ( 'gemini_api_key' ) ;
43
47
44
48
/**
45
49
* Logs a message to the UI.
@@ -194,6 +198,37 @@ async function resumeAudioContext() {
194
198
}
195
199
}
196
200
201
+ /**
202
+ * Handles the API key management
203
+ */
204
+ function handleApiKey ( ) {
205
+ apiKey = localStorage . getItem ( 'gemini_api_key' ) ;
206
+ if ( ! apiKey ) {
207
+ apiKeyContainer . style . display = 'block' ;
208
+ connectButton . disabled = true ;
209
+ } else {
210
+ apiKeyContainer . style . display = 'none' ;
211
+ connectButton . disabled = false ;
212
+ CONFIG . API . KEY = apiKey ;
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Saves the API key to localStorage
218
+ */
219
+ function saveApiKey ( ) {
220
+ const newApiKey = apiKeyInput . value . trim ( ) ;
221
+ if ( newApiKey ) {
222
+ apiKey = newApiKey ;
223
+ localStorage . setItem ( 'gemini_api_key' , apiKey ) ;
224
+ CONFIG . API . KEY = apiKey ;
225
+ apiKeyContainer . style . display = 'none' ;
226
+ connectButton . disabled = false ;
227
+ apiKeyInput . value = '' ;
228
+ logMessage ( 'API key saved successfully' , 'system' ) ;
229
+ }
230
+ }
231
+
197
232
/**
198
233
* Connects to the WebSocket server.
199
234
*/
@@ -505,4 +540,13 @@ function stopScreenSharing() {
505
540
506
541
screenButton . addEventListener ( 'click' , handleScreenShare ) ;
507
542
screenButton . disabled = true ;
543
+
544
+ saveApiKeyButton . addEventListener ( 'click' , saveApiKey ) ;
545
+ apiKeyInput . addEventListener ( 'keypress' , ( event ) => {
546
+ if ( event . key === 'Enter' ) {
547
+ saveApiKey ( ) ;
548
+ }
549
+ } ) ;
550
+
551
+ handleApiKey ( ) ; // Call this when the page loads
508
552
0 commit comments