mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
UWP: rely more on servo preferences
This commit is contained in:
parent
2c36754bf7
commit
9174b201b0
4 changed files with 29 additions and 27 deletions
|
@ -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,<input>"
|
||||
// #define OVERRIDE_DEFAULT_URL L"http://localhost:8000/test.html"
|
||||
|
|
|
@ -147,14 +147,6 @@ Servo::Servo(std::optional<hstring> 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<capi::CPref> cprefs;
|
||||
|
||||
for (auto pref : prefs.Values()) {
|
||||
|
@ -172,22 +164,9 @@ Servo::Servo(std::optional<hstring> initUrl, hstring args, GLsizei width,
|
|||
auto val = unbox_value<bool>(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<hstring>(value);
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
strValue = unbox_value<hstring>(value);
|
||||
}
|
||||
cpref.pref_type = capi::CPrefType::Str;
|
||||
cpref.value = *hstring2char(strValue);
|
||||
auto val = unbox_value<hstring>(value);
|
||||
cpref.value = *hstring2char(val);
|
||||
} else if (type == Windows::Foundation::PropertyType::Int64) {
|
||||
cpref.pref_type = capi::CPrefType::Int;
|
||||
auto val = unbox_value<int64_t>(value);
|
||||
|
@ -205,11 +184,19 @@ Servo::Servo(std::optional<hstring> 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::PrefTuple> Servo::GetPrefs() {
|
|||
return vec;
|
||||
}
|
||||
|
||||
void setNonPersistentHomepage(hstring url, std::vector<capi::CPref> &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);
|
||||
|
|
|
@ -21,6 +21,7 @@ using namespace capi;
|
|||
|
||||
hstring char2hstring(const char *);
|
||||
std::unique_ptr<char *> hstring2char(hstring);
|
||||
void setNonPersistentHomepage(hstring, std::vector<capi::CPref> &);
|
||||
|
||||
class ServoDelegate;
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue