[win] Use fragment files for Windows Terminal#4869
Conversation
88c1171 to
b311a28
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4869 +/- ##
=======================================
Coverage 87.78% 87.78%
=======================================
Files 269 269
Lines 14573 14573
=======================================
Hits 12791 12791
Misses 1782 1782 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eed9804 to
cea3b20
Compare
| const auto profiles_path = locate_profiles_path(); | ||
| const auto winterm_setting = MP_SETTINGS.get(mp::winterm_key); | ||
| if (winterm_setting == none) | ||
| return; |
There was a problem hiding this comment.
The old implementation was hiding the profile if the setting was set to none. Is the behavior change intentional, or a regression?
There was a problem hiding this comment.
After reading the old implementation more carefully, I think there's a regression here. The behavior should be the same if the setting is primary or none the first time we run this hook. (If the setting is none and there's no Multipass profile, the old code did nothing.)
However, when changing the setting to none later, we should mark the profile as hidden. I'll fix that. We might be able to have the "hide this profile" flag exist as a separate JSON fragment, so hiding/unhiding is just a matter of creating/deleting the right file.
There was a problem hiding this comment.
Ok, I've implemented this by removing the JSON fragment when winterm_setting == none. (See the second commit in this PR.)
| mpl::debug(log_category, | ||
| "Multipass fragment for Windows Terminal already exists: {}", | ||
| mp_fragment_file.toStdString()); | ||
| return; |
There was a problem hiding this comment.
What if we decided to update the parameters in the fragment? Wouldn't returning here cause the existing profiles to go stale?
There was a problem hiding this comment.
Right. If we update the parameters, we'd need to update this code. I have a few ideas for how to do this; one could be to have a versioned filename (or include a hash of the contents in the filename), and then we know whether the profile is out of date without parsing the JSON.
There was a problem hiding this comment.
I've added a comment just above the definition of our profile fragment to remind any future authors to think about how to handle updating this config if we ever need to do so (not likely, in my estimation, but you never know).
| {"guid", mp::winterm_profile_guid}, | ||
| // FIXME: Before merging, rename this to "Multipass". The "fragmentized" suffix is | ||
| // just to make manual testing easier. | ||
| {"name", "Multipass (fragmentized)"}, |
There was a problem hiding this comment.
So, this file will hide the old profile and provide a new profile with the same name, correct? If so, is it okay for the profiles to have the same name?
There was a problem hiding this comment.
I'm open to any option here. We could give it a new name, or keep the old name.
One thing we can't do unfortunately is use JSON fragments to update the old profile's name. We'd have to modify it in the main settings.json, which I'd like to avoid. (Messing with the user's main settings file is a little riskier than messing with files Multipass owns.)
| @@ -1,6 +1,3 @@ | |||
| [submodule "3rd-party/jsoncpp"] | |||
| EXPECT_EQ(json, read_json(json_file_name)); | ||
| } | ||
|
|
||
| TEST_P(TestWinTermSyncJson, wintermSyncDisablesVisibleProfileIfSettingNone) |
There was a problem hiding this comment.
Relevant test cases to winterm=none ^^
There was a problem hiding this comment.
Added a test case here.
d09fda2 to
7abc320
Compare
7abc320 to
1a655b1
Compare
Description
This PR changes how we add our Windows Terminal configs to use fragment files. This is simpler and safer, since we don't need to parse the user's settings file. It also means we can use Boost.JSON here instead of jsoncpp (which supports adding comments to JSON), so we can remove jsoncpp as a dependency.
Testing
Unit tests updated to check the new code
Manual testing steps:
mainbranch, start the Multipass daemon and run any command (e.g.multipass list)multipass list)Checklist