MonacoEditPage.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "MonacoEditPage.g.h"
  3. #include <functional>
  4. using namespace winrt::Windows::Foundation;
  5. using namespace winrt::Windows::UI::Xaml;
  6. using namespace winrt::Windows::UI::Xaml::Navigation;
  7. namespace MUXC = winrt::Microsoft::UI::Xaml::Controls;
  8. using winrt::Microsoft::Web::WebView2::Core::CoreWebView2WebMessageReceivedEventArgs;
  9. namespace winrt::Maple_App::implementation
  10. {
  11. constexpr wchar_t const* CONFIG_ROOT_VIRTUAL_HOSTW = L"http://maple-monaco-editor-config-root.com/";
  12. constexpr char const* CONFIG_ROOT_VIRTUAL_HOST = "http://maple-monaco-editor-config-root.com/";
  13. constexpr wchar_t const* WEBVIEW_EDITOR_URL = L"http://maple-monaco-editor-app-root.com/MonacoEditor/editor.html";
  14. enum class MonacoEditPageWebViewState
  15. {
  16. Uninitialized,
  17. AwaitingEditorReady,
  18. EditorReady,
  19. };
  20. struct MonacoEditPage : MonacoEditPageT<MonacoEditPage>
  21. {
  22. MonacoEditPage();
  23. fire_and_forget OnNavigatedTo(NavigationEventArgs const& e);
  24. fire_and_forget Page_Loaded(IInspectable const& sender, RoutedEventArgs const& e);
  25. fire_and_forget WebView_WebMessageReceived(MUXC::WebView2 const& sender, CoreWebView2WebMessageReceivedEventArgs const& args);
  26. inline static std::function<IAsyncAction()> SaveModifiedContent{ nullptr };
  27. private:
  28. auto const static inline packagePath = Windows::ApplicationModel::Package::Current().InstalledPath();
  29. auto const static inline configPath = Windows::Storage::ApplicationData::Current().LocalFolder().Path() + L"\\config";
  30. IAsyncAction initializeWebView();
  31. MonacoEditPageWebViewState m_webviewState{ MonacoEditPageWebViewState::Uninitialized };
  32. std::coroutine_handle<> m_fileSaveHandle{ nullptr };
  33. hstring m_currentFileName{};
  34. std::string m_currentSavingFileName{};
  35. };
  36. }
  37. namespace winrt::Maple_App::factory_implementation
  38. {
  39. struct MonacoEditPage : MonacoEditPageT<MonacoEditPage, implementation::MonacoEditPage>
  40. {
  41. };
  42. }