Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(desktop/main.cc): check for invalid values for the application window sizes #523

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 39 additions & 13 deletions src/desktop/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ MAIN {
}

auto screen = currentWindow->getScreenSize();

options.width = message.get("width").size() ? currentWindow->getSizeInPixels(message.get("width"), screen.width) : 0;
options.height = message.get("height").size() ? currentWindow->getSizeInPixels(message.get("height"), screen.height) : 0;

Expand Down Expand Up @@ -953,20 +953,46 @@ MAIN {

app.onExit = shutdownHandler;

String defaultWidth = app.appData["window_width"].size() > 0 ? app.appData["window_width"] : "100%";
String defaultHeight = app.appData["window_height"].size() > 0 ? app.appData["window_height"] : "100%";
String defaultMinWidth = app.appData["window_min_width"].size() > 0 ? app.appData["window_min_width"] : "0";
String defaultMinHeight = app.appData["window_min_height"].size() > 0 ? app.appData["window_min_height"] : "0";
String defaultMaxWidth = app.appData["window_max_width"].size() > 0 ? app.appData["window_max_width"] : "100%";
String defaultMaxHeight = app.appData["window_max_height"].size() > 0 ? app.appData["window_max_height"] : "100%";
Vector<String> properties = {
"window_width", "window_height",
"window_min_width", "window_min_height",
"window_max_width", "window_max_height"
};

auto setDefaultValue = [&](String property) {
// for min values set 0
if (property.find("min") != -1) {
return "0";
// for other values set 100%
} else {
return "100%";
}
};

// Regular expression to match a float number or a percentage
std::regex validPattern("^\\d*\\.?\\d+%?$");

for (const auto& property : properties) {
if (app.appData[property].size() > 0) {
auto value = app.appData[property];
if (!std::regex_match(value, validPattern)) {
stdWrite("Invalid value for " + property + ": " + value, true);
app.appData[property] = setDefaultValue(property);
stdWrite("Setting default value: " + app.appData[property], true);
Comment on lines +979 to +981
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these stdWrites don't work

}
// set default value if it's not set in socket.ini
} else {
app.appData[property] = setDefaultValue(property);
}
}

windowManager.configure(WindowManagerOptions {
.defaultHeight = defaultHeight,
.defaultWidth = defaultWidth,
.defaultMinWidth = defaultMinWidth,
.defaultMinHeight = defaultMinHeight,
.defaultMaxWidth = defaultMaxWidth,
.defaultMaxHeight = defaultMaxHeight,
.defaultHeight = app.appData["window_height"],
.defaultWidth = app.appData["window_width"],
.defaultMinWidth = app.appData["window_min_width"],
.defaultMinHeight = app.appData["window_min_height"],
.defaultMaxWidth = app.appData["window_max_width"],
.defaultMaxHeight = app.appData["window_max_height"],
.headless = isHeadless,
.isTest = isTest,
.argv = argvArray.str(),
Expand Down