From 2ef6ba25dc053a5ff381637c71b30748b943f869 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Fri, 26 Jun 2020 13:40:44 +0200 Subject: [PATCH] Fix DEFAULT_URL --- support/hololens/ServoApp/BrowserPage.cpp | 3 +- support/hololens/ServoApp/DefaultUrl.h | 7 +- .../hololens/ServoApp/ServoControl/Servo.cpp | 64 +++++++++++-------- .../hololens/ServoApp/ServoControl/Servo.h | 4 +- .../ServoApp/ServoControl/ServoControl.cpp | 11 ++-- .../ServoApp/ServoControl/ServoControl.h | 3 +- .../ServoApp/ServoControl/ServoControl.idl | 1 + 7 files changed, 56 insertions(+), 37 deletions(-) diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp index 39aa07099933..5c129a2bf769 100644 --- a/support/hololens/ServoApp/BrowserPage.cpp +++ b/support/hololens/ServoApp/BrowserPage.cpp @@ -7,7 +7,6 @@ #include "BrowserPage.h" #include "BrowserPage.g.cpp" #include "ConsoleLog.g.cpp" -#include "DefaultUrl.h" #include "Devtools/Client.h" using namespace std::placeholders; @@ -148,7 +147,7 @@ void BrowserPage::OnStopButtonClicked(IInspectable const &, void BrowserPage::OnHomeButtonClicked(IInspectable const &, RoutedEventArgs const &) { - servoControl().LoadURIOrSearch(DEFAULT_URL); + servoControl().GoHome(); } // Given a pref, update its associated UI control. diff --git a/support/hololens/ServoApp/DefaultUrl.h b/support/hololens/ServoApp/DefaultUrl.h index 98a30fa39dfa..ee17a9f0286e 100644 --- a/support/hololens/ServoApp/DefaultUrl.h +++ b/support/hololens/ServoApp/DefaultUrl.h @@ -1,3 +1,8 @@ #pragma once -#define DEFAULT_URL L"https://servo.org/hl-home/" \ No newline at end of file +#define DEFAULT_URL_PROD L"https://servo.org/hl-home/" + +// For development purpose. +// Will override DEFAULT_URL_PROD or any locally stored preferences. +// #define OVERRIDE_DEFAULT_URL "data:text/html," +// #define OVERRIDE_DEFAULT_URL "http://localhost:8000/test.html" diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp index 57f9a7536196..ebcc78c6a7fb 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -5,6 +5,8 @@ namespace winrt::servo { +using namespace Windows::Storage; + void on_load_started() { sServo->Delegate().OnServoLoadStarted(); } void on_load_ended() { sServo->Delegate().OnServoLoadEnded(); } @@ -125,23 +127,21 @@ const char *prompt_input(const char *message, const char *default, } } -Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, +Servo::Servo(hstring args, GLsizei width, GLsizei height, EGLNativeWindowType eglNativeWindow, float dpi, ServoDelegate &aDelegate) : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { - Windows::Storage::ApplicationDataContainer localSettings = - Windows::Storage::ApplicationData::Current().LocalSettings(); + ApplicationDataContainer localSettings = + ApplicationData::Current().LocalSettings(); if (!localSettings.Containers().HasKey(L"servoUserPrefs")) { - Windows::Storage::ApplicationDataContainer container = - localSettings.CreateContainer( - L"servoUserPrefs", - Windows::Storage::ApplicationDataCreateDisposition::Always); + ApplicationDataContainer container = localSettings.CreateContainer( + L"servoUserPrefs", ApplicationDataCreateDisposition::Always); } auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs"); if (!prefs.Values().HasKey(L"shell.homepage")) { - prefs.Values().Insert(L"shell.homepage", box_value(DEFAULT_URL)); + prefs.Values().Insert(L"shell.homepage", box_value(DEFAULT_URL_PROD)); } if (!prefs.Values().HasKey(L"dom.webxr.enabled")) { @@ -151,35 +151,42 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, std::vector cprefs; for (auto pref : prefs.Values()) { + auto key = *hstring2char(pref.Key()); auto value = pref.Value(); + auto type = value.as().Type(); - capi::CPref pref; - pref.key = key; - pref.pref_type = capi::CPrefType::Missing; - pref.value = NULL; + capi::CPref cpref; + cpref.key = key; + cpref.pref_type = capi::CPrefType::Missing; + cpref.value = NULL; if (type == Windows::Foundation::PropertyType::Boolean) { - pref.pref_type = capi::CPrefType::Bool; + cpref.pref_type = capi::CPrefType::Bool; auto val = unbox_value(value); - pref.value = &val; + cpref.value = &val; } else if (type == Windows::Foundation::PropertyType::String) { - pref.pref_type = capi::CPrefType::Str; - pref.value = *hstring2char(unbox_value(value)); + cpref.pref_type = capi::CPrefType::Str; + cpref.value = *hstring2char(unbox_value(value)); +#ifdef OVERRIDE_DEFAULT_URL + if (pref.Key() == L"shell.homepage") { + cpref.value = OVERRIDE_DEFAULT_URL; + } +#endif } else if (type == Windows::Foundation::PropertyType::Int64) { - pref.pref_type = capi::CPrefType::Int; + cpref.pref_type = capi::CPrefType::Int; auto val = unbox_value(value); - pref.value = &val; + cpref.value = &val; } else if (type == Windows::Foundation::PropertyType::Double) { - pref.pref_type = capi::CPrefType::Float; + cpref.pref_type = capi::CPrefType::Float; auto val = unbox_value(value); - pref.value = &val; + cpref.value = &val; } else if (type == Windows::Foundation::PropertyType::Empty) { - pref.pref_type = capi::CPrefType::Missing; + cpref.pref_type = capi::CPrefType::Missing; } else { log(L"skipping pref %s. Unknown type", key); continue; } - cprefs.push_back(pref); + cprefs.push_back(cpref); } capi::CPrefList prefsList = {cprefs.size(), cprefs.data()}; @@ -222,7 +229,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, bool logToFile = true; #endif if (logToFile) { - auto current = winrt::Windows::Storage::ApplicationData::Current(); + auto current = ApplicationData::Current(); auto filePath = std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt"; sLogHandle = @@ -315,9 +322,16 @@ Servo::PrefTuple Servo::ResetPref(hstring key) { return updatedPref; } +void Servo::GoHome() { + ApplicationDataContainer localSettings = + ApplicationData::Current().LocalSettings(); + auto prefs = localSettings.Containers().Lookup(L"servoUserPrefs"); + auto home = unbox_value(prefs.Values().Lookup(L"shell.homepage")); + LoadUri(home); +} + void Servo::SaveUserPref(PrefTuple pref) { - auto localSettings = - Windows::Storage::ApplicationData::Current().LocalSettings(); + auto localSettings = ApplicationData::Current().LocalSettings(); auto values = localSettings.Containers().Lookup(L"servoUserPrefs").Values(); auto [key, val, isDefault] = pref; if (isDefault) { diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h index d662942f1da7..1cf0641bf8be 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.h +++ b/support/hololens/ServoApp/ServoControl/Servo.h @@ -26,8 +26,7 @@ class ServoDelegate; class Servo { public: - Servo(hstring, hstring, GLsizei, GLsizei, EGLNativeWindowType, float, - ServoDelegate &); + Servo(hstring, GLsizei, GLsizei, EGLNativeWindowType, float, ServoDelegate &); ~Servo(); ServoDelegate &Delegate() { return mDelegate; } @@ -69,6 +68,7 @@ class Servo { bool LoadUri(hstring uri) { return load_uri(*hstring2char(uri)); } void ChangeVisibility(bool visible) { change_visibility(visible); } bool IsUriValid(hstring uri) { return is_uri_valid(*hstring2char(uri)); } + void GoHome(); void Scroll(float dx, float dy, float x, float y) { scroll((int32_t)dx, (int32_t)dy, (int32_t)x, (int32_t)y); } diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index 1b9fb910d6e6..b567a622cb3a 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -270,6 +270,9 @@ void ServoControl::ChangeVisibility(bool visible) { void ServoControl::Stop() { RunOnGLThread([=] { mServo->Stop(); }); } +void ServoControl::GoHome() { + RunOnGLThread([=] { mServo->GoHome(); }); +} hstring ServoControl::LoadURIOrSearch(hstring input) { // Initial input is valid if (mServo->IsUriValid(input)) { @@ -306,9 +309,7 @@ void ServoControl::SendMediaSessionAction(int32_t action) { } void ServoControl::TryLoadUri(hstring input) { - if (!mLooping) { - mInitialURL = input; - } else { + if (mLooping) { RunOnGLThread([=] { if (!mServo->LoadUri(input)) { RunOnUIThread([=] { @@ -336,8 +337,8 @@ void ServoControl::Loop() { log(L"Entering loop"); ServoDelegate *sd = static_cast(this); EGLNativeWindowType win = GetNativeWindow(); - mServo = std::make_unique(mInitialURL, mArgs, mPanelWidth, - mPanelHeight, win, mDPI, *sd); + mServo = std::make_unique(mArgs, mPanelWidth, mPanelHeight, win, + mDPI, *sd); } else { // FIXME: this will fail since create_task didn't pick the thread // where Servo was running initially. diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h index 56d32e2a12cc..041f9f42f544 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -3,7 +3,6 @@ #include "Pref.g.h" #include "OpenGLES.h" #include "Servo.h" -#include "DefaultUrl.h" using namespace winrt::Windows::Foundation::Collections; @@ -49,6 +48,7 @@ struct ServoControl : ServoControlT, public servo::ServoDelegate { void ChangeVisibility(bool); void Shutdown(); hstring LoadURIOrSearch(hstring); + void GoHome(); void SendMediaSessionAction(int32_t); ServoApp::Pref SetBoolPref(hstring aKey, bool aVal) { @@ -214,7 +214,6 @@ struct ServoControl : ServoControlT, public servo::ServoDelegate { int mPanelHeight = 0; int mPanelWidth = 0; float mDPI = 1; - hstring mInitialURL = DEFAULT_URL; hstring mCurrentUrl = L""; bool mTransient = false; diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.idl b/support/hololens/ServoApp/ServoControl/ServoControl.idl index 72568edf3f88..33e7629170cf 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.idl +++ b/support/hololens/ServoApp/ServoControl/ServoControl.idl @@ -26,6 +26,7 @@ namespace ServoApp { void Reload(); void Stop(); String LoadURIOrSearch(String url); + void GoHome(); void SetTransientMode(Boolean transient); void SetArgs(String args); void Shutdown();