diff --git a/common/menu.c b/common/menu.c index cd3d8ed..b762cdf 100644 --- a/common/menu.c +++ b/common/menu.c @@ -55,25 +55,7 @@ void launchMenuBackTask() { } void launchApplyThemeTask(menuEntry_s* arg) { - config_t cfg = {0}; - config_init(&cfg); - - if(!config_read_file(&cfg, arg->path)) { - menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be loaded!"); - return; - } - - char tmp_path[PATH_MAX] = {0}; - #ifdef __SWITCH__ - tmp_path[0] = '/'; - #endif - - strncat(tmp_path, "config/nx-hbmenu/theme.cfg", sizeof(tmp_path)-2); - if(!config_write_file(&cfg, tmp_path)) { - menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!"); - return; - } - config_destroy(&cfg); + //SetThemePathToConfig(arg->path); themeStartup(themeGlobalPreset); computeFrontGradient(themeCurrent.frontWaveColor, 280); } diff --git a/common/theme.c b/common/theme.c index a932fb5..df4c837 100644 --- a/common/theme.c +++ b/common/theme.c @@ -54,17 +54,13 @@ void themeStartup(ThemePreset preset) { .hbmenuLogoImage = hbmenu_logo_dark_bin }; - char tmp_path[PATH_MAX] = {0}; - - #ifdef __SWITCH__ - tmp_path[0] = '/'; - #endif + config_t themeCfg = {0}; + config_setting_t *setting; + config_init(&themeCfg); const char* themePath = ""; - config_t thmPthCfg = {0}; - config_init(&thmPthCfg); - GetThemePathFromConfig(thmPthCfg, themePath); - strncat(tmp_path, "config/nx-hbmenu/theme.cfg", sizeof(tmp_path)-2); + //GetThemePathFromConfig(themeCfg, setting, themePath); + theme_t *themeDefault; config_t cfg = {0}; config_init(&cfg); @@ -72,8 +68,9 @@ void themeStartup(ThemePreset preset) { color_t text, frontWave, middleWave, backWave, background, highlight, separator, borderColor, borderTextColor; int waveBlending; const char *AText, *BText; - bool good_cfg = config_read_file(&cfg, tmp_path); - + bool good_cfg = config_read_file(&cfg, themePath); + config_destroy(&themeCfg); + switch (preset) { case THEME_PRESET_LIGHT: default: @@ -141,18 +138,42 @@ void themeStartup(ThemePreset preset) { config_destroy(&cfg); } - -void GetThemePathFromConfig(config_t cfg, const char* path){ +void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath) { char tmp_path[PATH_MAX] = {0}; - config_setting_t *setting; #ifdef __SWITCH__ tmp_path[0] = '/'; #endif + strncat(tmp_path, "config/nx-hbmenu/setting.cfg", sizeof(tmp_path)-2); bool good_cfg = config_read_file(&cfg, tmp_path); if(good_cfg) { - config_setting_lookup_string(theme, "themePath", &path); - } + setting = config_lookup(&cfg, "themePath"); + config_setting_lookup_string(setting, "themePath", &themePath); + } +} + +void SetThemePathToConfig(const char* themePath) { + config_t cfg = {0}; + config_init(&cfg); + + char tmp_path[PATH_MAX] = {0}; + config_setting_t *root,*group, *setting; + + #ifdef __SWITCH__ + tmp_path[0] = '/'; + #endif + + strncat(tmp_path, "config/nx-hbmenu/setting.cfg", sizeof(tmp_path)-2); + root = config_root_setting(&cfg); + group = config_setting_add(root, "hbmenuConfig", CONFIG_TYPE_GROUP); + setting = config_setting_add(group, "themePath", CONFIG_TYPE_STRING); + config_setting_set_string(setting, themePath); + + if(!config_write_file(&cfg, tmp_path)) { + menuCreateMsgBox(780, 300, "Something went wrong, and the theme could not be applied!"); + } + + config_destroy(&cfg); } \ No newline at end of file diff --git a/common/theme.h b/common/theme.h index abdcfd4..b95a419 100644 --- a/common/theme.h +++ b/common/theme.h @@ -29,8 +29,9 @@ typedef enum } ThemePreset; bool colorFromSetting(config_setting_t *rgba, color_t *col); - void themeStartup(ThemePreset preset); +void GetThemePathFromConfig(config_t cfg, config_setting_t *setting, const char* themePath); +void SetThemePathToConfig(const char* themePath); extern theme_t themeCurrent;