Repository: microsoft/terminal (language: cpp)

Issue:
Don't generate WSL distributions for Rancher Desktop
# Description of the new feature/enhancement

Feature request #3556 suggested blocking Terminal from auto-generating profiles for Docker Desktop's service WSL2 machines, and this was accepted and implemented.

[Rancher Desktop](https://github.com/rancher-sandbox/rancher-desktop) is a new alternative to Docker for Windows developed by Rancher/SUSE and optimised for containerd and Kubernetes; and it uses a similar WSL2-based backend with two managed service machines: `rancher-desktop` and `rancher-desktop-data`. This leads to Terminal auto-generating profiles for these machines, even if there is no practical reason to ever use them.

A workaround for this is to hide the two entries from the profile list with the Settings GUI or in settings.json:

```javascript
{
    "guid": "{1cd79813-5972-56cb-badb-ba5ee12693c5}",
    "hidden": true,
    "name": "rancher-desktop",
    "source": "Windows.Terminal.Wsl"
},
{
    "guid": "{1bdae7ec-8ca6-5caa-8453-8b6fe78b2748}",
    "hidden": true,
    "name": "rancher-desktop-data",
    "source": "Windows.Terminal.Wsl"
},
```

Terminal should extend this blocking feature to include Rancher Desktop's service machines too, with the likelihood of future apps bundling more WSL service machines in mind.

# Proposed technical implementation details (optional)

This could be achieved in a few different ways:

1. The quick fix, add more hard-coded rules to extend the code added in #4156, and hope that loads more apps don't start shipping bundled WSL distros.
2. Suggestion from #3556, use metadata to differentiate service machines from user machines during auto-generation. This should probably include an allowlist config option to override this automatic detection when necessary. I'm not sure how feasible this is, as I don't think there's any suitable existing metadata provided by WSL. Maybe the distributions themselves would have to provide some flag for Terminal to detect?
3. Provide a blocklist config option, which would allow:
    - Apps providing WSL distros to programmatically insert their service machine's names into `settings.json` during app installation
    - Users to manually specify machines to skip, which also allows service machine developers (like me) greater flexibility in general.

Main benefit of options 2 and 3 is eliminating the burden on the Terminal team of maintaining a hard-coded blocklist, and dealing with further requests like these in future. I could see both 2 and 3 in combination being the ideal solution in the long term.



Discussion / hints:
@benhillis & @craigloewen-msft as an FYI. 

Was there ever any further progress on enabling WSL dristros to mark themselves as service machines vs actual user-facing ones? That was a agood idea that I don't believe ever really got traction.

Manually suppressing these distros is easy, but that's just a game of wack-a-mole. I feel like if two different entities have done this now, it's only a matter of time till more copy the pattern. There needs to be a more official way to clearmy markup these distros. 
(I may also suggest posting a similar issue on the WSL repo to make sure this stays on their triage queue 😝)
Fragment extensions may be a good distro-driven way to handle this! It's worth checking out whether fragments can set `hidden` when updating a profile.

It's slightly worse than us not generating them, as they'll show up in the settings UI.
> (I may also suggest posting a similar issue on the WSL repo to make sure this stays on their triage queue 😝)

Doesn't look like a feature request was ever created on the WSL repo following up on the original metadata idea from #3556, so I'm not sure its even in their triage queue (unless there were off-GitHub discussions about it).

@zadjii-msft About posting a similar issue to WSL, were you talking to me or the WSL devs you tagged?
We may want to follow up on this discussion upstream in https://github.com/rancher-sandbox/rancher-desktop/issues/818. I don't totally think it's tenable for us to continually manually exclude applications that are doing weird things with WSL distros like this. A better way would be having some property that apps can set to mark their distros themselves as not user-facing, but I suspect that'll never happen (@craigloewen-msft can correct me if I'm wrong). 

Admittedly though, https://github.com/microsoft/terminal/pull/4156/files was super trivial and would not take a lot of work for someone to add additional distros there. As much as I'd prefer pursuing the _technically correct_ solution, just monkey-patching that would be the quickest way to the best results. 

> **Note**
> ## Walkthrough

Literally just copy #4156, for these two distros. 
@zadjii-msft we definitely have it on our backlog to have a way for distros to mark themselves as non-user facing, but it isn't on our short term roadmap yet.

Fix patch:
diff --git a/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp b/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp
index 373282866a6..2b656154adf 100644
--- a/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp
+++ b/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp
@@ -11,6 +11,7 @@
 
 static constexpr std::wstring_view WslHomeDirectory{ L"~" };
 static constexpr std::wstring_view DockerDistributionPrefix{ L"docker-desktop" };
+static constexpr std::wstring_view RancherDistributionPrefix{ L"rancher-desktop" };
 
 // The WSL entries are structured as such:
 // HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss
@@ -78,9 +79,9 @@ static void namesToProfiles(const std::vector<std::wstring>& names, std::vector<
 {
     for (const auto& distName : names)
     {
-        if (til::starts_with(distName, DockerDistributionPrefix))
+        if (til::starts_with(distName, DockerDistributionPrefix) || til::starts_with(distName, RancherDistributionPrefix))
         {
-            // Docker for Windows creates some utility distributions to handle Docker commands.
+            // Docker for Windows and Rancher for Windows creates some utility distributions to handle Docker commands.
             // Pursuant to GH#3556, because they are _not_ user-facing we want to hide them.
             continue;
         }


Test patch: