Skip to content

Commit

Permalink
fix(vsix): preserve the selected profile when chosen first
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 17, 2024
1 parent 59747b7 commit c4873dc
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/Uno.UI.RemoteControl.VS/EntryPoint.ActiveProfileSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,40 @@ private async Task OnDebugFrameworkChangedAsync(string? previousFramework, strin

var profiles = await _debuggerObserver.GetLaunchProfilesAsync();

if (targetFrameworkIdentifier == WasmTargetFrameworkIdentifier)
var profileFilter = targetFrameworkIdentifier switch
{
if (profiles.Find(p => p.LaunchBrowser) is { } browserProfile)
{
_debugAction?.Invoke($"Setting profile {browserProfile.Name}");
WasmTargetFrameworkIdentifier
=> ((ILaunchProfile p) => p.LaunchBrowser),

await _debuggerObserver.SetActiveLaunchProfileAsync(browserProfile.Name);
}
}
else if (targetFrameworkIdentifier == DesktopTargetFrameworkIdentifier)
{
bool IsCompatible(ILaunchProfile profile)
=> profile.OtherSettings.TryGetValue(CompatibleTargetFrameworkProfileKey, out var compatibleTargetFramework)
&& compatibleTargetFramework is string ctfs
&& ctfs.Equals(DesktopTargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase);
DesktopTargetFrameworkIdentifier
=> (ILaunchProfile profile)
=> profile.OtherSettings.TryGetValue(CompatibleTargetFrameworkProfileKey, out var compatibleTargetFramework)
&& compatibleTargetFramework is string ctfs
&& ctfs.Equals(DesktopTargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase),

if (profiles.Find(IsCompatible) is { } desktopProfile)
{
_debugAction?.Invoke($"Setting profile {desktopProfile.Name}");
Windows10TargetFrameworkIdentifier
=> (ILaunchProfile p) => p.CommandName.Equals("MsixPackage", StringComparison.OrdinalIgnoreCase),

await _debuggerObserver.SetActiveLaunchProfileAsync(desktopProfile.Name);
}
}
else if (targetFrameworkIdentifier == Windows10TargetFrameworkIdentifier)
_ => (Func<ILaunchProfile, bool>?)null
};

if (profileFilter is not null)
{
if (profiles.Find(p => p.CommandName.Equals("MsixPackage", StringComparison.OrdinalIgnoreCase)) is { } msixProfile)
// If the current profile already matches the targetframework we're going to
// prefer using it. It can happen if the change is initiated through the profile
// selector.
var currentCompatible = profiles
.Where(profileFilter)
.FirstOrDefault(p => p.Name == _debuggerObserver.CurrentActiveDebugProfile);

// Otherwise, select the first compatible profile.
var firstCompatible = profiles.Find(p => profileFilter(p));

if ((currentCompatible ?? firstCompatible) is { } profile)
{
_debugAction?.Invoke($"Setting profile {msixProfile.Name}");
_debugAction?.Invoke($"Setting profile {profile}");

await _debuggerObserver.SetActiveLaunchProfileAsync(msixProfile.Name);
await _debuggerObserver.SetActiveLaunchProfileAsync(profile.Name);
}
}

Expand Down

0 comments on commit c4873dc

Please sign in to comment.