Skip to content

Commit d5ce76c

Browse files
committed
works, but errors
1 parent 4ef7041 commit d5ce76c

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

popup-page-scripts/popup-page-profiles.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ async function switchProfile(profileName) {
5757
profileName: profileName
5858
});
5959

60-
currentProfile = response.config;
60+
// --- Added null check: If response.config is null, try to retrieve default profile ---
61+
if (!response || !response.config) {
62+
logToConsole(`Error switching profile: received null config for profile "${profileName}". Attempting to retrieve default profile.`);
63+
const configResponse = await chrome.runtime.sendMessage({ type: 'getConfig' });
64+
if (configResponse && configResponse.config) {
65+
currentProfile = configResponse.config;
66+
} else {
67+
logToConsole('Error retrieving default profile during switchProfile.');
68+
return;
69+
}
70+
} else {
71+
currentProfile = response.config;
72+
}
6173
updateInterface();
6274
logToConsole(`Switched to profile: ${profileName}`);
6375
updateSaveStatus();
@@ -162,24 +174,33 @@ async function copyCurrentProfile(newProfileName) {
162174
* Deletes the current profile.
163175
*/
164176
async function deleteCurrentProfile() {
165-
if (currentProfile.PROFILE_NAME === 'Default') {
177+
// --- Modified deletion logic for safety ---
178+
// Check that currentProfile is defined and has a PROFILE_NAME property.
179+
if (!currentProfile || !currentProfile.PROFILE_NAME) {
180+
showToast('No profile is loaded to delete.', 'error');
181+
return;
182+
}
183+
184+
const profileName = currentProfile.PROFILE_NAME;
185+
186+
if (profileName === 'Default') {
166187
alert('Cannot delete Default profile');
167188
return;
168189
}
169190

170-
if (!confirm(`Delete profile "${currentProfile.PROFILE_NAME}"?`)) return;
191+
if (!confirm(`Delete profile "${profileName}"?`)) return;
171192

172193
try {
173194
await chrome.runtime.sendMessage({
174195
type: 'deleteProfile',
175-
profileName: currentProfile.PROFILE_NAME
196+
profileName: profileName
176197
});
177198

178199
await loadProfiles();
179-
logToConsole(`Deleted profile: ${currentProfile.PROFILE_NAME}`);
180-
showToast(`Profile "${currentProfile.PROFILE_NAME}" deleted successfully.`, 'success');
200+
logToConsole(`Deleted profile: ${profileName}`);
201+
showToast(`Profile "${profileName}" deleted successfully.`, 'success');
181202
} catch (error) {
182203
showToast(`Error deleting profile: ${error.message}`, 'error');
183204
logToConsole(`Error deleting profile: ${error.message}`);
184205
}
185-
}
206+
}

popup-page-scripts/popup-page-script.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ function updateSaveStatus() {
110110
* Updates the entire interface based on the current profile.
111111
*/
112112
function updateInterface() {
113+
// --- Added guard to check if currentProfile is valid ---
114+
if (!currentProfile || !currentProfile.customButtons) {
115+
logToConsole('No valid current profile found. Attempting to retrieve default profile...');
116+
chrome.runtime.sendMessage({ type: 'getConfig' }, (response) => {
117+
if (response && response.config) {
118+
currentProfile = response.config;
119+
updateInterface(); // Call updateInterface again after retrieving default
120+
} else {
121+
logToConsole('Failed to retrieve default profile in updateInterface.');
122+
}
123+
});
124+
return;
125+
}
113126
// Update buttons, settings, etc. based on currentProfile
114127
updateButtonList();
115128
document.getElementById('autoSendToggle').checked = currentProfile.globalAutoSendEnabled;
@@ -267,11 +280,9 @@ document.addEventListener('DOMContentLoaded', () => {
267280
textareaSaverAndResizerFunc();
268281
attachEmojiInputListeners();
269282
attachAutoSendToggleListeners();
270-
// Call the function for your specific textarea by ID
283+
// Call the function for your specific textarea by ID
271284
textareaInputAreaResizerFun('buttonText');
272285

273-
274-
275286
// -------------------------
276287
// Open external links in new tabs
277288
// -------------------------
@@ -456,7 +467,6 @@ function textareaInputAreaResizerFun(textareaId) {
456467
resizeTextarea();
457468
}
458469

459-
460470
/**
461471
* Attaches input listeners to emoji input fields to update button icons.
462472
*/
@@ -488,7 +498,6 @@ function attachAutoSendToggleListeners() {
488498
});
489499
}
490500

491-
492501
/**
493502
* Clears the text in the button text input field.
494503
*/

0 commit comments

Comments
 (0)