Skip to content

Commit 06b4c0d

Browse files
1 parent 3b1ae0c commit 06b4c0d

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

css/style.css

+36
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,40 @@ body {
481481
.audio-bar.active {
482482
animation: audio-pulse 0.5s infinite;
483483
}
484+
485+
#api-key-container {
486+
margin-bottom: 20px;
487+
padding: 15px;
488+
background: #f8f9fa;
489+
border-radius: 8px;
490+
border: 1px solid #dee2e6;
491+
display: none; /* Hidden by default, shown when no API key is set */
492+
}
493+
494+
#api-key-container input {
495+
width: calc(100% - 220px);
496+
padding: 8px;
497+
margin-right: 10px;
498+
border: 1px solid #ced4da;
499+
border-radius: 4px;
500+
}
501+
502+
#api-key-container button {
503+
padding: 8px 16px;
504+
background: #34a853;
505+
color: white;
506+
border: none;
507+
border-radius: 4px;
508+
cursor: pointer;
509+
}
510+
511+
#api-key-container a {
512+
margin-left: 10px;
513+
color: #4285f4;
514+
text-decoration: none;
515+
}
516+
517+
#api-key-container a:hover {
518+
text-decoration: underline;
519+
}
484520

index.html

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
</head>
1010
<body>
1111
<div id="app">
12+
<div id="api-key-container">
13+
<input type="password" id="api-key-input" placeholder="Enter your Google AI Studio API key">
14+
<button id="save-api-key">Save API Key</button>
15+
<a href="https://aistudio.google.com/apikey" target="_blank" rel="noopener noreferrer">Get API Key</a>
16+
</div>
1217
<button id="connect-button">Connect</button>
1318
<div id="logs-container"></div>
1419
<input type="text" id="message-input" placeholder="Enter message...">

js/main.js

+44
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const screenIcon = document.getElementById('screen-icon');
2727
const screenContainer = document.getElementById('screen-container');
2828
const screenPreview = document.getElementById('screen-preview');
2929
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');
3033

3134
// State variables
3235
let isRecording = false;
@@ -40,6 +43,7 @@ let isScreenSharing = false;
4043
let screenRecorder = null;
4144
let isUsingTool = false;
4245
let client = null;
46+
let apiKey = localStorage.getItem('gemini_api_key');
4347

4448
/**
4549
* Logs a message to the UI.
@@ -194,6 +198,37 @@ async function resumeAudioContext() {
194198
}
195199
}
196200

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+
197232
/**
198233
* Connects to the WebSocket server.
199234
*/
@@ -505,4 +540,13 @@ function stopScreenSharing() {
505540

506541
screenButton.addEventListener('click', handleScreenShare);
507542
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
508552

0 commit comments

Comments
 (0)