diff --git a/support/hololens/ServoApp/Assets/UI/devtools.png b/support/hololens/ServoApp/Assets/UI/devtools.png new file mode 100644 index 00000000000..e26f69b7887 Binary files /dev/null and b/support/hololens/ServoApp/Assets/UI/devtools.png differ diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp index 97784d9edd2..e8ba12ba2b3 100644 --- a/support/hololens/ServoApp/BrowserPage.cpp +++ b/support/hololens/ServoApp/BrowserPage.cpp @@ -15,6 +15,7 @@ using namespace winrt::Windows::UI::Core; using namespace winrt::Windows::UI::ViewManagement; using namespace winrt::Windows::ApplicationModel::Core; using namespace winrt::Windows::UI::Notifications; +using namespace winrt::Windows::Data::Xml::Dom; namespace winrt::ServoApp::implementation { BrowserPage::BrowserPage() { @@ -72,6 +73,11 @@ void BrowserPage::BindServoEvents() { ? Visibility::Collapsed : Visibility::Visible); }); + servoControl().OnDevtoolsStatusChanged( + [=](DevtoolsStatus status, unsigned int port) { + mDevtoolsStatus = status; + mDevtoolsPort = port; + }); Window::Current().VisibilityChanged( [=](const auto &, const VisibilityChangedEventArgs &args) { servoControl().ChangeVisibility(args.Visible()); @@ -142,6 +148,25 @@ void BrowserPage::OnHomeButtonClicked(IInspectable const &, servoControl().LoadURIOrSearch(DEFAULT_URL); } +void BrowserPage::OnDevtoolsButtonClicked(IInspectable const &, + RoutedEventArgs const &) { + auto toastTemplate = ToastTemplateType::ToastText01; + auto toastXml = ToastNotificationManager::GetTemplateContent(toastTemplate); + auto toastTextElements = toastXml.GetElementsByTagName(L"text"); + std::wstring message; + if (mDevtoolsStatus == DevtoolsStatus::Stopped) { + message = L"Devtools server hasn't started"; + } else if (mDevtoolsStatus == DevtoolsStatus::Running) { + message = L"DevTools server has started on port " + + std::to_wstring(mDevtoolsPort); + } else if (mDevtoolsStatus == DevtoolsStatus::Failed) { + message = L"Error: could not start DevTools"; + } + toastTextElements.Item(0).InnerText(message); + auto toast = ToastNotification(toastXml); + ToastNotificationManager::CreateToastNotifier().Show(toast); +} + void BrowserPage::OnURLEdited(IInspectable const &, Input::KeyRoutedEventArgs const &e) { if (e.Key() == Windows::System::VirtualKey::Enter) { diff --git a/support/hololens/ServoApp/BrowserPage.h b/support/hololens/ServoApp/BrowserPage.h index 92af23b7d05..bb57afad68a 100644 --- a/support/hololens/ServoApp/BrowserPage.h +++ b/support/hololens/ServoApp/BrowserPage.h @@ -26,6 +26,8 @@ public: Windows::UI::Xaml::RoutedEventArgs const &); void OnHomeButtonClicked(Windows::Foundation::IInspectable const &, Windows::UI::Xaml::RoutedEventArgs const &); + void OnDevtoolsButtonClicked(Windows::Foundation::IInspectable const &, + Windows::UI::Xaml::RoutedEventArgs const &); void OnURLEdited(Windows::Foundation::IInspectable const &, Windows::UI::Xaml::Input::KeyRoutedEventArgs const &); void OnURLFocused(Windows::Foundation::IInspectable const &); @@ -43,6 +45,8 @@ public: private: void BindServoEvents(); + DevtoolsStatus mDevtoolsStatus = DevtoolsStatus::Stopped; + unsigned int mDevtoolsPort = 0; }; } // namespace winrt::ServoApp::implementation diff --git a/support/hololens/ServoApp/BrowserPage.xaml b/support/hololens/ServoApp/BrowserPage.xaml index e71208ea76c..3fa6cf84982 100644 --- a/support/hololens/ServoApp/BrowserPage.xaml +++ b/support/hololens/ServoApp/BrowserPage.xaml @@ -125,7 +125,12 @@ - + + + + diff --git a/support/hololens/ServoApp/ServoApp.vcxproj b/support/hololens/ServoApp/ServoApp.vcxproj index 6d729b3661b..a39b23f4737 100644 --- a/support/hololens/ServoApp/ServoApp.vcxproj +++ b/support/hololens/ServoApp/ServoApp.vcxproj @@ -903,6 +903,7 @@ + diff --git a/support/hololens/ServoApp/ServoApp.vcxproj.filters b/support/hololens/ServoApp/ServoApp.vcxproj.filters index 0e78db725be..caff136e123 100644 --- a/support/hololens/ServoApp/ServoApp.vcxproj.filters +++ b/support/hololens/ServoApp/ServoApp.vcxproj.filters @@ -154,6 +154,9 @@ Assets\UI + + Assets\UI + diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index 6f21ab41dc1..cf3393f976e 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -11,8 +11,6 @@ using namespace winrt::Windows::UI::Core; using namespace winrt::Windows::Foundation; using namespace winrt::Windows::System; using namespace winrt::Windows::Devices::Input; -using namespace winrt::Windows::UI::Notifications; -using namespace winrt::Windows::Data::Xml::Dom; using namespace concurrency; using namespace winrt::servo; @@ -560,18 +558,10 @@ std::optional ServoControl::OnServoPromptInput(winrt::hstring message, void ServoControl::OnServoDevtoolsStarted(bool success, const unsigned int port) { - auto toastTemplate = ToastTemplateType::ToastText01; - auto toastXml = ToastNotificationManager::GetTemplateContent(toastTemplate); - auto toastTextElements = toastXml.GetElementsByTagName(L"text"); - std::wstring message; - if (success) { - message = L"DevTools server has started on port " + std::to_wstring(port); - } else { - message = L"Error: could not start DevTools"; - } - toastTextElements.Item(0).InnerText(message); - auto toast = ToastNotification(toastXml); - ToastNotificationManager::CreateToastNotifier().Show(toast); + RunOnUIThread([=] { + auto status = success ? DevtoolsStatus::Running : DevtoolsStatus::Failed; + mOnDevtoolsStatusChangedEvent(status, port); + }); } template void ServoControl::RunOnUIThread(Callable cb) { diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h index 16b34b77349..685f038311b 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -44,6 +44,14 @@ struct ServoControl : ServoControlT, public servo::ServoDelegate { mOnHistoryChangedEvent.remove(token); } + winrt::event_token + OnDevtoolsStatusChanged(DevtoolsStatusChangedDelegate const &handler) { + return mOnDevtoolsStatusChangedEvent.add(handler); + }; + void OnDevtoolsStatusChanged(winrt::event_token const &token) noexcept { + mOnDevtoolsStatusChangedEvent.remove(token); + } + winrt::event_token OnLoadStarted(EventDelegate const &handler) { return mOnLoadStartedEvent.add(handler); }; @@ -116,10 +124,13 @@ struct ServoControl : ServoControlT, public servo::ServoDelegate { winrt::hstring, bool); virtual void OnServoDevtoolsStarted(bool success, const unsigned int port); + DevtoolsStatus GetDevtoolsStatus(); + private: winrt::event> mOnURLChangedEvent; winrt::event> mOnTitleChangedEvent; winrt::event mOnHistoryChangedEvent; + winrt::event mOnDevtoolsStatusChangedEvent; winrt::event mOnLoadStartedEvent; winrt::event mOnLoadEndedEvent; winrt::event mOnCaptureGesturesStartedEvent; diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.idl b/support/hololens/ServoApp/ServoControl/ServoControl.idl index 8e1c60df574..5e5da81bc29 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.idl +++ b/support/hololens/ServoApp/ServoControl/ServoControl.idl @@ -3,6 +3,13 @@ namespace ServoApp { delegate void EventDelegate(); delegate void HistoryChangedDelegate(Boolean back, Boolean forward); delegate void MediaSessionMetadataDelegate(String title, String artist, String album); + delegate void DevtoolsStatusChangedDelegate(DevtoolsStatus status, UInt32 port); + + enum DevtoolsStatus { + Running = 0, + Stopped, + Failed, + }; runtimeclass ServoControl : Windows.UI.Xaml.Controls.Control { ServoControl(); @@ -20,6 +27,7 @@ namespace ServoApp { event EventDelegate OnLoadEnded; event EventDelegate OnCaptureGesturesStarted; event EventDelegate OnCaptureGesturesEnded; + event DevtoolsStatusChangedDelegate OnDevtoolsStatusChanged; event HistoryChangedDelegate OnHistoryChanged; event Windows.Foundation.EventHandler OnTitleChanged; event Windows.Foundation.EventHandler OnURLChanged;