diff options
author | Paul Rouget <me@paulrouget.com> | 2020-07-06 11:49:13 +0200 |
---|---|---|
committer | Paul Rouget <me@paulrouget.com> | 2020-07-06 11:49:13 +0200 |
commit | 79ecc7e216c2fee9e9b9ac99a04830509f55ddb9 (patch) | |
tree | 92e30502943414d5f427c24881da1769c45861d2 | |
parent | d93e67a0bf95ef6c68ccba5a37ebf19301476038 (diff) | |
download | servo-79ecc7e216c2fee9e9b9ac99a04830509f55ddb9.tar.gz servo-79ecc7e216c2fee9e9b9ac99a04830509f55ddb9.zip |
UWP: allow servo's initial URL to be set before Servo starts
-rw-r--r-- | support/hololens/ServoApp/DefaultUrl.h | 4 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/Servo.cpp | 25 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/Servo.h | 3 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.cpp | 6 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.h | 1 |
5 files changed, 26 insertions, 13 deletions
diff --git a/support/hololens/ServoApp/DefaultUrl.h b/support/hololens/ServoApp/DefaultUrl.h index ee17a9f0286..b5d82e65478 100644 --- a/support/hololens/ServoApp/DefaultUrl.h +++ b/support/hololens/ServoApp/DefaultUrl.h @@ -4,5 +4,5 @@ // For development purpose. // Will override DEFAULT_URL_PROD or any locally stored preferences. -// #define OVERRIDE_DEFAULT_URL "data:text/html,<input>" -// #define OVERRIDE_DEFAULT_URL "http://localhost:8000/test.html" +// #define OVERRIDE_DEFAULT_URL L"data:text/html,<input>" +// #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 d0711fc259e..6f724d4bcbb 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -134,8 +134,8 @@ const char *prompt_input(const char *message, const char *default, } } -Servo::Servo(hstring args, GLsizei width, GLsizei height, - EGLNativeWindowType eglNativeWindow, float dpi, +Servo::Servo(std::optional<hstring> initUrl, hstring args, GLsizei width, + GLsizei height, EGLNativeWindowType eglNativeWindow, float dpi, ServoDelegate &aDelegate) : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { ApplicationDataContainer localSettings = @@ -172,13 +172,22 @@ Servo::Servo(hstring args, GLsizei width, GLsizei height, auto val = unbox_value<bool>(value); cpref.value = &val; } else if (type == Windows::Foundation::PropertyType::String) { - cpref.pref_type = capi::CPrefType::Str; - cpref.value = *hstring2char(unbox_value<hstring>(value)); -#ifdef OVERRIDE_DEFAULT_URL + hstring strValue; if (pref.Key() == L"shell.homepage") { - cpref.value = OVERRIDE_DEFAULT_URL; - } + if (initUrl.has_value()) { + strValue = *initUrl; + } else { +#ifdef OVERRIDE_DEFAULT_URL + strValue = OVERRIDE_DEFAULT_URL; +#else + strValue = unbox_value<hstring>(value); #endif + } + } else { + strValue = unbox_value<hstring>(value); + } + cpref.pref_type = capi::CPrefType::Str; + cpref.value = *hstring2char(strValue); } else if (type == Windows::Foundation::PropertyType::Int64) { cpref.pref_type = capi::CPrefType::Int; auto val = unbox_value<int64_t>(value); @@ -200,7 +209,7 @@ Servo::Servo(hstring args, GLsizei width, GLsizei height, capi::CInitOptions o; o.prefs = &prefsList; - o.args = *hstring2char(args + L"--devtools"); + o.args = *hstring2char(args + L" --devtools"); o.width = mWindowWidth; o.height = mWindowHeight; o.density = dpi; diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h index d609763605e..2be93581b22 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.h +++ b/support/hololens/ServoApp/ServoControl/Servo.h @@ -26,7 +26,8 @@ class ServoDelegate; class Servo { public: - Servo(hstring, GLsizei, GLsizei, EGLNativeWindowType, float, ServoDelegate &); + Servo(std::optional<hstring>, hstring, GLsizei, GLsizei, EGLNativeWindowType, + float, ServoDelegate &); ~Servo(); ServoDelegate &Delegate() { return mDelegate; } diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index 7e7861c2652..f83aef32941 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -379,6 +379,8 @@ void ServoControl::TryLoadUri(hstring input) { }); } }); + } else { + mInitUrl = input; } } @@ -398,8 +400,8 @@ void ServoControl::Loop() { log(L"Entering loop"); ServoDelegate *sd = static_cast<ServoDelegate *>(this); EGLNativeWindowType win = GetNativeWindow(); - mServo = std::make_unique<Servo>(mArgs, mPanelWidth, mPanelHeight, win, - mDPI, *sd); + mServo = std::make_unique<Servo>(mInitUrl, 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 52d4d80ddf0..bf53f0e6487 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -217,6 +217,7 @@ private: float mDPI = 1; hstring mCurrentUrl = L""; bool mTransient = false; + std::optional<hstring> mInitUrl = {}; Windows::UI::Xaml::Controls::SwapChainPanel ServoControl::Panel(); void CreateNativeWindow(); |