Skip to content

Commit

Permalink
Auto merge of #26030 - paulrouget:delayedToaster, r=jdm
Browse files Browse the repository at this point in the history
UWP: Add a devtools button

fix #26027

Shows the toaster when the button is clicked, instead of showing the toaster at startup.
  • Loading branch information
bors-servo committed Mar 25, 2020
2 parents 998f9d1 + a707432 commit 2d055cb
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
Binary file added support/hololens/ServoApp/Assets/UI/devtools.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions support/hololens/ServoApp/BrowserPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions support/hololens/ServoApp/BrowserPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct BrowserPage : BrowserPageT<BrowserPage> {
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 &);
Expand All @@ -43,6 +45,8 @@ struct BrowserPage : BrowserPageT<BrowserPage> {

private:
void BindServoEvents();
DevtoolsStatus mDevtoolsStatus = DevtoolsStatus::Stopped;
unsigned int mDevtoolsPort = 0;
};
} // namespace winrt::ServoApp::implementation

Expand Down
7 changes: 6 additions & 1 deletion support/hololens/ServoApp/BrowserPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/ServoApp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 3 additions & 0 deletions support/hololens/ServoApp/ServoApp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
18 changes: 4 additions & 14 deletions support/hololens/ServoApp/ServoControl/ServoControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 2d055cb

Please sign in to comment.