2019-11-07 22:10:58 +01:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AppLogic.g.h"
|
|
|
|
|
|
|
|
#include "Tab.h"
|
|
|
|
#include "CascadiaSettings.h"
|
|
|
|
#include "TerminalPage.h"
|
|
|
|
#include "../../cascadia/inc/cppwinrt_utils.h"
|
|
|
|
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
|
|
{
|
|
|
|
struct AppLogic : AppLogicT<AppLogic>
|
|
|
|
{
|
|
|
|
public:
|
2020-04-07 20:35:05 +02:00
|
|
|
static AppLogic* Current() noexcept;
|
|
|
|
|
2019-11-07 22:10:58 +01:00
|
|
|
AppLogic();
|
|
|
|
~AppLogic() = default;
|
|
|
|
|
|
|
|
void Create();
|
2019-12-09 20:07:08 +01:00
|
|
|
bool IsUwp() const noexcept;
|
2019-11-26 01:30:45 +01:00
|
|
|
void RunAsUwp();
|
2020-03-11 16:52:09 +01:00
|
|
|
bool IsElevated() const noexcept;
|
2019-11-07 22:10:58 +01:00
|
|
|
void LoadSettings();
|
2019-11-25 23:22:29 +01:00
|
|
|
[[nodiscard]] std::shared_ptr<::TerminalApp::CascadiaSettings> GetSettings() const noexcept;
|
2019-11-07 22:10:58 +01:00
|
|
|
|
2020-01-27 16:34:12 +01:00
|
|
|
int32_t SetStartupCommandline(array_view<const winrt::hstring> actions);
|
2020-05-04 22:56:15 +02:00
|
|
|
winrt::hstring ParseCommandlineMessage();
|
|
|
|
bool ShouldExitEarly();
|
2020-01-27 16:34:12 +01:00
|
|
|
|
2020-04-07 20:35:05 +02:00
|
|
|
winrt::hstring ApplicationDisplayName() const;
|
|
|
|
winrt::hstring ApplicationVersion() const;
|
|
|
|
|
2019-11-07 22:10:58 +01:00
|
|
|
Windows::Foundation::Point GetLaunchDimensions(uint32_t dpi);
|
|
|
|
winrt::Windows::Foundation::Point GetLaunchInitialPositions(int32_t defaultInitialX, int32_t defaultInitialY);
|
|
|
|
winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme();
|
|
|
|
LaunchMode GetLaunchMode();
|
|
|
|
bool GetShowTabsInTitlebar();
|
2020-01-08 22:19:23 +01:00
|
|
|
float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const;
|
2019-11-07 22:10:58 +01:00
|
|
|
|
|
|
|
Windows::UI::Xaml::UIElement GetRoot() noexcept;
|
|
|
|
|
|
|
|
hstring Title();
|
|
|
|
void TitlebarClicked();
|
2020-03-05 21:35:46 +01:00
|
|
|
bool OnF7Pressed();
|
2019-11-07 22:10:58 +01:00
|
|
|
|
|
|
|
void WindowCloseButtonClicked();
|
|
|
|
|
|
|
|
// -------------------------------- WinRT Events ---------------------------------
|
|
|
|
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RequestedThemeChanged, _requestedThemeChangedHandlers, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::ElementTheme);
|
|
|
|
|
|
|
|
private:
|
2019-11-26 01:30:45 +01:00
|
|
|
bool _isUwp{ false };
|
2020-03-11 16:52:09 +01:00
|
|
|
bool _isElevated{ false };
|
2019-11-26 01:30:45 +01:00
|
|
|
|
2019-11-07 22:10:58 +01:00
|
|
|
// If you add controls here, but forget to null them either here or in
|
|
|
|
// the ctor, you're going to have a bad time. It'll mysteriously fail to
|
|
|
|
// activate the AppLogic.
|
|
|
|
// ALSO: If you add any UIElements as roots here, make sure they're
|
2020-02-10 21:40:01 +01:00
|
|
|
// updated in _ApplyTheme. The root currently is _root.
|
2019-11-07 22:10:58 +01:00
|
|
|
winrt::com_ptr<TerminalPage> _root{ nullptr };
|
|
|
|
|
|
|
|
std::shared_ptr<::TerminalApp::CascadiaSettings> _settings{ nullptr };
|
|
|
|
|
|
|
|
HRESULT _settingsLoadedResult;
|
|
|
|
winrt::hstring _settingsLoadExceptionText{};
|
|
|
|
|
|
|
|
bool _loadedInitialSettings;
|
|
|
|
|
|
|
|
wil::unique_folder_change_reader_nothrow _reader;
|
|
|
|
|
|
|
|
std::shared_mutex _dialogLock;
|
|
|
|
|
|
|
|
std::atomic<bool> _settingsReloadQueued{ false };
|
|
|
|
|
|
|
|
fire_and_forget _ShowDialog(const winrt::Windows::Foundation::IInspectable& sender, winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
|
|
|
|
void _ShowLoadErrorsDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey, HRESULT settingsLoadedResult);
|
|
|
|
void _ShowLoadWarningsDialog();
|
|
|
|
|
Converts Dispatcher().RunAsync to WinRT Coroutines (#4051)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
This PR turns all* instances of `Dispatcher().RunAsync` to WinRT coroutines 👌.
This was good coding fodder to fill my plane ride ✈️. Enjoy your holidays everyone!
*With the exception of three functions whose signatures cannot be changed due to inheritance and function overriding in `TermControlAutomationPeer` [`L44`](https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp#L44), [`L58`](https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp#L58), [`L72`](https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalControl/TermControlAutomationPeer.cpp#L72).
<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? -->
## References
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #3919
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
* [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #3919
<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
My thought pattern here was to minimally disturb the existing code where possible. So where I could, I converted existing functions into coroutine using functions (like in the [core example](https://github.com/microsoft/terminal/issues/3919#issue-536598706)). For ~the most part~ all instances, I used the format where [`this` is accessed safely within a locked scope](https://github.com/microsoft/terminal/issues/3919#issuecomment-564730620). Some function signatures were changed to take objects by value instead of reference, so the coroutines don't crash when the objects are accessed past their original lifetime. The [copy](https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalApp/TerminalPage.cpp#L1132) and [paste](https://github.com/microsoft/terminal/blob/master/src/cascadia/TerminalApp/TerminalPage.cpp#L1170) event handler entry points were originally set to a high priority; however, the WinRT coroutines don't appear to support a priority scheme so this priority setting was not preserved in the translation.
<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
Compiles and runs, and for every event with a clear trigger repro, I triggered it to ensure crashes weren't introduced.
2020-01-10 04:29:49 +01:00
|
|
|
fire_and_forget _LoadErrorsDialogRoutine();
|
|
|
|
fire_and_forget _ShowLoadWarningsDialogRoutine();
|
|
|
|
fire_and_forget _RefreshThemeRoutine();
|
|
|
|
|
2019-11-07 22:10:58 +01:00
|
|
|
void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
|
|
|
|
|
|
|
|
[[nodiscard]] HRESULT _TryLoadSettings() noexcept;
|
|
|
|
void _RegisterSettingsChange();
|
|
|
|
fire_and_forget _DispatchReloadSettings();
|
|
|
|
void _ReloadSettings();
|
|
|
|
|
|
|
|
void _ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme);
|
|
|
|
|
|
|
|
// These are events that are handled by the TerminalPage, but are
|
|
|
|
// exposed through the AppLogic. This macro is used to forward the event
|
|
|
|
// directly to them.
|
|
|
|
FORWARDED_TYPED_EVENT(SetTitleBarContent, winrt::Windows::Foundation::IInspectable, winrt::Windows::UI::Xaml::UIElement, _root, SetTitleBarContent);
|
|
|
|
FORWARDED_TYPED_EVENT(TitleChanged, winrt::Windows::Foundation::IInspectable, winrt::hstring, _root, TitleChanged);
|
|
|
|
FORWARDED_TYPED_EVENT(LastTabClosed, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::LastTabClosedEventArgs, _root, LastTabClosed);
|
|
|
|
FORWARDED_TYPED_EVENT(ToggleFullscreen, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::ToggleFullscreenEventArgs, _root, ToggleFullscreen);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace winrt::TerminalApp::factory_implementation
|
|
|
|
{
|
|
|
|
struct AppLogic : AppLogicT<AppLogic, implementation::AppLogic>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
}
|