diff scid/theme.c @ 46:16f1c72d1635

scid: simplify theme code
author David Demelier <markand@malikania.fr>
date Mon, 15 Aug 2022 17:57:34 +0200
parents 576f4b1ec79f
children 070d8c92ca30
line wrap: on
line diff
--- a/scid/theme.c	Thu Aug 11 21:24:50 2022 +0200
+++ b/scid/theme.c	Mon Aug 15 17:57:34 2022 +0200
@@ -302,15 +302,15 @@
 	case JSON_FALSE:
 		duk_push_false(ctx);
 		break;
-	case JSON_NULL:
-		duk_push_null(ctx);
-		break;
 	case JSON_OBJECT:
 		push_object(ctx, val);
 		break;
 	case JSON_ARRAY:
 		push_array(ctx, val);
 		break;
+	default:
+		duk_push_null(ctx);
+		break;
 	}
 }
 
@@ -416,40 +416,24 @@
 }
 
 char *
-theme_page_index(json_t *json)
+theme_render(const char *function, json_t *json)
 {
-	assert(json);
-
-	return call(json, "onPageIndex");
-}
+	assert(function);
 
-char *
-theme_page_jobresults(json_t *json)
-{
-	assert(json);
-
-	return call(json, "onPageJobresults");
+	return call(json, function);
 }
 
 char *
-theme_page_status(int status, const char *message)
+theme_status(int status, const char *message)
 {
-	json_t *doc;
-	char *ret;
-
-	doc = util_json_pack("{si ss}",
+	return theme_render("onPageStatus", util_json_pack("{si ss}",
 		"status",  status,
 		"message", message
-	);
-	ret = call(doc, "onPageStatus");
-
-	json_decref(doc);
-
-	return ret;
+	));
 }
 
 void
-theme_free(void)
+theme_finish(void)
 {
 	duk_destroy_heap(context);
 }