From ef79469863f8ca9c7ae8428c045478371b4b30c8 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:08:02 +0800 Subject: [PATCH] fix: template name init bug --- src/modules/template/controller.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/template/controller.ts b/src/modules/template/controller.ts index 52811be..c4f74ab 100644 --- a/src/modules/template/controller.ts +++ b/src/modules/template/controller.ts @@ -21,9 +21,14 @@ function initTemplates() { // Convert old template keys to new format const raw = getPref("templateKeys") as string; let keys = raw ? JSON.parse(raw) : []; - if (keys.length > 0 && typeof keys[0] !== "string") { - keys = keys.map((t: { name: string }) => t.name); - setTemplateKeys(keys); + if (keys.length > 0) { + keys = keys.map((t: { name: string } | string) => { + if (typeof t === "string") { + return t; + } + return t.name; + }); + setTemplateKeys(Array.from(new Set(keys))); } // Add default templates const templateKeys = getTemplateKeys();