fix(prefs): Use strings for ui_defaults values

Previously we converted some ui_defaults values to booleans.
Unfortunately, when we save similar preferences to LocalStorage, we can
only save them as strings. To make sure code doesn't get booleans when
it's expecting everything to be a string, let's only send strings back
in our ui_defaults json

A nice followup to this might be to continue standardizing ui_defaults
transformation code on the server side so that its use is minimal (e.g.
uiMode, uiTheme variables), however an overhaul of server-side
ui_defaults was deemed to risky for now

Signed-off-by: Skyler Grey <skyler.grey@collabora.com>
Change-Id: I35ce175bf38da40361efd6f246264d0733e975e9
This commit is contained in:
Skyler Grey 2024-06-06 12:47:34 +00:00 committed by Skyler Grey
parent f93a9ee086
commit f9c3447061
3 changed files with 16 additions and 12 deletions

View file

@ -59,22 +59,22 @@ void FileServeTests::testUIDefaults()
LOK_ASSERT_EQUAL(std::string("classic"), uiMode);
LOK_ASSERT_EQUAL(
std::string("{\"spreadsheet\":{\"ShowSidebar\":false},\"text\":{\"ShowRuler\":true}}"),
std::string("{\"spreadsheet\":{\"ShowSidebar\":\"false\"},\"text\":{\"ShowRuler\":\"true\"}}"),
FileServerRequestHandler::uiDefaultsToJSON("TextRuler=true;SpreadsheetSidebar=false",
uiMode, uiTheme, savedUIState));
LOK_ASSERT_EQUAL(std::string(""), uiMode);
LOK_ASSERT_EQUAL(
std::string("{\"presentation\":{\"ShowStatusbar\":false},\"spreadsheet\":{\"ShowSidebar\":"
"false},\"text\":{\"ShowRuler\":true},\"uiMode\":\"notebookbar\"}"),
std::string("{\"presentation\":{\"ShowStatusbar\":\"false\"},\"spreadsheet\":{\"ShowSidebar\":"
"\"false\"},\"text\":{\"ShowRuler\":\"true\"},\"uiMode\":\"notebookbar\"}"),
FileServerRequestHandler::uiDefaultsToJSON(
";;UIMode=notebookbar;;PresentationStatusbar=false;;TextRuler=true;;bah=ugh;;"
"SpreadsheetSidebar=false",
uiMode, uiTheme, savedUIState));
LOK_ASSERT_EQUAL(std::string("{\"drawing\":{\"ShowStatusbar\":true},\"presentation\":{"
"\"ShowStatusbar\":false},\"spreadsheet\":{\"ShowSidebar\":false},"
"\"text\":{\"ShowRuler\":true},\"uiMode\":\"notebookbar\"}"),
LOK_ASSERT_EQUAL(std::string("{\"drawing\":{\"ShowStatusbar\":\"true\"},\"presentation\":{"
"\"ShowStatusbar\":\"false\"},\"spreadsheet\":{\"ShowSidebar\":\"false\"},"
"\"text\":{\"ShowRuler\":\"true\"},\"uiMode\":\"notebookbar\"}"),
FileServerRequestHandler::uiDefaultsToJSON(
";;UIMode=notebookbar;;PresentationStatusbar=false;;TextRuler=true;;bah="
"ugh;;SpreadsheetSidebar=false;;DrawingStatusbar=true",

View file

@ -239,7 +239,7 @@ void HTTPServerTest::testCoolPost()
std::string::npos);
LOK_ASSERT(
html.find(
R"xx(window.uiDefaults = {"presentation":{"ShowSidebar":false,"ShowStatusbar":false},"spreadsheet":{"ShowSidebar":false,"ShowStatusbar":false},"text":{"ShowRuler":false,"ShowSidebar":false,"ShowStatusbar":false},"uiMode":"classic"};)xx") !=
R"xx(window.uiDefaults = {"presentation":{"ShowSidebar":"false","ShowStatusbar":"false"},"spreadsheet":{"ShowSidebar":"false","ShowStatusbar":"false"},"text":{"ShowRuler":"false","ShowSidebar":"false","ShowStatusbar":"false"},"uiMode":"classic"};)xx") !=
std::string::npos);
LOK_ASSERT(
html.find(

View file

@ -233,7 +233,11 @@ std::string FileServerRequestHandler::uiDefaultsToJSON(const std::string& uiDefa
// detect the UITheme default, light or dark
if (keyValue.equals(0, "UITheme"))
{
json.set("darkTheme", keyValue.equals(1, "dark"));
if (keyValue.equals(1, "dark")) {
json.set("darkTheme", "true");
} else {
json.set("darkTheme", "false");
}
uiTheme = keyValue[1];
continue;
}
@ -262,12 +266,12 @@ std::string FileServerRequestHandler::uiDefaultsToJSON(const std::string& uiDefa
}
if (keyValue.equals(0, "TouchscreenHint"))
{
json.set("touchscreenHint", keyValue.equals(1, "true"));
json.set("touchscreenHint", keyValue[1]);
continue;
}
if (keyValue.equals(0, "OnscreenKeyboardHint"))
{
json.set("onscreenKeyboardHint", keyValue.equals(1, "true"));
json.set("onscreenKeyboardHint", keyValue[1]);
continue;
}
else if (keyValue.startsWith(0, "Text"))
@ -301,9 +305,9 @@ std::string FileServerRequestHandler::uiDefaultsToJSON(const std::string& uiDefa
// detect the actual UI widget we want to hide or show
if (key == "Ruler" || key == "Sidebar" || key == "Statusbar" || key == "Toolbar")
{
bool value(true);
std::string value("true");
if (keyValue.equals(1, "false") || keyValue.equals(1, "False") || keyValue.equals(1, "0"))
value = false;
value = "false";
currentDef->set("Show" + key, value);
}