Add a devtools button

This commit is contained in:
Paul Rouget 2020-03-25 13:19:50 +01:00
parent 6ca767d7f9
commit a707432b00
9 changed files with 62 additions and 15 deletions

View file

@ -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) {