updateProfile method

Future<void> updateProfile(
  1. String profileId,
  2. Profile updatedProfile
)

Updates an existing profile with new settings.

profileId - ID of the profile to update updatedProfile - Updated profile data Throws an exception if profiles have not been loaded or if the profile ID doesn't exist.

Implementation

Future<void> updateProfile(String profileId, Profile updatedProfile) async {
  if (_profiles == null) {
    throw Exception('Launcher profiles not loaded');
  }

  if (!_profiles!.profiles.containsKey(profileId)) {
    throw Exception('Profile with ID $profileId not found');
  }

  final updatedProfiles = Map<String, Profile>.from(_profiles!.profiles);
  updatedProfiles[profileId] = updatedProfile;

  _profiles = LauncherProfiles(
    profiles: updatedProfiles,
    settings: _profiles!.settings,
    version: _profiles!.version,
  );

  if (_activeProfile != null && _activeProfile!.name == updatedProfile.name) {
    _activeProfile = updatedProfile;
  }

  await saveProfiles();
}