Skip to content

Commit

Permalink
Fix DEFAULT_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Jun 29, 2020
1 parent 345238a commit 2ef6ba2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 37 deletions.
3 changes: 1 addition & 2 deletions support/hololens/ServoApp/BrowserPage.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion support/hololens/ServoApp/DefaultUrl.h
@@ -1,3 +1,8 @@
#pragma once

#define DEFAULT_URL L"https://servo.org/hl-home/"
#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,<input>"
// #define OVERRIDE_DEFAULT_URL "http://localhost:8000/test.html"
64 changes: 39 additions & 25 deletions support/hololens/ServoApp/ServoControl/Servo.cpp
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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")) {
Expand All @@ -151,35 +151,42 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
std::vector<capi::CPref> cprefs;

for (auto pref : prefs.Values()) {

auto key = *hstring2char(pref.Key());
auto value = pref.Value();

auto type = value.as<Windows::Foundation::IPropertyValue>().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<bool>(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<hstring>(value));
cpref.pref_type = capi::CPrefType::Str;
cpref.value = *hstring2char(unbox_value<hstring>(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<int64_t>(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<double>(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()};
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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<hstring>(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) {
Expand Down
4 changes: 2 additions & 2 deletions support/hololens/ServoApp/ServoControl/Servo.h
Expand Up @@ -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; }

Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions support/hololens/ServoApp/ServoControl/ServoControl.cpp
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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([=] {
Expand Down Expand Up @@ -336,8 +337,8 @@ void ServoControl::Loop() {
log(L"Entering loop");
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
EGLNativeWindowType win = GetNativeWindow();
mServo = std::make_unique<Servo>(mInitialURL, mArgs, mPanelWidth,
mPanelHeight, win, mDPI, *sd);
mServo = std::make_unique<Servo>(mArgs, mPanelWidth, mPanelHeight, win,
mDPI, *sd);
} else {
// FIXME: this will fail since create_task didn't pick the thread
// where Servo was running initially.
Expand Down
3 changes: 1 addition & 2 deletions support/hololens/ServoApp/ServoControl/ServoControl.h
Expand Up @@ -3,7 +3,6 @@
#include "Pref.g.h"
#include "OpenGLES.h"
#include "Servo.h"
#include "DefaultUrl.h"

using namespace winrt::Windows::Foundation::Collections;

Expand Down Expand Up @@ -49,6 +48,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
void ChangeVisibility(bool);
void Shutdown();
hstring LoadURIOrSearch(hstring);
void GoHome();
void SendMediaSessionAction(int32_t);

ServoApp::Pref SetBoolPref(hstring aKey, bool aVal) {
Expand Down Expand Up @@ -214,7 +214,6 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
int mPanelHeight = 0;
int mPanelWidth = 0;
float mDPI = 1;
hstring mInitialURL = DEFAULT_URL;
hstring mCurrentUrl = L"";
bool mTransient = false;

Expand Down
1 change: 1 addition & 0 deletions support/hololens/ServoApp/ServoControl/ServoControl.idl
Expand Up @@ -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();
Expand Down

0 comments on commit 2ef6ba2

Please sign in to comment.