@@ -134,6 +134,10 @@ class AutoCaptionApp {
134134 document . getElementById ( 'manual-check-updates-btn' ) . addEventListener ( 'click' , ( ) => this . checkForUpdates ( ) ) ;
135135 document . getElementById ( 'show-debug-logs-btn' ) . addEventListener ( 'click' , ( ) => this . openDebugLogs ( ) ) ;
136136
137+ // API Key Management in Settings
138+ document . getElementById ( 'settings-change-api-key-btn' ) . addEventListener ( 'click' , ( ) => this . changeApiKeyFromSettings ( ) ) ;
139+ document . getElementById ( 'settings-remove-api-key-btn' ) . addEventListener ( 'click' , ( ) => this . removeApiKeyFromSettings ( ) ) ;
140+
137141 // Theme selection
138142 document . getElementById ( 'theme-select' ) . addEventListener ( 'change' , ( e ) => {
139143 this . setTheme ( e . target . value ) ;
@@ -454,6 +458,9 @@ class AutoCaptionApp {
454458
455459 // Update last check info
456460 this . updateLastCheckInfo ( ) ;
461+
462+ // Check and update API key status
463+ await this . updateApiKeyStatus ( ) ;
457464 }
458465
459466 closeSettings ( ) {
@@ -1085,6 +1092,92 @@ class AutoCaptionApp {
10851092 console . error ( 'Error finishing onboarding:' , error ) ;
10861093 }
10871094 }
1095+
1096+ // API Key Management in Settings
1097+ async updateApiKeyStatus ( ) {
1098+ const statusDisplay = document . getElementById ( 'settings-api-key-status' ) ;
1099+ const indicator = document . getElementById ( 'settings-api-key-indicator' ) ;
1100+
1101+ try {
1102+ const result = await window . electronAPI . getApiKeyStatus ( ) ;
1103+ if ( result . success && result . hasApiKey ) {
1104+ statusDisplay . classList . remove ( 'not-configured' ) ;
1105+ statusDisplay . classList . add ( 'configured' ) ;
1106+ indicator . textContent = '✅ API Key Configured' ;
1107+ } else {
1108+ statusDisplay . classList . remove ( 'configured' ) ;
1109+ statusDisplay . classList . add ( 'not-configured' ) ;
1110+ indicator . textContent = '❌ No API Key Set' ;
1111+ }
1112+ } catch ( error ) {
1113+ console . error ( 'Error checking API key status:' , error ) ;
1114+ statusDisplay . classList . remove ( 'configured' ) ;
1115+ statusDisplay . classList . add ( 'not-configured' ) ;
1116+ indicator . textContent = '⚠️ Error checking status' ;
1117+ }
1118+ }
1119+
1120+ async changeApiKeyFromSettings ( ) {
1121+ // Close settings modal
1122+ this . closeSettings ( ) ;
1123+
1124+ // Show the main API key section
1125+ this . showApiKeySection ( ) ;
1126+
1127+ // Focus on the input
1128+ document . getElementById ( 'api-key-input' ) . focus ( ) ;
1129+ }
1130+
1131+ async removeApiKeyFromSettings ( ) {
1132+ const button = document . getElementById ( 'settings-remove-api-key-btn' ) ;
1133+ const originalText = button . innerHTML ;
1134+
1135+ // Show confirmation dialog
1136+ const confirmed = confirm ( 'Are you sure you want to remove your API key? You will need to enter it again to use the application.' ) ;
1137+
1138+ if ( ! confirmed ) {
1139+ return ;
1140+ }
1141+
1142+ // Show loading state
1143+ button . innerHTML = '<span>🔄 Removing...</span>' ;
1144+ button . disabled = true ;
1145+
1146+ try {
1147+ const result = await window . electronAPI . removeApiKey ( ) ;
1148+ if ( result . success ) {
1149+ // Update API key status
1150+ this . apiKeySet = false ;
1151+ await this . updateApiKeyStatus ( ) ;
1152+
1153+ // Show success message briefly
1154+ button . innerHTML = '<span>✅ Removed</span>' ;
1155+
1156+ // Reset UI to show API key section
1157+ setTimeout ( ( ) => {
1158+ this . closeSettings ( ) ;
1159+ this . showApiKeySection ( ) ;
1160+
1161+ // Show status message
1162+ const statusDiv = document . getElementById ( 'api-key-status' ) ;
1163+ this . showStatus ( statusDiv , '🗑️ API key removed. Please enter a new one to continue.' , 'error' ) ;
1164+ } , 1000 ) ;
1165+ } else {
1166+ button . innerHTML = '<span>❌ Failed</span>' ;
1167+ setTimeout ( ( ) => {
1168+ button . innerHTML = originalText ;
1169+ button . disabled = false ;
1170+ } , 2000 ) ;
1171+ }
1172+ } catch ( error ) {
1173+ console . error ( 'Error removing API key:' , error ) ;
1174+ button . innerHTML = '<span>❌ Error</span>' ;
1175+ setTimeout ( ( ) => {
1176+ button . innerHTML = originalText ;
1177+ button . disabled = false ;
1178+ } , 2000 ) ;
1179+ }
1180+ }
10881181}
10891182
10901183// Initialize the app when the DOM is loaded
0 commit comments