Skip to content

Commit

Permalink
Merge branch 'main' into dev/lelian/notifyicon/yougetoneyougetone
Browse files Browse the repository at this point in the history
  • Loading branch information
leonMSFT committed Jun 16, 2021
2 parents be222d2 + 1ae6e3b commit 6e65805
Show file tree
Hide file tree
Showing 38 changed files with 687 additions and 203 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,7 @@ REGSTR
reingest
Relayout
RELBINPATH
remoting
Remoting
renamer
renderengine
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/CascadiaPackage/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<com:Extension Category="windows.comInterface">
<com:ComInterface>
<com:ProxyStub Id="DEC4804D-56D1-4F73-9FBE-6828E7C85C56" DisplayName="OpenConsoleHandoffProxy" Path="OpenConsoleProxy.dll"/>
<com:Interface Id="2B607BC1-43EB-40C3-95AE-2856ADDB7F23" ProxyStubClsid="DEC4804D-56D1-4F73-9FBE-6828E7C85C56"/>
<com:Interface Id="E686C757-9A35-4A1C-B3CE-0BCC8B5C69F4" ProxyStubClsid="DEC4804D-56D1-4F73-9FBE-6828E7C85C56"/>
<com:Interface Id="59D55CCE-FC8A-48B4-ACE8-0A9286C6557F" ProxyStubClsid="DEC4804D-56D1-4F73-9FBE-6828E7C85C56"/>
</com:ComInterface>
</com:Extension>
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/CascadiaPackage/Package-Pre.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<com:Extension Category="windows.comInterface">
<com:ComInterface>
<com:ProxyStub Id="1833E661-CC81-4DD0-87C6-C2F74BD39EFA" DisplayName="OpenConsoleHandoffProxy" Path="OpenConsoleProxy.dll"/>
<com:Interface Id="2B607BC1-43EB-40C3-95AE-2856ADDB7F23" ProxyStubClsid="1833E661-CC81-4DD0-87C6-C2F74BD39EFA"/>
<com:Interface Id="E686C757-9A35-4A1C-B3CE-0BCC8B5C69F4" ProxyStubClsid="1833E661-CC81-4DD0-87C6-C2F74BD39EFA"/>
<com:Interface Id="59D55CCE-FC8A-48B4-ACE8-0A9286C6557F" ProxyStubClsid="1833E661-CC81-4DD0-87C6-C2F74BD39EFA"/>
</com:ComInterface>
</com:Extension>
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/CascadiaPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<com:Extension Category="windows.comInterface">
<com:ComInterface>
<com:ProxyStub Id="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F" DisplayName="OpenConsoleHandoffProxy" Path="OpenConsoleProxy.dll"/>
<com:Interface Id="2B607BC1-43EB-40C3-95AE-2856ADDB7F23" ProxyStubClsid="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F"/>
<com:Interface Id="E686C757-9A35-4A1C-B3CE-0BCC8B5C69F4" ProxyStubClsid="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F"/>
<com:Interface Id="59D55CCE-FC8A-48B4-ACE8-0A9286C6557F" ProxyStubClsid="3171DE52-6EFA-4AEF-8A9F-D02BD67E7A4F"/>
</com:ComInterface>
</com:Extension> -->
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/ShellExtension/OpenTerminalHere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ try
std::filesystem::path modulePath{ wil::GetModuleFileNameW<std::wstring>(wil::GetModuleInstanceHandle()) };
modulePath.replace_filename(WindowsTerminalExe);
// WindowsTerminal.exe,-101 will be the first icon group in WT
// We're using WindowsTerminal here explicitly, and not wt (from _getExePath), because
// We're using WindowsTerminal here explicitly, and not wt (from GetWtExePath), because
// WindowsTerminal is the only one built with the right icons.
const auto resource{ modulePath.wstring() + L",-101" };
return SHStrDupW(resource.c_str(), ppszIcon);
Expand Down
13 changes: 11 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>

#include <LibraryResources.h>
#include <WtExeUtils.h>

using namespace winrt::Windows::ApplicationModel;
using namespace winrt::Windows::ApplicationModel::DataTransfer;
Expand Down Expand Up @@ -913,18 +914,26 @@ namespace winrt::TerminalApp::implementation
}
}

void AppLogic::_ApplyLanguageSettingChange()
void AppLogic::_ApplyLanguageSettingChange() noexcept
try
{
if (!IsPackaged())
{
return;
}

using ApplicationLanguages = winrt::Windows::Globalization::ApplicationLanguages;

const auto language = _settings.GlobalSettings().Language();
// NOTE: PrimaryLanguageOverride throws if this instance is unpackaged.
const auto primaryLanguageOverride = ApplicationLanguages::PrimaryLanguageOverride();
const auto language = _settings.GlobalSettings().Language();

if (primaryLanguageOverride != language)
{
ApplicationLanguages::PrimaryLanguageOverride(language);
}
}
CATCH_LOG()

void AppLogic::_RefreshThemeRoutine()
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace winrt::TerminalApp::implementation
void _ShowLoadWarningsDialog();
bool _IsKeyboardServiceEnabled();

