Skip to content

Commit 4846d33

Browse files
PankajBhojwanimcpiroman
authored andcommitted
The Azure cloud shell connector (microsoft#1808)
* We can now connect to the Azure cloud shell microsoft#1235
1 parent 67f80c9 commit 4846d33

24 files changed

+1189
-32
lines changed

src/cascadia/CascadiaPackage/CascadiaPackage.wapproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\..\..\common.openconsole.props" Condition="'$(OpenConsoleDir)'==''" />
44
<Import Project="$(OpenConsoleDir)src\wap-common.build.pre.props" />
@@ -257,6 +257,8 @@
257257
<Content Include="ProfileIcons\{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.scale-200.png" />
258258
<Content Include="ProfileIcons\{9acb9455-ca41-5af7-950f-6bca1bc9722f}.scale-100.png" />
259259
<Content Include="ProfileIcons\{9acb9455-ca41-5af7-950f-6bca1bc9722f}.scale-200.png" />
260+
<Content Include="ProfileIcons\{b453ae62-4e3d-5e58-b989-0a998ec441b8}.scale-100.png" />
261+
<Content Include="ProfileIcons\{b453ae62-4e3d-5e58-b989-0a998ec441b8}.scale-200.png" />
260262
<PRIResource Include="Resources\en-US\Resources.resw" />
261263
</ItemGroup>
262264
<Import Project="$(OpenConsoleDir)src\wap-common.build.post.props" />
@@ -277,7 +279,8 @@
277279
<!-- Override the filename for OpenConsole.exe (only) -->
278280
<TargetPath Condition="'%(Filename)' == 'OpenConsole' and '%(Extension)' == '.exe'">conhost.exe</TargetPath>
279281
<!-- Blank the SourceProject here to vend all files into the root of the package. -->
280-
<SourceProject></SourceProject>
282+
<SourceProject>
283+
</SourceProject>
281284
</_FilteredNonWapProjProjectOutput>
282285
</ItemGroup>
283286
</Target>
@@ -302,4 +305,4 @@
302305
</ItemGroup>
303306
</Target>
304307

305-
</Project>
308+
</Project>
314 Bytes
Loading
573 Bytes
Loading

src/cascadia/TerminalApp/App.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,8 @@ namespace winrt::TerminalApp::implementation
916916
{
917917
// Initialize the new tab
918918

919-
// Create a Conhost connection based on the values in our settings object.
920-
auto connection = TerminalConnection::ConhostConnection(settings.Commandline(),
921-
settings.StartingDirectory(),
922-
30,
923-
80,
924-
winrt::guid());
919+
// Create a connection based on the values in our settings object.
920+
const auto connection = _CreateConnectionFromSettings(profileGuid, settings);
925921

926922
TermControl term{ settings, connection };
927923

@@ -1333,12 +1329,7 @@ namespace winrt::TerminalApp::implementation
13331329
_settings->GlobalSettings().GetDefaultProfile();
13341330
const auto controlSettings = _settings->MakeSettings(realGuid);
13351331

1336-
// Create a Conhost connection based on the values in our settings object.
1337-
auto controlConnection = TerminalConnection::ConhostConnection(controlSettings.Commandline(),
1338-
controlSettings.StartingDirectory(),
1339-
30,
1340-
80,
1341-
winrt::guid());
1332+
const auto controlConnection = _CreateConnectionFromSettings(realGuid, controlSettings);
13421333

13431334
TermControl newControl{ controlSettings, controlConnection };
13441335

@@ -1467,6 +1458,32 @@ namespace winrt::TerminalApp::implementation
14671458
}
14681459
}
14691460

1461+
// Method Description:
1462+
// - Creates a new connection based on the profile settings
1463+
// Arguments:
1464+
// - the profile GUID we want the settings from
1465+
// - the terminal settings
1466+
// Return value:
1467+
// - the desired connection
1468+
TerminalConnection::ITerminalConnection App::_CreateConnectionFromSettings(GUID profileGuid, winrt::Microsoft::Terminal::Settings::TerminalSettings settings)
1469+
{
1470+
const auto* const profile = _settings->FindProfile(profileGuid);
1471+
TerminalConnection::ITerminalConnection connection{ nullptr };
1472+
// The Azure connection has a boost dependency, and boost does not support ARM64
1473+
// so we make sure that we do not try to compile the Azure connection code if we are in ARM64 (we would get build errors otherwise)
1474+
#ifndef _M_ARM64
1475+
if (profile->HasConnectionType() && profile->GetConnectionType() == AzureConnectionType)
1476+
{
1477+
connection = TerminalConnection::AzureConnection(settings.InitialRows(), settings.InitialCols());
1478+
}
1479+
else
1480+
#endif
1481+
{
1482+
connection = TerminalConnection::ConhostConnection(settings.Commandline(), settings.StartingDirectory(), settings.InitialRows(), settings.InitialCols(), winrt::guid());
1483+
}
1484+
return connection;
1485+
}
1486+
14701487
// -------------------------------- WinRT Events ---------------------------------
14711488
// Winrt events need a method for adding a callback to the event and removing the callback.
14721489
// These macros will define them both for you.

src/cascadia/TerminalApp/App.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ namespace winrt::TerminalApp::implementation
101101
void _RegisterTerminalEvents(Microsoft::Terminal::TerminalControl::TermControl term, std::shared_ptr<Tab> hostingTab);
102102

103103
void _CreateNewTabFromSettings(GUID profileGuid, winrt::Microsoft::Terminal::Settings::TerminalSettings settings);
104+
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(GUID profileGuid, winrt::Microsoft::Terminal::Settings::TerminalSettings settings);
104105

105106
void _OpenNewTab(std::optional<int> profileIndex);
106107
void _DuplicateTabViewItem();

src/cascadia/TerminalApp/CascadiaSettings.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ void CascadiaSettings::_CreateDefaultProfiles()
239239
powershellProfile.SetDefaultBackground(POWERSHELL_BLUE);
240240
powershellProfile.SetUseAcrylic(false);
241241

242+
// The Azure connection has a boost dependency, and boost does not support ARM64
243+
// so we don't create a default profile for the Azure cloud shell if we're in ARM64
244+
#ifndef _M_ARM64
245+
auto azureCloudShellProfile{ _CreateDefaultProfile(L"Azure Cloud Shell") };
246+
azureCloudShellProfile.SetCommandline(L"Azure");
247+
azureCloudShellProfile.SetStartingDirectory(DEFAULT_STARTING_DIRECTORY);
248+
azureCloudShellProfile.SetColorScheme({ L"Solarized Dark" });
249+
azureCloudShellProfile.SetAcrylicOpacity(0.85);
250+
azureCloudShellProfile.SetUseAcrylic(true);
251+
azureCloudShellProfile.SetCloseOnExit(false);
252+
azureCloudShellProfile.SetConnectionType(AzureConnectionType);
253+
#endif
254+
242255
// If the user has installed PowerShell Core, we add PowerShell Core as a default.
243256
// PowerShell Core default folder is "%PROGRAMFILES%\PowerShell\[Version]\".
244257
std::filesystem::path psCoreCmdline{};
@@ -261,6 +274,9 @@ void CascadiaSettings::_CreateDefaultProfiles()
261274

262275
_profiles.emplace_back(powershellProfile);
263276
_profiles.emplace_back(cmdProfile);
277+
#ifndef _M_ARM64
278+
_profiles.emplace_back(azureCloudShellProfile);
279+
#endif
264280
try
265281
{
266282
_AppendWslProfiles(_profiles);

src/cascadia/TerminalApp/CascadiaSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Author(s):
2020
#include "GlobalAppSettings.h"
2121
#include "Profile.h"
2222

23+
static constexpr GUID AzureConnectionType = { 0xd9fcfdfa, 0xa479, 0x412c, { 0x83, 0xb7, 0xc5, 0x64, 0xe, 0x61, 0xcd, 0x62 } };
24+
2325
namespace TerminalApp
2426
{
2527
class CascadiaSettings;

src/cascadia/TerminalApp/Profile.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static constexpr std::string_view CursorColorKey{ "cursorColor" };
2626
static constexpr std::string_view CursorShapeKey{ "cursorShape" };
2727
static constexpr std::string_view CursorHeightKey{ "cursorHeight" };
2828

29+
static constexpr std::string_view ConnectionTypeKey{ "connectionType" };
2930
static constexpr std::string_view CommandlineKey{ "commandline" };
3031
static constexpr std::string_view FontFaceKey{ "fontFace" };
3132
static constexpr std::string_view FontSizeKey{ "fontSize" };
@@ -89,6 +90,7 @@ Profile::Profile(const winrt::guid& guid) :
8990
_cursorShape{ CursorStyle::Bar },
9091
_cursorHeight{ DEFAULT_CURSOR_HEIGHT },
9192

93+
_connectionType{},
9294
_commandline{ L"cmd.exe" },
9395
_startingDirectory{},
9496
_fontFace{ DEFAULT_FONT_FACE },
@@ -280,6 +282,10 @@ Json::Value Profile::ToJson() const
280282
root[JsonKey(CloseOnExitKey)] = _closeOnExit;
281283
root[JsonKey(PaddingKey)] = winrt::to_string(_padding);
282284

285+
if (_connectionType)
286+
{
287+
root[JsonKey(ConnectionTypeKey)] = winrt::to_string(Utils::GuidToString(_connectionType.value()));
288+
}
283289
if (_scrollbarState)
284290
{
285291
const auto scrollbarState = winrt::to_string(_scrollbarState.value());
@@ -406,6 +412,10 @@ Profile Profile::FromJson(const Json::Value& json)
406412
}
407413

408414
// Control Settings
415+
if (auto connectionType{ json[JsonKey(ConnectionTypeKey)] })
416+
{
417+
result._connectionType = Utils::GuidFromString(GetWstringFromJson(connectionType));
418+
}
409419
if (auto commandline{ json[JsonKey(CommandlineKey)] })
410420
{
411421
result._commandline = GetWstringFromJson(commandline);
@@ -511,6 +521,16 @@ void Profile::SetDefaultBackground(COLORREF defaultBackground) noexcept
511521
_defaultBackground = defaultBackground;
512522
}
513523

524+
void Profile::SetCloseOnExit(bool defaultClose) noexcept
525+
{
526+
_closeOnExit = defaultClose;
527+
}
528+
529+
void Profile::SetConnectionType(GUID connectionType) noexcept
530+
{
531+
_connectionType = connectionType;
532+
}
533+
514534
bool Profile::HasIcon() const noexcept
515535
{
516536
return _icon.has_value() && !_icon.value().empty();
@@ -576,6 +596,18 @@ std::wstring_view Profile::GetTabTitle() const noexcept
576596
std::wstring_view{ L"", 0 };
577597
}
578598

599+
bool Profile::HasConnectionType() const noexcept
600+
{
601+
return _connectionType.has_value();
602+
}
603+
604+
GUID Profile::GetConnectionType() const noexcept
605+
{
606+
return HasConnectionType() ?
607+
_connectionType.value() :
608+
_GUID{};
609+
}
610+
579611
bool Profile::GetCloseOnExit() const noexcept
580612
{
581613
return _closeOnExit;

src/cascadia/TerminalApp/Profile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class TerminalApp::Profile final
3838
std::wstring_view GetName() const noexcept;
3939
bool HasTabTitle() const noexcept;
4040
std::wstring_view GetTabTitle() const noexcept;
41+
bool HasConnectionType() const noexcept;
42+
GUID GetConnectionType() const noexcept;
4143

4244
void SetFontFace(std::wstring fontFace) noexcept;
4345
void SetColorScheme(std::optional<std::wstring> schemeName) noexcept;
@@ -49,6 +51,8 @@ class TerminalApp::Profile final
4951
void SetUseAcrylic(bool useAcrylic) noexcept;
5052
void SetDefaultForeground(COLORREF defaultForeground) noexcept;
5153
void SetDefaultBackground(COLORREF defaultBackground) noexcept;
54+
void SetCloseOnExit(bool defaultClose) noexcept;
55+
void SetConnectionType(GUID connectionType) noexcept;
5256

5357
bool HasIcon() const noexcept;
5458
std::wstring_view GetIconPath() const noexcept;
@@ -69,6 +73,7 @@ class TerminalApp::Profile final
6973

7074
GUID _guid;
7175
std::wstring _name;
76+
std::optional<GUID> _connectionType;
7277

7378
// If this is set, then our colors should come from the associated color scheme
7479
std::optional<std::wstring> _schemeName;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#pragma once
5+
6+
#include <cpprest/details/web_utilities.h>
7+
8+
const utility::string_t AzureClientID = U("0");

0 commit comments

Comments
 (0)