mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #26030 - paulrouget:delayedToaster, r=jdm
UWP: Add a devtools button fix #26027 Shows the toaster when the button is clicked, instead of showing the toaster at startup.
This commit is contained in:
commit
2d055cbf6b
9 changed files with 62 additions and 15 deletions
BIN
support/hololens/ServoApp/Assets/UI/devtools.png
Normal file
BIN
support/hololens/ServoApp/Assets/UI/devtools.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"/>
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue