mirror of https://gitlab.com/nakst/essence
move default settings into settings.cpp
This commit is contained in:
parent
5d4b2caeb4
commit
6d1039ad77
|
@ -898,9 +898,9 @@ void WriteNewConfiguration() {
|
|||
EsBuffer buffer = { .canGrow = true };
|
||||
|
||||
while (EsINIParse(&s)) {
|
||||
if (!s.sectionClassBytes && 0 == EsStringCompareRaw(s.section, s.sectionBytes, EsLiteral("ui"))
|
||||
&& 0 == EsStringCompareRaw(s.key, s.keyBytes, EsLiteral("font_sans"))) {
|
||||
EsBufferFormat(&buffer, "font_sans=%z\n", cSelectedFont);
|
||||
if (!s.sectionClassBytes && 0 == EsStringCompareRaw(s.section, s.sectionBytes, EsLiteral("ui_fonts"))
|
||||
&& 0 == EsStringCompareRaw(s.key, s.keyBytes, EsLiteral("sans"))) {
|
||||
EsBufferFormat(&buffer, "sans=%z\n", cSelectedFont);
|
||||
} else if (!s.sectionClassBytes && 0 == EsStringCompareRaw(s.section, s.sectionBytes, EsLiteral("general"))
|
||||
&& 0 == EsStringCompareRaw(s.key, s.keyBytes, EsLiteral("installation_state"))) {
|
||||
EsBufferFormat(&buffer, "installation_state=0\n");
|
||||
|
|
|
@ -426,9 +426,9 @@ void SystemConfigurationUnload() {
|
|||
api.systemConfigurationGroups.Free();
|
||||
}
|
||||
|
||||
void SystemConfigurationLoad(char *file, size_t fileBytes) {
|
||||
void SystemConfigurationLoad(const char *file, size_t fileBytes) {
|
||||
EsINIState s = {};
|
||||
s.buffer = file;
|
||||
s.buffer = (char *) file;
|
||||
s.bytes = fileBytes;
|
||||
|
||||
EsSystemConfigurationGroup *group = nullptr;
|
||||
|
@ -455,8 +455,6 @@ void SystemConfigurationLoad(char *file, size_t fileBytes) {
|
|||
group->itemCount++;
|
||||
}
|
||||
}
|
||||
|
||||
EsHeapFree(file);
|
||||
}
|
||||
|
||||
uint8_t *ApplicationStartupInformationToBuffer(const _EsApplicationStartupInformation *information, size_t *dataBytes = nullptr) {
|
||||
|
@ -1383,6 +1381,7 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) {
|
|||
void *file = EsFileReadAll(K_SYSTEM_CONFIGURATION, -1, &fileSize);
|
||||
EsAssert(file);
|
||||
SystemConfigurationLoad((char *) file, fileSize);
|
||||
EsHeapFree(file);
|
||||
|
||||
_EsNodeInformation node;
|
||||
char *path;
|
||||
|
@ -1392,6 +1391,7 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) {
|
|||
NodeAddMountPoint(EsLiteral("|Fonts:"), node.handle, false);
|
||||
EsHeapFree(path);
|
||||
|
||||
SettingsLoadDefaults();
|
||||
SettingsUpdateGlobalAndWindowManager();
|
||||
SettingsWindowColorUpdated();
|
||||
} else {
|
||||
|
@ -1428,6 +1428,7 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) {
|
|||
EsBuffer responseBuffer = { .canGrow = true };
|
||||
MessageDesktop(&m, 1, ES_INVALID_HANDLE, &responseBuffer);
|
||||
SystemConfigurationLoad((char *) responseBuffer.out, responseBuffer.bytes);
|
||||
EsHeapFree(responseBuffer.out);
|
||||
}
|
||||
|
||||
if (uiProcess) {
|
||||
|
|
|
@ -2568,7 +2568,7 @@ void DesktopSyscall(EsMessage *message, uint8_t *buffer, EsBuffer *pipe) {
|
|||
InstalledApplication *application = ApplicationFindByPID(message->desktop.processID);
|
||||
|
||||
ConfigurationWriteSectionsToBuffer("font", nullptr, false, pipe);
|
||||
ConfigurationWriteSectionsToBuffer(nullptr, "ui", false, pipe);
|
||||
ConfigurationWriteSectionsToBuffer(nullptr, "ui_fonts", false, pipe);
|
||||
|
||||
if (application && (application->permissions & APPLICATION_PERMISSION_ALL_FILES)) {
|
||||
ConfigurationWriteSectionsToBuffer(nullptr, "paths", false, pipe);
|
||||
|
|
|
@ -134,6 +134,67 @@ const EsStyle styleSliderRow = {
|
|||
},
|
||||
};
|
||||
|
||||
bool SettingsPutValue(const char *cConfigurationSection, const char *cConfigurationKey, char *newValue, size_t newValueBytes,
|
||||
char **oldValue, size_t *oldValueBytes, bool duplicate, bool overwriteExisting) {
|
||||
if (duplicate) {
|
||||
char *newValueDuplicate = (char *) EsHeapAllocate(newValueBytes, false);
|
||||
|
||||
if (!newValueDuplicate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EsMemoryCopy(newValueDuplicate, newValue, newValueBytes);
|
||||
newValue = newValueDuplicate;
|
||||
}
|
||||
|
||||
EsSystemConfigurationGroup *group = SystemConfigurationGetGroup(cConfigurationSection, -1, true);
|
||||
|
||||
if (!group) {
|
||||
EsHeapFree(newValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
EsSystemConfigurationItem *item = SystemConfigurationGetItem(group, cConfigurationKey, -1, true);
|
||||
|
||||
if (!item) {
|
||||
EsHeapFree(newValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (oldValue) {
|
||||
*oldValue = item->value;
|
||||
}
|
||||
|
||||
if (oldValueBytes) {
|
||||
*oldValueBytes = item->valueBytes;
|
||||
}
|
||||
|
||||
if (!overwriteExisting && item->valueBytes) {
|
||||
EsHeapFree(newValue);
|
||||
} else {
|
||||
if (!oldValue) {
|
||||
EsHeapFree(item->value);
|
||||
}
|
||||
|
||||
item->value = newValue;
|
||||
item->valueBytes = newValueBytes;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SettingsLoadDefaults() {
|
||||
SettingsPutValue("general", "click_chain_timeout_ms", EsLiteral("500"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "show_cursor_shadow", EsLiteral("1"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "scroll_lines_per_notch", EsLiteral("3"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "ui_scale", EsLiteral("100"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "window_color", EsLiteral("6"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "use_smart_quotes", EsLiteral("1"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "enable_hover_state", EsLiteral("1"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("general", "enable_animations", EsLiteral("1"), nullptr, nullptr, true, false);
|
||||
SettingsPutValue("paths", "default_user_documents", EsLiteral("0:/"), nullptr, nullptr, true, false);
|
||||
}
|
||||
|
||||
void SettingsUpdateGlobalAndWindowManager() {
|
||||
api.global->clickChainTimeoutMs = EsSystemConfigurationReadInteger(EsLiteral("general"), EsLiteral("click_chain_timeout_ms"));
|
||||
api.global->swapLeftAndRightButtons = EsSystemConfigurationReadInteger(EsLiteral("general"), EsLiteral("swap_left_and_right_buttons"));
|
||||
|
@ -196,18 +257,14 @@ void SettingsNumberBoxSetValue(EsElement *element, double newValueDouble) {
|
|||
|
||||
EsMutexAcquire(&api.systemConfigurationMutex);
|
||||
|
||||
EsSystemConfigurationGroup *group = SystemConfigurationGetGroup(control->cConfigurationSection, -1, true);
|
||||
char *value = (char *) EsHeapAllocate(65, true), *_oldValue;
|
||||
size_t valueBytes = EsStringFormat(value, 64, "%fd", ES_STRING_FORMAT_SIMPLE, newValue), _oldValueBytes;
|
||||
int32_t oldValue = 0;
|
||||
|
||||
if (group) {
|
||||
EsSystemConfigurationItem *item = SystemConfigurationGetItem(group, control->cConfigurationKey, -1, true);
|
||||
|
||||
if (item) {
|
||||
oldValue = EsIntegerParse(item->value, item->valueBytes);
|
||||
EsHeapFree(item->value);
|
||||
item->value = (char *) EsHeapAllocate(65, true);
|
||||
item->valueBytes = EsStringFormat(item->value, 64, "%fd", ES_STRING_FORMAT_SIMPLE, newValue);
|
||||
}
|
||||
if (SettingsPutValue(control->cConfigurationSection, control->cConfigurationKey, value, valueBytes,
|
||||
&_oldValue, &_oldValueBytes, false, true)) {
|
||||
oldValue = EsIntegerParse(_oldValue, _oldValueBytes);
|
||||
EsHeapFree(_oldValue);
|
||||
}
|
||||
|
||||
EsMutexRelease(&api.systemConfigurationMutex);
|
||||
|
@ -263,19 +320,15 @@ void SettingsCheckboxCommand(EsInstance *_instance, EsElement *element, EsComman
|
|||
|
||||
EsMutexAcquire(&api.systemConfigurationMutex);
|
||||
|
||||
EsSystemConfigurationGroup *group = SystemConfigurationGetGroup(control->cConfigurationSection, -1, true);
|
||||
char *value = (char *) EsHeapAllocate(2, true), *_oldValue;
|
||||
size_t _oldValueBytes;
|
||||
value[0] = newValue ? '1' : '0';
|
||||
bool oldValue = false;
|
||||
|
||||
if (group) {
|
||||
EsSystemConfigurationItem *item = SystemConfigurationGetItem(group, control->cConfigurationKey, -1, true);
|
||||
|
||||
if (item) {
|
||||
oldValue = EsIntegerParse(item->value, item->valueBytes);
|
||||
EsHeapFree(item->value);
|
||||
item->value = (char *) EsHeapAllocate(2, true);
|
||||
*item->value = newValue ? '1' : '0';
|
||||
item->valueBytes = 1;
|
||||
}
|
||||
if (SettingsPutValue(control->cConfigurationSection, control->cConfigurationKey, value, 1,
|
||||
&_oldValue, &_oldValueBytes, false, true)) {
|
||||
oldValue = EsIntegerParse(_oldValue, _oldValueBytes);
|
||||
EsHeapFree(_oldValue);
|
||||
}
|
||||
|
||||
EsMutexRelease(&api.systemConfigurationMutex);
|
||||
|
@ -389,19 +442,15 @@ int SettingsSliderMessage(EsElement *element, EsMessage *message) {
|
|||
if (message->type == ES_MSG_SLIDER_MOVED && !message->sliderMoved.inDrag) {
|
||||
EsMutexAcquire(&api.systemConfigurationMutex);
|
||||
|
||||
EsSystemConfigurationGroup *group = SystemConfigurationGetGroup(control->cConfigurationSection, -1, true);
|
||||
int32_t oldValue = 0;
|
||||
int32_t newValue = LinearMap(0, 1, control->minimumValue, control->maximumValue, EsSliderGetValue(slider));
|
||||
char *value = (char *) EsHeapAllocate(65, true), *_oldValue;
|
||||
size_t valueBytes = EsStringFormat(value, 64, "%fd", ES_STRING_FORMAT_SIMPLE, newValue), _oldValueBytes;
|
||||
int32_t oldValue = 0;
|
||||
|
||||
if (group) {
|
||||
EsSystemConfigurationItem *item = SystemConfigurationGetItem(group, control->cConfigurationKey, -1, true);
|
||||
|
||||
if (item) {
|
||||
oldValue = EsIntegerParse(item->value, item->valueBytes);
|
||||
EsHeapFree(item->value);
|
||||
item->value = (char *) EsHeapAllocate(65, true);
|
||||
item->valueBytes = EsStringFormat(item->value, 64, "%fd", ES_STRING_FORMAT_SIMPLE, newValue);
|
||||
}
|
||||
if (SettingsPutValue(control->cConfigurationSection, control->cConfigurationKey, value, valueBytes,
|
||||
&_oldValue, &_oldValueBytes, false, true)) {
|
||||
oldValue = EsIntegerParse(_oldValue, _oldValueBytes);
|
||||
EsHeapFree(_oldValue);
|
||||
}
|
||||
|
||||
EsMutexRelease(&api.systemConfigurationMutex);
|
||||
|
@ -623,18 +672,9 @@ void SettingsColorButtonCommand(EsInstance *, EsElement *element, EsCommand *) {
|
|||
}
|
||||
|
||||
EsMutexAcquire(&api.systemConfigurationMutex);
|
||||
EsSystemConfigurationGroup *group = SystemConfigurationGetGroup("general", -1, true);
|
||||
|
||||
if (group) {
|
||||
EsSystemConfigurationItem *item = SystemConfigurationGetItem(group, "window_color", -1, true);
|
||||
|
||||
if (item) {
|
||||
EsHeapFree(item->value);
|
||||
item->value = (char *) EsHeapAllocate(65, true);
|
||||
item->valueBytes = EsStringFormat(item->value, 64, "%fd", ES_STRING_FORMAT_SIMPLE, element->userData.u);
|
||||
}
|
||||
}
|
||||
|
||||
char *value = (char *) EsHeapAllocate(65, true);
|
||||
size_t valueBytes = EsStringFormat(value, 64, "%fd", ES_STRING_FORMAT_SIMPLE, element->userData.u);
|
||||
SettingsPutValue("general", "window_color", value, valueBytes, nullptr, nullptr, false, true);
|
||||
EsMutexRelease(&api.systemConfigurationMutex);
|
||||
SettingsWindowColorUpdated();
|
||||
desktop.configurationModified = true;
|
||||
|
@ -665,19 +705,16 @@ void SettingsPageTheme(EsElement *element, SettingsPage *page) {
|
|||
if (message->type == ES_MSG_TEXTBOX_EDIT_END) {
|
||||
EsMutexAcquire(&api.systemConfigurationMutex);
|
||||
|
||||
EsSystemConfigurationGroup *group = SystemConfigurationGetGroup("general", -1, true);
|
||||
size_t newValueBytes;
|
||||
char *newValue = EsTextboxGetContents((EsTextbox *) element, &newValueBytes);
|
||||
|
||||
if (group) {
|
||||
EsSystemConfigurationItem *item = SystemConfigurationGetItem(group, "wallpaper", -1, true);
|
||||
|
||||
if (item) {
|
||||
EsHeapFree(item->value);
|
||||
item->value = EsTextboxGetContents((EsTextbox *) element, &item->valueBytes);
|
||||
desktop.configurationModified = true;
|
||||
EsThreadCreate(WallpaperLoad, nullptr, 0);
|
||||
}
|
||||
if (newValue) {
|
||||
SettingsPutValue("general", "wallpaper", newValue, newValueBytes, nullptr, nullptr, false, true);
|
||||
}
|
||||
|
||||
desktop.configurationModified = true;
|
||||
EsThreadCreate(WallpaperLoad, nullptr, 0);
|
||||
|
||||
EsMutexRelease(&api.systemConfigurationMutex);
|
||||
return ES_HANDLED;
|
||||
}
|
||||
|
|
|
@ -453,10 +453,10 @@ void FontInitialise() {
|
|||
return;
|
||||
}
|
||||
|
||||
fontManagement.sansName = EsSystemConfigurationReadString(EsLiteral("ui"), EsLiteral("font_sans"));
|
||||
fontManagement.serifName = EsSystemConfigurationReadString(EsLiteral("ui"), EsLiteral("font_serif"));
|
||||
fontManagement.monospacedName = EsSystemConfigurationReadString(EsLiteral("ui"), EsLiteral("font_mono"));
|
||||
fontManagement.fallbackName = EsSystemConfigurationReadString(EsLiteral("ui"), EsLiteral("font_fallback"));
|
||||
fontManagement.sansName = EsSystemConfigurationReadString(EsLiteral("ui_fonts"), EsLiteral("sans"));
|
||||
fontManagement.serifName = EsSystemConfigurationReadString(EsLiteral("ui_fonts"), EsLiteral("serif"));
|
||||
fontManagement.monospacedName = EsSystemConfigurationReadString(EsLiteral("ui_fonts"), EsLiteral("mono"));
|
||||
fontManagement.fallbackName = EsSystemConfigurationReadString(EsLiteral("ui_fonts"), EsLiteral("fallback"));
|
||||
|
||||
FontDatabaseEntry nullFont = {};
|
||||
fontManagement.database.Add(nullFont);
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
[general]
|
||||
click_chain_timeout_ms=500
|
||||
show_cursor_shadow=1
|
||||
scroll_lines_per_notch=3
|
||||
ui_scale=100
|
||||
window_color=6
|
||||
use_smart_quotes=1
|
||||
enable_hover_state=1
|
||||
enable_animations=1
|
||||
|
||||
[ui]
|
||||
font_fallback=Inter
|
||||
font_sans=Inter
|
||||
font_serif=Inter
|
||||
font_mono=Hack
|
Binary file not shown.
Binary file not shown.
|
@ -773,32 +773,25 @@ void ParseApplicationManifest(const char *manifestPath) {
|
|||
}
|
||||
|
||||
void OutputSystemConfiguration() {
|
||||
EsINIState s = {};
|
||||
char *config = (char *) LoadFile("res/System Configuration Template.ini", &s.bytes);
|
||||
s.buffer = config;
|
||||
File file = FileOpen("root/" SYSTEM_FOLDER_NAME "/Default.ini", 'w');
|
||||
|
||||
while (EsINIParse(&s)) {
|
||||
EsINIZeroTerminate(&s);
|
||||
FilePrintFormat(file, "\n[paths]\n"
|
||||
"fonts=0:/" SYSTEM_FOLDER_NAME "/Fonts\n"
|
||||
"temporary=0:/" SYSTEM_FOLDER_NAME "/Temporary\n"
|
||||
"default_settings=0:/" SYSTEM_FOLDER_NAME "/Settings\n"
|
||||
"\n[ui_fonts]\n"
|
||||
"fallback=Inter\n"
|
||||
"sans=Inter\n"
|
||||
"serif=Inter\n"
|
||||
"mono=Hack\n");
|
||||
|
||||
FilePrintFormat(file, "\n[general]\nnext_id=%d\n", nextID);
|
||||
|
||||
for (uintptr_t i = 0; i < arrlenu(generalOptions); i++) {
|
||||
char buffer[4096];
|
||||
FileWrite(file, EsINIFormat(&s, buffer, sizeof(buffer)), buffer);
|
||||
|
||||
if (0 == strcmp(s.section, "general") && (!EsINIPeek(&s) || !s.keyBytes)) {
|
||||
FilePrintFormat(file, "next_id=%d\n", nextID);
|
||||
|
||||
for (uintptr_t i = 0; i < arrlenu(generalOptions); i++) {
|
||||
FileWrite(file, EsINIFormat(generalOptions + i, buffer, sizeof(buffer)), buffer);
|
||||
}
|
||||
}
|
||||
FileWrite(file, EsINIFormat(generalOptions + i, buffer, sizeof(buffer)), buffer);
|
||||
}
|
||||
|
||||
FilePrintFormat(file, "\n[paths]\n");
|
||||
FilePrintFormat(file, "fonts=0:/" SYSTEM_FOLDER_NAME "/Fonts\n");
|
||||
FilePrintFormat(file, "temporary=0:/" SYSTEM_FOLDER_NAME "/Temporary\n");
|
||||
FilePrintFormat(file, "default_settings=0:/" SYSTEM_FOLDER_NAME "/Settings\n");
|
||||
FilePrintFormat(file, "default_user_documents=0:/\n");
|
||||
|
||||
for (uintptr_t i = 0; i < arrlenu(applications); i++) {
|
||||
if (!applications[i].install) {
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue