Start fixing MDI

This commit is contained in:
2025-04-22 13:54:57 +02:00
parent 792272a478
commit f3b508c9f7
8 changed files with 461 additions and 228 deletions

View File

@@ -53,26 +53,52 @@ export class ProfileManager extends EventEmitter {
try {
const storedProfiles = localStorage.getItem(this.storageKey);
console.log('Retrieved from localStorage:', storedProfiles);
if (storedProfiles) {
this.profiles = JSON.parse(storedProfiles);
console.log('Loaded profiles from localStorage:', this.profiles);
this.emit('profilesLoaded', this.profiles);
const parsed = JSON.parse(storedProfiles);
console.log('Parsed profiles:', parsed);
// Validate profiles before assigning
if (Array.isArray(parsed)) {
// Filter out invalid profiles
this.profiles = parsed.filter(profile => this.isValidProfile(profile));
console.log('Loaded profiles from localStorage:', this.profiles);
if (this.profiles.length > 0) {
this.emit('profilesLoaded', this.profiles);
return; // Success, exit early
} else {
console.warn('No valid profiles found in stored data, creating default');
}
} else {
console.warn('Stored profiles data is not an array, creating default');
}
} else {
console.log('No profiles found in localStorage, creating default profile');
// Add a default profile if none exist
const defaultProfile = this.createDefaultProfile();
defaultProfile.name = 'Aardwolf MUD';
defaultProfile.host = 'aardmud.org';
defaultProfile.port = 23;
this.addProfile(defaultProfile);
}
// If we got here, we need to create a default profile
const defaultProfile = this.createDefaultProfile();
defaultProfile.name = 'Aardwolf MUD';
defaultProfile.host = 'aardmud.org';
defaultProfile.port = 23;
// Clear profiles array and add the default
this.profiles = [];
this.addProfile(defaultProfile);
} catch (error) {
console.error('Failed to load profiles from local storage:', error);
console.error('Error details:', error.message, error.stack);
// Add a default profile if there was an error
const defaultProfile = this.createDefaultProfile();
defaultProfile.name = 'Aardwolf MUD';
defaultProfile.host = 'aardmud.org';
defaultProfile.port = 23;
// Clear profiles array and add the default
this.profiles = [];
this.addProfile(defaultProfile);
}
}
@@ -86,9 +112,21 @@ export class ProfileManager extends EventEmitter {
}
try {
localStorage.setItem(this.storageKey, JSON.stringify(this.profiles));
// Add logging to help debug
console.log('Saving profiles to localStorage:', this.profiles);
const profilesJson = JSON.stringify(this.profiles);
console.log('Profiles JSON:', profilesJson);
localStorage.setItem(this.storageKey, profilesJson);
console.log('Profiles saved successfully');
// Validate by reading back
const readBack = localStorage.getItem(this.storageKey);
console.log('Read back from localStorage:', readBack);
} catch (error) {
console.error('Failed to save profiles to local storage:', error);
console.error('Error details:', error.message, error.stack);
}
}