Skip to content

Commit 8bfeb14

Browse files
committed
solved error when deleting profiles
1 parent d5ce76c commit 8bfeb14

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

config.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,36 @@ async function getCurrentProfileConfig() {
126126
logConfigurationRelatedStuff('Retrieving current profile from storage');
127127
try {
128128
const result = await chrome.storage.sync.get(['currentProfile']);
129-
const currentProfile = result.currentProfile;
129+
const profileName = result.currentProfile;
130130

131-
if (currentProfile) {
132-
logConfigurationRelatedStuff(`Current profile found: ${currentProfile}`);
133-
const profile = await loadProfileConfig(currentProfile);
131+
if (profileName) {
132+
logConfigurationRelatedStuff(`Current profile found: ${profileName}`);
133+
let profile = await loadProfileConfig(profileName);
134134
if (profile) {
135+
// Ensure the profile has a 'customButtons' property
136+
if (!profile.customButtons) {
137+
profile.customButtons = [];
138+
logConfigurationRelatedStuff(`Initialized missing 'customButtons' for profile: ${profileName}`);
139+
}
135140
return profile;
136141
}
137142
}
138143

139-
logConfigurationRelatedStuff('No current profile found. Creating default profile');
140-
return await createDefaultProfile();
144+
logConfigurationRelatedStuff('No valid current profile found. Creating default profile');
145+
const defaultProfile = await createDefaultProfile();
146+
// Ensure the default profile includes 'customButtons'
147+
if (!defaultProfile.customButtons) {
148+
defaultProfile.customButtons = [];
149+
logConfigurationRelatedStuff("Initialized missing 'customButtons' for default profile");
150+
}
151+
return defaultProfile;
141152
} catch (error) {
142153
handleStorageError(error);
143154
throw new Error('Unable to retrieve current profile configuration.');
144155
}
145156
}
146157

158+
147159
// Function to list all available profiles
148160
async function listProfiles() {
149161
try {

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

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

60-
// --- Added null check: If response.config is null, try to retrieve default profile ---
60+
let newConfig = null;
61+
62+
// If the primary response is missing config, attempt to retrieve via getConfig
6163
if (!response || !response.config) {
62-
logToConsole(`Error switching profile: received null config for profile "${profileName}". Attempting to retrieve default profile.`);
64+
logToConsole(`Warning: Received null config for profile "${profileName}". Attempting to retrieve default config...`);
6365
const configResponse = await chrome.runtime.sendMessage({ type: 'getConfig' });
6466
if (configResponse && configResponse.config) {
65-
currentProfile = configResponse.config;
67+
newConfig = configResponse.config;
6668
} else {
67-
logToConsole('Error retrieving default profile during switchProfile.');
69+
logToConsole('Error: Unable to retrieve default profile configuration during switchProfile.');
6870
return;
6971
}
7072
} else {
71-
currentProfile = response.config;
73+
newConfig = response.config;
7274
}
75+
76+
currentProfile = newConfig;
7377
updateInterface();
7478
logToConsole(`Switched to profile: ${profileName}`);
7579
updateSaveStatus();
@@ -78,6 +82,7 @@ async function switchProfile(profileName) {
7882
}
7983
}
8084

85+
8186
// -------------------------
8287
// 3. Add New Empty Profile
8388
// -------------------------

0 commit comments

Comments
 (0)