It doesn't crash on launch. That's something. There's no startupActions though, so it immediately exits

This commit is contained in:
Mike Griese
2023-01-31 09:34:02 -06:00
parent 439b21f879
commit 99bc280207
6 changed files with 42 additions and 8 deletions

View File

@@ -301,6 +301,11 @@ namespace winrt::TerminalApp::implementation
return hr;
}
bool AppLogic::HasSettingsStartupActions() const noexcept
{
return _hasSettingsStartupActions;
}
// Call this function after loading your _settings.
// It handles any CPU intensive settings updates (like updating the Jumplist)
// which should thus only occur if the settings file actually changed.
@@ -474,6 +479,10 @@ namespace winrt::TerminalApp::implementation
}
else
{
// TODO! Arg should be a SettingsLoadEventArgs{ result, warnings, error, settings}
//
// _SettingsChangedHandlers(*this, make_self<SettingsLoadEventArgs>( _settingsLoadedResult, warnings, _settingsLoadExceptionText, settings}))
// const winrt::hstring titleKey = USES_RESOURCE(L"ReloadJsonParseErrorTitle");
// const winrt::hstring textKey = USES_RESOURCE(L"ReloadJsonParseErrorText");
// _ShowLoadErrorsDialog(titleKey, textKey, _settingsLoadedResult);
@@ -500,7 +509,7 @@ namespace winrt::TerminalApp::implementation
_ApplyStartupTaskStateChange();
_ProcessLazySettingsChanges();
_SettingsChangedHandlers(*this, nullptr);
_SettingsChangedHandlers(*this, _settings);
}
// Method Description:
@@ -675,6 +684,12 @@ namespace winrt::TerminalApp::implementation
TerminalApp::TerminalWindow AppLogic::CreateNewWindow()
{
return *winrt::make_self<implementation::TerminalWindow>(_settings);
if (_settings == nullptr)
{
ReloadSettings();
}
auto window = winrt::make_self<implementation::TerminalWindow>(_settings);
this->SettingsChanged({ window->get_weak(), &implementation::TerminalWindow::UpdateSettingsHandler });
return *window;
}
}

View File

@@ -52,6 +52,8 @@ namespace winrt::TerminalApp::implementation
bool IsElevated() const noexcept;
void ReloadSettings();
bool HasSettingsStartupActions() const noexcept;
[[nodiscard]] Microsoft::Terminal::Settings::Model::CascadiaSettings GetSettings() const noexcept;
TerminalApp::FindTargetWindowResult FindTargetWindow(array_view<const winrt::hstring> actions);

View File

@@ -27,6 +27,8 @@ namespace TerminalApp
void RunAsUwp();
Boolean IsElevated();
Boolean HasSettingsStartupActions();
void ReloadSettings();
void SetInboundListener();
@@ -37,6 +39,9 @@ namespace TerminalApp
TerminalWindow CreateNewWindow();
Boolean ShouldImmediatelyHandoffToElevated();
void HandoffToElevated();
Windows.Foundation.Collections.IMapView<Microsoft.Terminal.Control.KeyChord, Microsoft.Terminal.Settings.Model.Command> GlobalHotkeys();
event Windows.Foundation.TypedEventHandler<Object, Object> SettingsChanged;

View File

@@ -1137,4 +1137,14 @@ namespace winrt::TerminalApp::implementation
{
return _settings.GlobalSettings().AutoHideWindow();
}
// TODO! Arg should be a SettingsLoadEventArgs{ result, warnings, error, settings}
void TerminalWindow::UpdateSettingsHandler(const winrt::IInspectable& /*sender*/,
const winrt::IInspectable& arg)
{
if (const auto& settings{ arg.try_as<CascadiaSettings>() })
{
this->UpdateSettings(S_OK, settings);
_root->SetSettings(_settings, true);
}
}
};

View File

@@ -107,6 +107,7 @@ namespace winrt::TerminalApp::implementation
void DismissDialog();
Microsoft::Terminal::Settings::Model::Theme Theme();
void UpdateSettingsHandler(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& arg);
// -------------------------------- WinRT Events ---------------------------------
// PropertyChanged is surprisingly not a typed event, so we'll define that one manually.

View File

@@ -32,7 +32,7 @@ AppHost::AppHost() noexcept :
_app{},
_windowManager{},
_appLogic{ nullptr }, // don't make one, we're going to take a ref on app's
_windowLogic{ nullptr },
_windowLogic{ nullptr },
_window{ nullptr },
_getWindowLayoutThrottler{} // this will get set if we become the monarch
{
@@ -234,7 +234,7 @@ void AppHost::_HandleCommandlineArgs()
}
// We did want to make a window, so let's instantiate it here.
// We don't have XAML yet, but we do have other stuff.
// We don't have XAML yet, but we do have other stuff.
_windowLogic = _appLogic.CreateNewWindow();
if (auto peasant{ _windowManager.CurrentWindow() })
@@ -269,10 +269,10 @@ void AppHost::_HandleCommandlineArgs()
// the window at all here. In that case, we're going through this
// special escape hatch to dispatch all the calls to elevate-shim, and
// then we're going to exit immediately.
if (_windowLogic.ShouldImmediatelyHandoffToElevated())
if (_appLogic.ShouldImmediatelyHandoffToElevated())
{
_shouldCreateWindow = false;
_windowLogic.HandoffToElevated();
_appLogic.HandoffToElevated();
return;
}
@@ -425,6 +425,7 @@ void AppHost::Initialize()
_revokers.PropertyChanged = _windowLogic.PropertyChanged(winrt::auto_revoke, { this, &AppHost::_PropertyChangedHandler });
_appLogic.Create();
_windowLogic.Create();
_revokers.TitleChanged = _windowLogic.TitleChanged(winrt::auto_revoke, { this, &AppHost::AppTitleChanged });
_revokers.LastTabClosed = _windowLogic.LastTabClosed(winrt::auto_revoke, { this, &AppHost::LastTabClosed });
@@ -974,14 +975,14 @@ void AppHost::_BecomeMonarch(const winrt::Windows::Foundation::IInspectable& /*s
if (_getWindowLayoutThrottler) {
_getWindowLayoutThrottler.value()();
}
_appLogic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants()); });
_windowLogic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants()); });
_WindowClosedToken = _windowManager.WindowClosed([this](auto&&, auto&&) {
if (_getWindowLayoutThrottler)
{
_getWindowLayoutThrottler.value()();
}
_appLogic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants());
_windowLogic.SetNumberOfOpenWindows(_windowManager.GetNumberOfPeasants());
});
// These events are coming from peasants that become or un-become quake windows.