Skip to content

Commit

Permalink
Only load default terminal choice on OS builds where it should work.
Browse files Browse the repository at this point in the history
  • Loading branch information
miniksa committed Apr 21, 2021
1 parent 0472516 commit 463a853
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ blog
Blt
BLUESCROLL
bmp
BODGY
BOLDFONT
BOOLIFY
bools
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

INITIALIZE_BINDABLE_ENUM_SETTING(LaunchMode, LaunchMode, LaunchMode, L"Globals_LaunchMode", L"Content");
INITIALIZE_BINDABLE_ENUM_SETTING(WindowingBehavior, WindowingMode, WindowingMode, L"Globals_WindowingBehavior", L"Content");

// BODGY
// Xaml code generator for x:Bind to this will fail to find UnloadObject() on Launch class.
// To work around, check it ourselves on construction and FindName to force load.
// It's specified as x:Load=false in the XAML. So it only loads if this passes.
if (CascadiaSettings::IsDefaultTerminalAvailable())
{
FindName(L"DefaultTerminalDropdown");
}
}

void Launch::OnNavigatedTo(const NavigationEventArgs& e)
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Launch.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
</local:SettingContainer>

<!-- Default Terminal -->
<local:SettingContainer x:Uid="Globals_DefaultTerminal">
<local:SettingContainer x:Uid="Globals_DefaultTerminal"
x:Name="DefaultTerminalDropdown"
x:Load="false"
>
<ComboBox x:Name="DefaultTerminal"
ItemsSource="{x:Bind State.Settings.DefaultTerminals, Mode=OneWay}"
SelectedItem="{x:Bind State.Settings.CurrentDefaultTerminal, Mode=TwoWay}"
Expand Down
27 changes: 27 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,33 @@ void CascadiaSettings::RefreshDefaultTerminals()
_currentDefaultTerminal = Model::DefaultTerminal::Current();
}

// Helper to do the version check
static bool _isOnBuildWithDefTerm() noexcept
{
OSVERSIONINFOEXW osver{ 0 };
osver.dwOSVersionInfoSize = sizeof(osver);
osver.dwBuildNumber = 21359;

DWORDLONG dwlConditionMask = 0;
VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);

return VerifyVersionInfoW(&osver, VER_BUILDNUMBER, dwlConditionMask);
}

// Method Description:
// - Determines if we're on an OS platform that supports
// the default terminal handoff functionality.
// Arguments:
// - <none>
// Return Value:
// - True if OS supports default termianl. False otherwise.
bool CascadiaSettings::IsDefaultTerminalAvailable() noexcept
{
// Cached on first use since the OS version shouldn't change while we're running.
static bool isAvailable = _isOnBuildWithDefTerm();
return isAvailable;
}

// Method Description:
// - Returns an iterable collection of all available terminals.
// Arguments:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

void RefreshDefaultTerminals();

static bool IsDefaultTerminalAvailable() noexcept;
Windows::Foundation::Collections::IObservableVector<Model::DefaultTerminal> DefaultTerminals() const noexcept;
Model::DefaultTerminal CurrentDefaultTerminal() const noexcept;
void CurrentDefaultTerminal(Model::DefaultTerminal terminal);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Microsoft.Terminal.Settings.Model
Guid GetProfileForArgs(NewTerminalArgs newTerminalArgs);

void RefreshDefaultTerminals();
static Boolean IsDefaultTerminalAvailable { get; };
Windows.Foundation.Collections.IObservableVector<DefaultTerminal> DefaultTerminals { get; };
DefaultTerminal CurrentDefaultTerminal;
}
Expand Down

1 comment on commit 463a853

@github-actions

This comment was marked as duplicate.

Please sign in to comment.