Skip to content

Commit

Permalink
Use a different schema for each branding (#15856)
Browse files Browse the repository at this point in the history
Switch the schema depending on the branding we're being built for

Ever since we started writing the entire settings file out ourselves,
we've had the opportunity to control which schema it uses.

This is a quality-of-life improvement for Preview users, and might make
life easier for Dev users as well.

For Debug builds, it even switches over to a local `file://` path to
the schema in the source directory!

Closes #6601
  • Loading branch information
DHowett authored Aug 22, 2023
1 parent 21c2dee commit 333fcd8
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,15 @@ void CascadiaSettings::WriteSettingsToDisk()
}
}

#ifndef NDEBUG
static [[maybe_unused]] std::string _getDevPathToSchema()
{
std::filesystem::path filePath{ __FILE__ };
auto schemaPath = filePath.parent_path().parent_path().parent_path().parent_path() / "doc" / "cascadia" / "profiles.schema.json";
return "file:///" + schemaPath.generic_string();
}
#endif

// Method Description:
// - Create a new serialized JsonObject from an instance of this class
// Arguments:
Expand All @@ -1238,7 +1247,17 @@ Json::Value CascadiaSettings::ToJson() const
// top-level json object
auto json{ _globals->ToJson() };
json["$help"] = "https://aka.ms/terminal-documentation";
json["$schema"] = "https://aka.ms/terminal-profiles-schema";
json["$schema"] =
#if defined(WT_BRANDING_RELEASE)
"https://aka.ms/terminal-profiles-schema"
#elif defined(WT_BRANDING_PREVIEW)
"https://aka.ms/terminal-profiles-schema-preview"
#elif !defined(NDEBUG) // DEBUG mode
_getDevPathToSchema() // magic schema path that refers to the local source directory
#else // All other brandings
"https://raw.githubusercontent.com/microsoft/terminal/main/doc/cascadia/profiles.schema.json"
#endif
;

// "profiles" will always be serialized as an object
Json::Value profiles{ Json::ValueType::objectValue };
Expand Down

0 comments on commit 333fcd8

Please sign in to comment.