Skip to content

Commit

Permalink
Clean this up, it's better-ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Apr 6, 2020
1 parent 65cd6c3 commit 76d0255
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 33 deletions.
27 changes: 25 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ catch (...)

namespace winrt::TerminalApp::implementation
{
// Function Description:
// - Get the AppLogic for the current active Xaml application, or null if there isn't one.
// Return value:
// - A pointer (bare) to the applogic, or nullptr. The app logic outlives all other objects,
// unless the application is in a terrible way, so this is "safe."
AppLogic* AppLogic::Current() noexcept
try
{
if (auto currentXamlApp{ winrt::Windows::UI::Xaml::Application::Current().try_as<winrt::TerminalApp::App>() })
{
if (auto appLogicPointer{ winrt::get_self<AppLogic>(currentXamlApp.Logic()) })
{
return appLogicPointer;
}
}
return nullptr;
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
return nullptr;
}

AppLogic::AppLogic() :
_dialogLock{},
_loadedInitialSettings{ false },
Expand Down Expand Up @@ -871,7 +894,7 @@ namespace winrt::TerminalApp::implementation
}
CATCH_LOG();

return RS_(L"AboutDialog_DisplayNameUnpackaged");
return RS_(L"ApplicationDisplayNameUnpackaged");
}

winrt::hstring AppLogic::ApplicationVersion() const
Expand All @@ -885,7 +908,7 @@ namespace winrt::TerminalApp::implementation
}
CATCH_LOG();

return RS_(L"AboutDialog_VersionUnknown");
return RS_(L"ApplicationVersionUnknown");
}

// -------------------------------- WinRT Events ---------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace winrt::TerminalApp::implementation
struct AppLogic : AppLogicT<AppLogic>
{
public:
static AppLogic* Current() noexcept;

AppLogic();
~AppLogic() = default;

Expand Down
36 changes: 16 additions & 20 deletions src/cascadia/TerminalApp/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,14 @@ static constexpr std::wstring_view DEFAULT_LINUX_ICON_GUID{ L"{9acb9455-ca41-5af
// make sure this matches defaults.json.
static constexpr std::wstring_view DEFAULT_WINDOWS_POWERSHELL_GUID{ L"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}" };

// Method Description:
// - Returns the active application logic singleton
// Throws:
// - HR E_INVALIDARG if the app isn't up and running.
static auto GetAppLogic()
{
auto currentXamlApp{ winrt::Windows::UI::Xaml::Application::Current().as<winrt::TerminalApp::App>() };
THROW_HR_IF_NULL(E_INVALIDARG, currentXamlApp);

auto appLogicPointer = winrt::get_self<winrt::TerminalApp::implementation::AppLogic>(currentXamlApp.Logic());
THROW_HR_IF_NULL(E_INVALIDARG, appLogicPointer);

winrt::com_ptr<winrt::TerminalApp::implementation::AppLogic> appLogic;
appLogic.copy_from(appLogicPointer);
return appLogic;
}

// Method Description:
// - Returns the settings currently in use by the entire Terminal application.
// Throws:
// - HR E_INVALIDARG if the app isn't up and running.
const CascadiaSettings& CascadiaSettings::GetCurrentAppSettings()
{
auto appLogic{ GetAppLogic() };
auto appLogic{ ::winrt::TerminalApp::implementation::AppLogic::Current() };
THROW_HR_IF_NULL(E_INVALIDARG, appLogic);
return *(appLogic->GetSettings());
}

Expand Down Expand Up @@ -689,6 +673,14 @@ void CascadiaSettings::_ValidateKeybindings()
}
}

