AI-Studio/app/MindWork AI Studio/Settings/ProfilePreselection.cs
Thorsten Sommer 4a8348b9df
Some checks failed
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Added explicit profile behavior choices (#696)
2026-03-14 15:40:07 +01:00

55 lines
2.1 KiB
C#

namespace AIStudio.Settings;
public readonly record struct ProfilePreselection
{
public ProfilePreselectionMode Mode { get; }
public string SpecificProfileId { get; }
public bool UseAppDefault => this.Mode == ProfilePreselectionMode.USE_APP_DEFAULT;
public bool DoNotPreselectProfile => this.Mode == ProfilePreselectionMode.USE_NO_PROFILE;
public bool UseSpecificProfile => this.Mode == ProfilePreselectionMode.USE_SPECIFIC_PROFILE;
public static ProfilePreselection AppDefault => new(ProfilePreselectionMode.USE_APP_DEFAULT, string.Empty);
public static ProfilePreselection NoProfile => new(ProfilePreselectionMode.USE_NO_PROFILE, Profile.NO_PROFILE.Id);
private ProfilePreselection(ProfilePreselectionMode mode, string specificProfileId)
{
this.Mode = mode;
this.SpecificProfileId = specificProfileId;
}
public static ProfilePreselection Specific(string profileId)
{
if (string.IsNullOrWhiteSpace(profileId))
throw new ArgumentException("A specific profile preselection requires a profile ID.", nameof(profileId));
if (profileId.Equals(Profile.NO_PROFILE.Id, StringComparison.OrdinalIgnoreCase))
throw new ArgumentException("Use NoProfile for the NO_PROFILE selection.", nameof(profileId));
return new(ProfilePreselectionMode.USE_SPECIFIC_PROFILE, profileId);
}
public static ProfilePreselection FromStoredValue(string? storedValue)
{
if (string.IsNullOrWhiteSpace(storedValue))
return AppDefault;
if (storedValue.Equals(Profile.NO_PROFILE.Id, StringComparison.OrdinalIgnoreCase))
return NoProfile;
return new(ProfilePreselectionMode.USE_SPECIFIC_PROFILE, storedValue);
}
public static implicit operator string(ProfilePreselection preselection) => preselection.Mode switch
{
ProfilePreselectionMode.USE_APP_DEFAULT => string.Empty,
ProfilePreselectionMode.USE_NO_PROFILE => Profile.NO_PROFILE.Id,
ProfilePreselectionMode.USE_SPECIFIC_PROFILE => preselection.SpecificProfileId,
_ => string.Empty,
};
}