1. Add default_file option in theme plugin

2. Add F5 Tools --> Theme Select menu to swith between themes
This commit is contained in:
longpanda 2021-11-16 19:32:23 +08:00
parent a4200ed99e
commit d938100eeb
5 changed files with 120 additions and 0 deletions

View File

@ -402,6 +402,7 @@ int g_menu_update_mode = 0;
int g_ventoy_tip_label_enable = 0; int g_ventoy_tip_label_enable = 0;
const char * g_ventoy_tip_msg1 = NULL; const char * g_ventoy_tip_msg1 = NULL;
const char * g_ventoy_tip_msg2 = NULL; const char * g_ventoy_tip_msg2 = NULL;
char g_ventoy_theme_path[256] = {0};
static const char *g_ventoy_cur_img_path = NULL; static const char *g_ventoy_cur_img_path = NULL;
static void menu_set_chosen_tip(grub_menu_t menu, int entry) static void menu_set_chosen_tip(grub_menu_t menu, int entry)
{ {
@ -410,9 +411,15 @@ static void menu_set_chosen_tip(grub_menu_t menu, int entry)
menu_tip *tip; menu_tip *tip;
grub_menu_entry_t e = grub_menu_get_entry (menu, entry); grub_menu_entry_t e = grub_menu_get_entry (menu, entry);
if (g_ventoy_theme_path[0])
{
grub_env_set("theme", g_ventoy_theme_path);
}
g_ventoy_tip_msg1 = g_ventoy_tip_msg2 = NULL; g_ventoy_tip_msg1 = g_ventoy_tip_msg2 = NULL;
if (e && e->id && grub_strncmp(e->id, "VID_", 4) == 0) if (e && e->id && grub_strncmp(e->id, "VID_", 4) == 0)
{ {
g_ventoy_theme_path[0] = 0;
img = (img_info *)(void *)grub_strtoul(e->id + 4, NULL, 16); img = (img_info *)(void *)grub_strtoul(e->id + 4, NULL, 16);
if (img) if (img)
{ {
@ -423,6 +430,7 @@ static void menu_set_chosen_tip(grub_menu_t menu, int entry)
} }
else if (e && e->id && grub_strncmp(e->id, "DIR_", 4) == 0) else if (e && e->id && grub_strncmp(e->id, "DIR_", 4) == 0)
{ {
g_ventoy_theme_path[0] = 0;
for (i = 0; i < e->argc; i++) for (i = 0; i < e->argc; i++)
{ {
if (e->args[i] && grub_strncmp(e->args[i], "_VTIP_", 6) == 0) if (e->args[i] && grub_strncmp(e->args[i], "_VTIP_", 6) == 0)

View File

@ -5268,6 +5268,8 @@ static cmd_para ventoy_cmds[] =
{ "vt_sel_wimboot", ventoy_cmd_sel_wimboot, 0, NULL, "", "", NULL }, { "vt_sel_wimboot", ventoy_cmd_sel_wimboot, 0, NULL, "", "", NULL },
{ "vt_set_wim_load_prompt", ventoy_cmd_set_wim_prompt, 0, NULL, "", "", NULL }, { "vt_set_wim_load_prompt", ventoy_cmd_set_wim_prompt, 0, NULL, "", "", NULL },
{ "vt_set_theme", ventoy_cmd_set_theme, 0, NULL, "", "", NULL }, { "vt_set_theme", ventoy_cmd_set_theme, 0, NULL, "", "", NULL },
{ "vt_set_theme_path", ventoy_cmd_set_theme_path, 0, NULL, "", "", NULL },
{ "vt_select_theme_cfg", ventoy_cmd_select_theme_cfg, 0, NULL, "", "", NULL },
{ "vt_get_efi_vdisk_offset", ventoy_cmd_get_efivdisk_offset, 0, NULL, "", "", NULL }, { "vt_get_efi_vdisk_offset", ventoy_cmd_get_efivdisk_offset, 0, NULL, "", "", NULL },
{ "vt_search_replace_initrd", ventoy_cmd_search_replace_initrd, 0, NULL, "", "", NULL }, { "vt_search_replace_initrd", ventoy_cmd_search_replace_initrd, 0, NULL, "", "", NULL },

View File

@ -1077,6 +1077,8 @@ int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, gr
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start); int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
void ventoy_plugin_dump_persistence(void); void ventoy_plugin_dump_persistence(void);
grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_set_theme_path(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);

View File

@ -57,6 +57,7 @@ static auto_memdisk *g_auto_memdisk_head = NULL;
static image_list *g_image_list_head = NULL; static image_list *g_image_list_head = NULL;
static conf_replace *g_conf_replace_head = NULL; static conf_replace *g_conf_replace_head = NULL;
static int g_theme_id = 0;
static int g_theme_num = 0; static int g_theme_num = 0;
static theme_list *g_theme_head = NULL; static theme_list *g_theme_head = NULL;
static int g_theme_random = vtoy_theme_random_boot_second; static int g_theme_random = vtoy_theme_random_boot_second;
@ -281,6 +282,7 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk)
static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk) static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
{ {
const char *value; const char *value;
char val[64];
char filepath[256]; char filepath[256];
VTOY_JSON *node = NULL; VTOY_JSON *node = NULL;
theme_list *tail = NULL; theme_list *tail = NULL;
@ -367,6 +369,18 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
} }
} }
grub_snprintf(val, sizeof(val), "%d", g_theme_num);
grub_env_set("VTOY_THEME_COUNT", val);
grub_env_export("VTOY_THEME_COUNT");
if (g_theme_num > 0)
{
vtoy_json_get_int(json->pstChild, "default_file", &g_theme_id);
if (g_theme_id > g_theme_num || g_theme_id < 0)
{
g_theme_id = 0;
}
}
value = vtoy_json_get_string_ex(json->pstChild, "gfxmode"); value = vtoy_json_get_string_ex(json->pstChild, "gfxmode");
if (value) if (value)
{ {
@ -3277,6 +3291,65 @@ end:
return 0; return 0;
} }
grub_err_t ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, char **args)
{
int pos = 0;
int bufsize = 0;
char *name = NULL;
char *buf = NULL;
theme_list *node = NULL;
(void)argc;
(void)args;
(void)ctxt;
if (g_theme_single_file[0])
{
return 0;
}
if (g_theme_num < 2)
{
return 0;
}
bufsize = (g_theme_num + 1) * 1024;
buf = grub_malloc(bufsize);
if (!buf)
{
return 0;
}
for (node = g_theme_head; node; node = node->next)
{
name = grub_strstr(node->theme.path, ")/");
if (name)
{
name++;
}
else
{
name = node->theme.path;
}
pos += grub_snprintf(buf + pos, bufsize - pos,
"menuentry \"%s\" --class=debug_theme_item --class=debug_theme_select --class=F5tool {\n"
"vt_set_theme_path \"%s\"\n"
"}\n",
name, node->theme.path);
}
pos += grub_snprintf(buf + pos, bufsize - pos,
"menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {\n"
"echo 'Return ...'\n"
"}\n");
grub_script_execute_sourcecode(buf);
grub_free(buf);
return 0;
}
grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args) grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args)
{ {
grub_uint32_t i = 0; grub_uint32_t i = 0;
@ -3302,6 +3375,17 @@ grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **arg
goto end; goto end;
} }
if (g_theme_id > 0 && g_theme_id <= g_theme_num)
{
for (i = 0; i < (grub_uint32_t)(g_theme_id - 1) && node; i++)
{
node = node->next;
}
grub_env_set("theme", node->theme.path);
goto end;
}
grub_memset(&datetime, 0, sizeof(datetime)); grub_memset(&datetime, 0, sizeof(datetime));
grub_get_datetime(&datetime); grub_get_datetime(&datetime);
@ -3332,7 +3416,25 @@ grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **arg
grub_env_set("theme", node->theme.path); grub_env_set("theme", node->theme.path);
end: end:
VENTOY_CMD_RETURN(GRUB_ERR_NONE); VENTOY_CMD_RETURN(GRUB_ERR_NONE);
} }
extern char g_ventoy_theme_path[256];
grub_err_t ventoy_cmd_set_theme_path(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)argc;
(void)ctxt;
if (argc == 0)
{
g_ventoy_theme_path[0] = 0;
}
else
{
grub_snprintf(g_ventoy_theme_path, sizeof(g_ventoy_theme_path), "%s", args[0]);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

View File

@ -38,6 +38,12 @@ submenu "Screen Display Mode" --class=debug_screen_mode --class=F5tool {
} }
} }
if [ $VTOY_THEME_COUNT -gt 1 ]; then
submenu "Theme Select" --class=debug_theme_select --class=F5tool {
vt_select_theme_cfg
}
fi
if [ "$grub_platform" != "pc" ]; then if [ "$grub_platform" != "pc" ]; then
submenu 'Ventoy UEFI Utilities' --class=debug_util --class=F5tool { submenu 'Ventoy UEFI Utilities' --class=debug_util --class=F5tool {
menuentry 'Show EFI Drivers' --class=debug_util_efidrv --class=debug_util --class=F5tool { menuentry 'Show EFI Drivers' --class=debug_util_efidrv --class=debug_util --class=F5tool {