Wallpaper: support JSON format

This commit is contained in:
李通洲
2023-09-13 13:39:56 +08:00
parent 16b01a06e0
commit 9765885fe6
2 changed files with 14 additions and 1 deletions
+13 -1
View File
@@ -44,7 +44,7 @@ void ffPrintWallpaper(FFWallpaperOptions* options)
void ffInitWallpaperOptions(FFWallpaperOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, NULL);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, ffGenerateWallpaperJson);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -79,3 +79,15 @@ void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module)
ffPrintError(FF_WALLPAPER_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateWallpaperJson(FF_MAYBE_UNUSED FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_STRBUF_AUTO_DESTROY fullpath = ffStrbufCreate();
const char* error = ffDetectWallpaper(&fullpath);
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
}
yyjson_mut_obj_add_strbuf(doc, module, "result", &fullpath);
}
+1
View File
@@ -9,3 +9,4 @@ void ffInitWallpaperOptions(FFWallpaperOptions* options);
bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key, const char* value);
void ffDestroyWallpaperOptions(FFWallpaperOptions* options);
void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module);
void ffGenerateWallpaperJson(FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);