void _ApplyLanguageSettingChange();
void _ApplyLanguageSettingChange() noexcept;
void _RefreshThemeRoutine();
fire_and_forget _ApplyStartupTaskStateChange();

Expand Down
66 changes: 4 additions & 62 deletions src/cascadia/TerminalApp/Jumplist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <ShObjIdl.h>
#include <Propkey.h>

#include <WtExeUtils.h>

using namespace winrt::Microsoft::Terminal::Settings::Model;

// This property key isn't already defined in propkey.h, but is used by UWP Jumplist to determine the icon of the jumplist item.
Expand Down Expand Up @@ -52,66 +54,6 @@ static std::wstring _normalizeIconPath(std::wstring_view path)
return std::wstring{ fullPath };
}

// Function Description:
// - Helper function for getting the path to the appropriate executable to use
// for this instance of the jumplist. For the dev build, it should be `wtd.exe`,
// but if we're preview or release, we want to make sure to get the correct
// `wt.exe` that corresponds to _us_.
// - If we're unpackaged, this needs to get us `WindowsTerminal.exe`, because
// the `wt*exe` alias won't have been installed for this install.
// Arguments:
// - <none>
// Return Value:
// - the full path to the exe, one of `wt.exe`, `wtd.exe`, or `WindowsTerminal.exe`.
static std::wstring_view _getExePath()
{
static constexpr std::wstring_view WtExe{ L"wt.exe" };
static constexpr std::wstring_view WindowsTerminalExe{ L"WindowsTerminal.exe" };
static constexpr std::wstring_view WtdExe{ L"wtd.exe" };

static constexpr std::wstring_view LocalAppDataAppsPath{ L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\" };

// use C++11 magic statics to make sure we only do this once.
static const std::wstring exePath = []() -> std::wstring {
// First, check a packaged location for the exe. If we've got a package
// family name, that means we're one of the packaged Dev build, packaged
// Release build, or packaged Preview build.
//
// If we're the preview or release build, there's no way of knowing if the
// `wt.exe` on the %PATH% is us or not. Fortunately, _our_ execution alias
// is located in "%LOCALAPPDATA%\Microsoft\WindowsApps\<our package family
// name>", _always_, so we can use that to look up the exe easier.
try
{
const auto package{ winrt::Windows::ApplicationModel::Package::Current() };
const auto id{ package.Id() };
const std::wstring pfn{ id.FamilyName() };
const auto isDevPackage{ pfn.rfind(L"WindowsTerminalDev") == 0 };
if (!pfn.empty())
{
const std::filesystem::path windowsAppsPath{ wil::ExpandEnvironmentStringsW<std::wstring>(LocalAppDataAppsPath.data()) };
const std::filesystem::path wtPath{ windowsAppsPath / pfn / (isDevPackage ? WtdExe : WtExe) };
return wtPath;
}
}
CATCH_LOG();

// If we're here, then we couldn't resolve our exe from the package. This
// means we're running unpackaged. We should just use the
// WindowsTerminal.exe that's sitting in the directory next to us.
try
{
std::filesystem::path module{ wil::GetModuleFileNameW<std::wstring>(nullptr) };
module.replace_filename(WindowsTerminalExe);
return module;
}
CATCH_LOG();

return std::wstring{ WtExe };
}();
return exePath;
}

// Method Description:
// - Updates the items of the Jumplist based on the given settings.
// Arguments:
Expand Down Expand Up @@ -187,7 +129,7 @@ winrt::fire_and_forget Jumplist::UpdateJumplist(const CascadiaSettings& settings
// - Creates a ShellLink object. Each item in a jumplist is a ShellLink, which is sort of
// like a shortcut. It requires the path to the application (wt.exe), the arguments to pass,
// and the path to the icon for the jumplist item. The path to the application isn't passed
// into this function, as we'll determine it with _getExePath
// into this function, as we'll determine it with GetWtExePath
// Arguments:
// - name: The name of the item displayed in the jumplist.
// - path: The path to the icon for the jumplist item.
Expand All @@ -204,7 +146,7 @@ winrt::fire_and_forget Jumplist::UpdateJumplist(const CascadiaSettings& settings
{
auto sh = winrt::create_instance<IShellLinkW>(CLSID_ShellLink, CLSCTX_ALL);

const auto module{ _getExePath() };
const auto module{ GetWtExePath() };
RETURN_IF_FAILED(sh->SetPath(module.data()));
RETURN_IF_FAILED(sh->SetArguments(args.data()));

Expand Down
48 changes: 38 additions & 10 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "GlobalAppearancePageNavigationState.g.cpp"

#include <LibraryResources.h>
#include <WtExeUtils.h>

using namespace winrt;
using namespace winrt::Windows::UI::Xaml;
Expand Down Expand Up @@ -47,6 +48,16 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return language.NativeName();
}

// Returns whether the language selector is available/shown.
//
// winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride()
// doesn't work for unpackaged applications. The corresponding code in TerminalApp is disabled.
// It would be confusing for our users if we presented a dysfunctional language selector.
bool GlobalAppearance::LanguageSelectorAvailable()
{
return IsPackaged();
}

// Returns the list of languages the user may override the application language with.
// The returned list are BCP 47 language tags like {"und", "en-US", "de-DE", "es-ES", ...}.
// "und" is short for "undefined" and is synonymous for "Use system language" in this code.
Expand All @@ -57,6 +68,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return _languageList;
}

if (!LanguageSelectorAvailable())
{
_languageList = {};
return _languageList;
}

// In order to return the language list this code does the following:
// [1] Get all possible languages we want to allow the user to choose.
// We have to acquire languages from multiple sources, creating duplicates. See below at [1].
Expand Down Expand Up @@ -144,30 +161,41 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

winrt::Windows::Foundation::IInspectable GlobalAppearance::CurrentLanguage()
{
if (_currentLanguage.empty())
if (_currentLanguage)
{
_currentLanguage = winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride();
if (_currentLanguage.empty())
{
_currentLanguage = systemLanguageTag;
}
return _currentLanguage;
}

if (!LanguageSelectorAvailable())
{
_currentLanguage = {};
return _currentLanguage;
}

// NOTE: PrimaryLanguageOverride throws if this instance is unpackaged.
auto currentLanguage = winrt::Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride();
if (currentLanguage.empty())
{
currentLanguage = systemLanguageTag;
}

return winrt::box_value(_currentLanguage);
_currentLanguage = winrt::box_value(currentLanguage);
return _currentLanguage;
}

void GlobalAppearance::CurrentLanguage(const winrt::Windows::Foundation::IInspectable& tag)
{
_currentLanguage = winrt::unbox_value<winrt::hstring>(tag);
_currentLanguage = tag;

const auto currentLanguage = winrt::unbox_value<winrt::hstring>(_currentLanguage);
const auto globals = _State.Globals();
if (_currentLanguage == systemLanguageTag)
if (currentLanguage == systemLanguageTag)
{
globals.ClearLanguage();
}
else
{
globals.Language(_currentLanguage);
globals.Language(currentLanguage);
}
}
}
7 changes: 3 additions & 4 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// "Deutsch (Deutschland)". This works independently of the user's locale.
static winrt::hstring LanguageDisplayConverter(const winrt::hstring& tag);

bool LanguageSelectorAvailable();
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> LanguageList();
winrt::Windows::Foundation::IInspectable CurrentLanguage();
void CurrentLanguage(const winrt::Windows::Foundation::IInspectable& tag);

private:
std::vector<winrt::hstring> _GetSupportedLanguageTags();

winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> _languageList{ nullptr };
winrt::hstring _currentLanguage;
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring> _languageList;
winrt::Windows::Foundation::IInspectable _currentLanguage;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.idl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Terminal.Settings.Editor
GlobalAppearancePageNavigationState State { get; };

static String LanguageDisplayConverter(String tag);
Boolean LanguageSelectorAvailable { get; };
Windows.Foundation.Collections.IObservableVector<String> LanguageList { get; };
IInspectable CurrentLanguage;

Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<StackPanel Style="{StaticResource SettingsStackStyle}">
<!-- Language -->
<local:SettingContainer x:Uid="Globals_Language"
Margin="0">
Margin="0"
Visibility="{x:Bind LanguageSelectorAvailable}">
<ComboBox ItemsSource="{x:Bind LanguageList}"
SelectedItem="{x:Bind CurrentLanguage, Mode=TwoWay}">
<ComboBox.ItemTemplate>
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#undef GetCurrentTime
#endif

#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Globalization.h>
Expand Down
15 changes: 4 additions & 11 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
// Licensed under the MIT license.

#include "pch.h"
#include <argb.h>
#include <conattrs.hpp>
#include <io.h>
#include <fcntl.h>
#include "CascadiaSettings.h"
#include "../../types/inc/utils.hpp"
#include "../../inc/DefaultSettings.h"
#include "Utils.h"
#include "LibraryResources.h"
#include "CascadiaSettings.g.cpp"

#include <LibraryResources.h>

#include "AzureCloudShellGenerator.h"
#include "PowershellCoreProfileGenerator.h"
#include "WslDistroGenerator.h"
#include "AzureCloudShellGenerator.h"

#include "CascadiaSettings.g.cpp"

using namespace ::Microsoft::Terminal::Settings::Model;
using namespace winrt::Microsoft::Terminal;
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalSettingsModel/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
std::unordered_set<std::string> _AccumulateJsonFilesInDirectory(const std::wstring_view directory);
void _ParseAndLayerFragmentFiles(const std::unordered_set<std::string> files, const winrt::hstring source);

static bool _IsPackaged();
static void _WriteSettings(std::string_view content, const hstring filepath);
static std::optional<std::string> _ReadUserSettings();
static std::optional<std::string> _ReadFile(HANDLE hFile);
Expand Down
Loading

1 comment on commit 6e65805

@github-actions

This comment was marked as resolved.

Please sign in to comment.