From 9174b201b0b0eeedded34c9cd9868669802f6b4e Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Fri, 17 Jul 2020 08:32:10 +0200 Subject: [PATCH] UWP: rely more on servo preferences --- support/hololens/ServoApp/DefaultUrl.h | 4 +- .../hololens/ServoApp/ServoControl/Servo.cpp | 49 ++++++++++--------- .../hololens/ServoApp/ServoControl/Servo.h | 1 + .../ServoApp/ServoControl/ServoControl.cpp | 2 + 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/support/hololens/ServoApp/DefaultUrl.h b/support/hololens/ServoApp/DefaultUrl.h index b5d82e65478..ba1719dc530 100644 --- a/support/hololens/ServoApp/DefaultUrl.h +++ b/support/hololens/ServoApp/DefaultUrl.h @@ -1,8 +1,6 @@ #pragma once -#define DEFAULT_URL_PROD L"https://servo.org/hl-home/" - // For development purpose. -// Will override DEFAULT_URL_PROD or any locally stored preferences. +// Will override shell.homepage preference: // #define OVERRIDE_DEFAULT_URL L"data:text/html," // #define OVERRIDE_DEFAULT_URL L"http://localhost:8000/test.html" diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp index 6f724d4bcbb..0602fcb7992 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -147,14 +147,6 @@ Servo::Servo(std::optional initUrl, hstring args, GLsizei width, auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs"); - if (!prefs.Values().HasKey(L"shell.homepage")) { - prefs.Values().Insert(L"shell.homepage", box_value(DEFAULT_URL_PROD)); - } - - if (!prefs.Values().HasKey(L"dom.webxr.enabled")) { - prefs.Values().Insert(L"dom.webxr.enabled", box_value(true)); - } - std::vector cprefs; for (auto pref : prefs.Values()) { @@ -172,22 +164,9 @@ Servo::Servo(std::optional initUrl, hstring args, GLsizei width, auto val = unbox_value(value); cpref.value = &val; } else if (type == Windows::Foundation::PropertyType::String) { - hstring strValue; - if (pref.Key() == L"shell.homepage") { - if (initUrl.has_value()) { - strValue = *initUrl; - } else { -#ifdef OVERRIDE_DEFAULT_URL - strValue = OVERRIDE_DEFAULT_URL; -#else - strValue = unbox_value(value); -#endif - } - } else { - strValue = unbox_value(value); - } cpref.pref_type = capi::CPrefType::Str; - cpref.value = *hstring2char(strValue); + auto val = unbox_value(value); + cpref.value = *hstring2char(val); } else if (type == Windows::Foundation::PropertyType::Int64) { cpref.pref_type = capi::CPrefType::Int; auto val = unbox_value(value); @@ -205,11 +184,19 @@ Servo::Servo(std::optional initUrl, hstring args, GLsizei width, cprefs.push_back(cpref); } + if (initUrl.has_value()) { + setNonPersistentHomepage(*initUrl, cprefs); + } else { +#ifdef OVERRIDE_DEFAULT_URL + setNonPersistentHomepage(OVERRIDE_DEFAULT_URL, cprefs); +#endif + } + capi::CPrefList prefsList = {cprefs.size(), cprefs.data()}; capi::CInitOptions o; o.prefs = &prefsList; - o.args = *hstring2char(args + L" --devtools"); + o.args = *hstring2char(args); o.width = mWindowWidth; o.height = mWindowHeight; o.density = dpi; @@ -385,6 +372,20 @@ std::vector Servo::GetPrefs() { return vec; } +void setNonPersistentHomepage(hstring url, std::vector &cprefs) { + for (auto cpref : cprefs) { + if (strcmp(cpref.key, "shell.homepage") == 0) { + cpref.value = *hstring2char(url); + return; + } + } + capi::CPref cpref; + cpref.key = "shell.homepage"; + cpref.pref_type = capi::CPrefType::Str; + cpref.value = *hstring2char(url); + cprefs.push_back(cpref); +} + winrt::hstring char2hstring(const char *c_str) { // FIXME: any better way of doing this? auto str = std::string(c_str); diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h index 2d8e3b0f091..e6eaf428be1 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.h +++ b/support/hololens/ServoApp/ServoControl/Servo.h @@ -21,6 +21,7 @@ using namespace capi; hstring char2hstring(const char *); std::unique_ptr hstring2char(hstring); +void setNonPersistentHomepage(hstring, std::vector &); class ServoDelegate; diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index db4710f0606..d0d1e814e91 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -661,6 +661,8 @@ void ServoControl::OnServoDevtoolsStarted(bool success, const unsigned int port, hstring token) { RunOnUIThread([=] { auto status = success ? DevtoolsStatus::Running : DevtoolsStatus::Failed; + // This port works, let's save it for future use. + Servo::SetIntPref(L"devtools.server.port", port); mOnDevtoolsStatusChangedEvent(status, port, token); }); }