Skip to content

Commit

Permalink
UWP port: re-enable devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Mar 16, 2020
1 parent 58ff35f commit 0039512
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
6 changes: 5 additions & 1 deletion support/hololens/ServoApp/BrowserPage.cpp
Expand Up @@ -14,6 +14,7 @@ using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::UI::ViewManagement;
using namespace winrt::Windows::ApplicationModel::Core;
using namespace winrt::Windows::UI::Notifications;

namespace winrt::ServoApp::implementation {
BrowserPage::BrowserPage() {
Expand Down Expand Up @@ -109,7 +110,10 @@ void BrowserPage::SetTransientMode(bool transient) {

void BrowserPage::SetArgs(hstring args) { servoControl().SetArgs(args); }

void BrowserPage::Shutdown() { servoControl().Shutdown(); }
void BrowserPage::Shutdown() {
ToastNotificationManager::History().Clear();
servoControl().Shutdown();
}

/**** USER INTERACTIONS WITH UI ****/

Expand Down
13 changes: 7 additions & 6 deletions support/hololens/ServoApp/ServoControl/Servo.cpp
Expand Up @@ -67,6 +67,12 @@ void prompt_alert(const char *message, bool trusted) {
sServo->Delegate().OnServoPromptAlert(char2hstring(message), trusted);
}

void on_devtools_started(Servo::DevtoolsServerState result,
const unsigned int port) {
sServo->Delegate().OnServoDevtoolsStarted(
result == Servo::DevtoolsServerState::Started, port);
}

Servo::PromptResult prompt_ok_cancel(const char *message, bool trusted) {
return sServo->Delegate().OnServoPromptOkCancel(char2hstring(message),
trusted);
Expand All @@ -87,17 +93,12 @@ const char *prompt_input(const char *message, const char *default,
}
}

void on_devtools_started(Servo::DevtoolsServerState result,
const unsigned int port) {
// FIXME
}

Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
float dpi, ServoDelegate &aDelegate)
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {

capi::CInitOptions o;
hstring defaultPrefs = L" --pref dom.webxr.enabled";
hstring defaultPrefs = L" --pref dom.webxr.enabled --devtools";
o.args = *hstring2char(args + defaultPrefs);
o.url = *hstring2char(url);
o.width = mWindowWidth;
Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/ServoControl/Servo.h
Expand Up @@ -95,6 +95,7 @@ class ServoDelegate {
virtual bool OnServoAllowNavigation(hstring) = 0;
virtual void OnServoAnimatingChanged(bool) = 0;
virtual void OnServoIMEStateChanged(bool) = 0;
virtual void OnServoDevtoolsStarted(bool, unsigned int) = 0;
virtual void Flush() = 0;
virtual void MakeCurrent() = 0;
virtual void OnServoMediaSessionMetadata(hstring, hstring, hstring) = 0;
Expand Down
18 changes: 18 additions & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.cpp
Expand Up @@ -11,6 +11,8 @@ 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 @@ -556,6 +558,22 @@ std::optional<hstring> ServoControl::OnServoPromptInput(winrt::hstring message,
return string;
}

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);
}

template <typename Callable> void ServoControl::RunOnUIThread(Callable cb) {
Dispatcher().RunAsync(CoreDispatcherPriority::High, cb);
}
Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.h
Expand Up @@ -114,6 +114,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
virtual servo::Servo::PromptResult OnServoPromptYesNo(winrt::hstring, bool);
virtual std::optional<hstring> OnServoPromptInput(winrt::hstring,
winrt::hstring, bool);
virtual void OnServoDevtoolsStarted(bool success, const unsigned int port);

private:
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnURLChangedEvent;
Expand Down
2 changes: 2 additions & 0 deletions support/hololens/ServoApp/pch.h
Expand Up @@ -52,3 +52,5 @@
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Markup.h>
#include <winrt/Windows.UI.Xaml.Navigation.h>
#include <winrt/Windows.UI.Notifications.h>
#include <winrt/Windows.Data.Xml.Dom.h>

0 comments on commit 0039512

Please sign in to comment.