From e358b967461f9ae20a3eef6e1487d91ed50f7205 Mon Sep 17 00:00:00 2001 From: Leon Liang <57155886+leonMSFT@users.noreply.github.com> Date: Tue, 28 Apr 2020 13:22:44 -0700 Subject: [PATCH] Add a Third-Party notices link to the about dialog (#5508) ## Summary of the Pull Request This PR will add a link to the version of `NOTICE.md` in GitHub at the commit that the build was on. It uses the same approach for generating our settings files, where we'll create a header file with the commit hash assigned to a `wstring_view` during build time. ## PR Checklist * [x] Closes #5139 * [x] CLA signed. * [x] Tests added/passed ## Validation Steps Performed The link is there and goes to the expected `NOTICE.md`. --- .../Resources/en-US/Resources.resw | 4 ++++ src/cascadia/TerminalApp/TerminalPage.cpp | 8 +++++++ src/cascadia/TerminalApp/TerminalPage.h | 2 ++ src/cascadia/TerminalApp/TerminalPage.idl | 2 ++ src/cascadia/TerminalApp/TerminalPage.xaml | 3 +++ .../TerminalApp/lib/TerminalAppLib.vcxproj | 4 ++++ tools/GenerateCommitHashHeader.ps1 | 21 +++++++++++++++++++ 7 files changed, 44 insertions(+) create mode 100644 tools/GenerateCommitHashHeader.ps1 diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index c8fa25218..e9732e9ce 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -273,6 +273,10 @@ Privacy Policy A hyperlink name for the Terminal's privacy policy + + Third-Party Notices + A hyperlink name for the Terminal's third-party notices + Windows Terminal (Unpackaged) This display name is used when the application's name cannot be determined diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 96a823e7d..d7a15836f 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -18,6 +18,8 @@ #include "TabRowControl.h" #include "DebugTapConnection.h" +#include "CurrentCommitHash.h" // For the about dialog's ThirdPartyNotices link + using namespace winrt; using namespace winrt::Windows::Foundation::Collections; using namespace winrt::Windows::UI::Xaml; @@ -254,6 +256,12 @@ namespace winrt::TerminalApp::implementation return RS_(L"ApplicationVersionUnknown"); } + winrt::hstring TerminalPage::ThirdPartyNoticesLink() + { + winrt::hstring link{ fmt::format(L"https://github.com/microsoft/terminal/blob/{}/NOTICE.md", CurrentCommitHash) }; + return link; + } + // Method Description: // - Displays a dialog for warnings found while closing the terminal app using // key binding with multiple tabs opened. Display messages to warn user diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index a7d37c138..ff561f164 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -45,6 +45,8 @@ namespace winrt::TerminalApp::implementation winrt::hstring ApplicationDisplayName(); winrt::hstring ApplicationVersion(); + winrt::hstring ThirdPartyNoticesLink(); + void CloseWindow(); int32_t SetStartupCommandline(winrt::array_view args); diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl index dc4b7820d..ec7e261ba 100644 --- a/src/cascadia/TerminalApp/TerminalPage.idl +++ b/src/cascadia/TerminalApp/TerminalPage.idl @@ -17,6 +17,8 @@ namespace TerminalApp String ApplicationDisplayName { get; }; String ApplicationVersion { get; }; + String ThirdPartyNoticesLink { get; }; + event Windows.Foundation.TypedEventHandler TitleChanged; event Windows.Foundation.TypedEventHandler LastTabClosed; event Windows.Foundation.TypedEventHandler SetTitleBarContent; diff --git a/src/cascadia/TerminalApp/TerminalPage.xaml b/src/cascadia/TerminalApp/TerminalPage.xaml index 97f966c12..d71d4b47c 100644 --- a/src/cascadia/TerminalApp/TerminalPage.xaml +++ b/src/cascadia/TerminalApp/TerminalPage.xaml @@ -43,6 +43,9 @@ the MIT License. See LICENSE in the project root for license information. --> + diff --git a/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj index a552e6cec..056786e14 100644 --- a/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/lib/TerminalAppLib.vcxproj @@ -330,4 +330,8 @@ + + + + diff --git a/tools/GenerateCommitHashHeader.ps1 b/tools/GenerateCommitHashHeader.ps1 new file mode 100644 index 000000000..4606017ce --- /dev/null +++ b/tools/GenerateCommitHashHeader.ps1 @@ -0,0 +1,21 @@ +# This script gets the current git commit hash and places it in a header file stamped to a wstring_view +# If we're unable to retrieve the hash, we'll return the hard coded string "master" instead. + +$filePath = "Generated Files\CurrentCommitHash.h" + +Write-Output "constexpr std::wstring_view CurrentCommitHash{ L`"" | Out-File -FilePath $filePath -Encoding ASCII -NoNewline + +# Let's see if we're on a build agent that can give us the commit hash through this predefined variable. +$hash = $env:Build_SourceVersion +if (-not $hash) +{ + # Otherwise attempt to invoke git to get the commit. + $hash = git rev-parse HEAD + if ($LASTEXITCODE -or -not $hash) + { + $hash = "master" + } +} + +$hash | Out-File -FilePath $filePath -Encoding ASCII -Append -NoNewline +Write-Output "`" };" | Out-File -FilePath $filePath -Encoding ASCII -Append -NoNewline