// Method Description
// - Replaces known tokens DEFAULT_PROFILE, PRODUCT and VERSION in the settings template
// with their expected values. DEFAULT_PROFILE is updated to match PowerShell Core's GUID
// if such a profile is detected. If it isn't, it'll be set to Windows PowerShell's GUID.
// Arguments:
// - settingsTemplate: a settings template
// Return value:
// - The new settings string.
std::string CascadiaSettings::_ApplyFirstRunChangesToSettingsTemplate(std::string_view settingsTemplate) const
{
std::string finalSettings{ settingsTemplate };
Expand All @@ -707,7 +699,11 @@ std::string CascadiaSettings::_ApplyFirstRunChangesToSettingsTemplate(std::strin
}

replace(finalSettings, "%DEFAULT_PROFILE%", til::u16u8(defaultProfileGuid));
replace(finalSettings, "%VERSION%", til::u16u8(GetAppLogic()->ApplicationVersion()));
replace(finalSettings, "%PRODUCT%", til::u16u8(GetAppLogic()->ApplicationDisplayName()));
if (const auto appLogic{ winrt::TerminalApp::implementation::AppLogic::Current() })
{
replace(finalSettings, "%VERSION%", til::u16u8(appLogic->ApplicationVersion()));
replace(finalSettings, "%PRODUCT%", til::u16u8(appLogic->ApplicationDisplayName()));
}

return finalSettings;
}
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ Temporarily using the Windows Terminal default settings.
<value>Privacy Policy</value>
<comment>A hyperlink name for the Terminal's privacy policy</comment>
</data>
<data name="AboutDialog_DisplayNameUnpackaged" xml:space="preserve">
<data name="ApplicationDisplayNameUnpackaged" xml:space="preserve">
<value>Windows Terminal (Unpackaged)</value>
<comment>This display name is used when the application's name cannot be determined</comment>
</data>
<data name="AboutDialog_VersionUnknown" xml:space="preserve">
<data name="ApplicationVersionUnknown" xml:space="preserve">
<value>Unknown</value>
<comment>This is displayed when the version of the application cannot be determined</comment>
</data>
Expand All @@ -283,4 +283,4 @@ Temporarily using the Windows Terminal default settings.
<data name="CloseAllDialog.Title" xml:space="preserve">
<value>Do you want to close all tabs?</value>
</data>
</root>
</root>
15 changes: 7 additions & 8 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "TerminalPage.h"
#include "ActionAndArgs.h"
#include "Utils.h"
#include "AppLogic.h"
#include "../../types/inc/utils.hpp"

#include <LibraryResources.h>
Expand Down Expand Up @@ -234,24 +235,22 @@ namespace winrt::TerminalApp::implementation

winrt::hstring TerminalPage::ApplicationDisplayName()
{
try
if (const auto appLogic{ implementation::AppLogic::Current() })
{
return ::winrt::Windows::UI::Xaml::Application::Current().as<::winrt::TerminalApp::App>().Logic().ApplicationDisplayName();
return appLogic->ApplicationDisplayName();
}
CATCH_LOG();

return RS_(L"AboutDialog_DisplayNameUnpackaged");
return RS_(L"ApplicationDisplayNameUnpackaged");
}

winrt::hstring TerminalPage::ApplicationVersion()
{
try
if (const auto appLogic{ implementation::AppLogic::Current() })
{
return ::winrt::Windows::UI::Xaml::Application::Current().as<::winrt::TerminalApp::App>().Logic().ApplicationVersion();
return appLogic->ApplicationVersion();
}
CATCH_LOG();

return RS_(L"AboutDialog_VersionUnknown");
return RS_(L"ApplicationVersionUnknown");
}

// Method Description:
Expand Down

1 comment on commit 76d0255

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • rfind
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw('"
APPLOGIC
Impl
trackpads
ve
XY
"');
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/alphabet.txt .github/actions/spell-check/whitelist/web.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
applogic
impl
rfind
xy
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/76d02557c8fde9ea6264c978875d36759807a9d9.txt'
✏️ Contributor please read this
  • If the items listed above are names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • If they're APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • If they're just things you're using, please add them to an appropriate file in .github/actions/spell-check/whitelist/.
  • If you need to use a specific token in one place and it shouldn't generally be used, you can
    add an item in an appropriate file in .github/actions/spell-check/patterns/.

See the README.md in each directory for more information.

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

Please sign in to comment.