mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Add a devtools button
This commit is contained in:
parent
6ca767d7f9
commit
a707432b00
9 changed files with 62 additions and 15 deletions
|
@ -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