aboutsummaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorPaul Rouget <me@paulrouget.com>2020-03-25 13:19:50 +0100
committerPaul Rouget <me@paulrouget.com>2020-03-25 13:23:10 +0100
commita707432b00f5a5e54dfaffd1f76125988650ec4d (patch)
treea1660ad0c151aa8aa309904b8a5c8defc387a3fa /support
parent6ca767d7f92eb22eb7631283973ef8305567bf07 (diff)
downloadservo-a707432b00f5a5e54dfaffd1f76125988650ec4d.tar.gz
servo-a707432b00f5a5e54dfaffd1f76125988650ec4d.zip
Add a devtools button
Diffstat (limited to 'support')
-rw-r--r--support/hololens/ServoApp/Assets/UI/devtools.pngbin0 -> 2372 bytes
-rw-r--r--support/hololens/ServoApp/BrowserPage.cpp25
-rw-r--r--support/hololens/ServoApp/BrowserPage.h4
-rw-r--r--support/hololens/ServoApp/BrowserPage.xaml7
-rw-r--r--support/hololens/ServoApp/ServoApp.vcxproj1
-rw-r--r--support/hololens/ServoApp/ServoApp.vcxproj.filters3
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.cpp18
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.h11
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.idl8
9 files changed, 62 insertions, 15 deletions
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
--- /dev/null
+++ b/support/hololens/ServoApp/Assets/UI/devtools.png
Binary files 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 @@
<KeyboardAccelerator Key="L" Modifiers="Control" Invoked="OnURLKeyboardAccelerator"/>
</TextBox.KeyboardAccelerators>
</TextBox>
- <ProgressRing x:Name="urlbarLoadingIndicator" Grid.Column="2" Margin="10,0"/>
+ <StackPanel Orientation="Horizontal" Grid.Column="2">
+ <Button Style="{StaticResource NavigationBarButton}" x:Name="devtoolsButton" IsTabStop="true" Click="OnDevtoolsButtonClicked" AutomationProperties.Name="Devtools" ToolTipService.ToolTip="Devtools">
+ <Image Source="Assets/UI/devtools.png" Height="18"></Image>
+ </Button>
+ <ProgressRing x:Name="urlbarLoadingIndicator" Margin="10,0"/>
+ </StackPanel>
</Grid>
<local:ServoControl TabIndex="0" x:Name="servoControl" Grid.Row="1"/>
<ProgressBar x:Name="transientLoadingIndicator" Visibility="Collapsed" Grid.Row="2"/>
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 @@
<Image Include="Assets\StoreLogo.scale-200.png" />
<Image Include="Assets\StoreLogo.scale-400.png" />
<Image Include="Assets\UI\back.png" />
+ <Image Include="Assets\UI\devtools.png" />
<Image Include="Assets\UI\forward.png" />
<Image Include="Assets\UI\home.png" />
<Image Include="Assets\UI\reload.png" />
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 @@
<Image Include="Assets\UI\home.png">
<Filter>Assets\UI</Filter>
</Image>
+ <Image Include="Assets\UI\devtools.png">
+ <Filter>Assets\UI</Filter>
+ </Image>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
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<hstring> 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 <typename Callable> 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<ServoControl>, 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<ServoControl>, public servo::ServoDelegate {
winrt::hstring, bool);
virtual void OnServoDevtoolsStarted(bool success, const unsigned int port);
+ DevtoolsStatus GetDevtoolsStatus();
+
private:
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnURLChangedEvent;
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnTitleChangedEvent;
winrt::event<HistoryChangedDelegate> mOnHistoryChangedEvent;
+ winrt::event<DevtoolsStatusChangedDelegate> mOnDevtoolsStatusChangedEvent;
winrt::event<EventDelegate> mOnLoadStartedEvent;
winrt::event<EventDelegate> mOnLoadEndedEvent;
winrt::event<EventDelegate> 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<String> OnTitleChanged;
event Windows.Foundation.EventHandler<String> OnURLChanged;