From efafc31c9b52b0a306736fdacd2298e1ae8b5fa0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 6 Jul 2022 07:08:45 +0900 Subject: [PATCH] =?UTF-8?q?fix(client):=20=E3=83=86=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E3=81=A8=E3=82=AF?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=82=A2=E3=83=B3=E3=83=88=E3=81=8C=E8=B5=B7?= =?UTF-8?q?=E5=8B=95=E3=81=97=E3=81=AA=E3=81=8F=E3=81=AA=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/pages/settings/theme.vue | 10 ++++++++-- packages/client/src/pages/theme-editor.vue | 2 +- packages/client/src/store.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/client/src/pages/settings/theme.vue b/packages/client/src/pages/settings/theme.vue index 1bdad3e75a..d330e1ba25 100644 --- a/packages/client/src/pages/settings/theme.vue +++ b/packages/client/src/pages/settings/theme.vue @@ -97,7 +97,10 @@ const darkThemeId = computed({ return darkTheme.value.id; }, set(id) { - ColdDeviceStorage.set('darkTheme', themes.value.find(x => x.id === id)); + const t = themes.value.find(x => x.id === id); + if (t) { // テーマエディタでテーマを作成したときなどは、themesに反映されないため undefined になる + ColdDeviceStorage.set('darkTheme', t); + } }, }); const lightTheme = ColdDeviceStorage.ref('lightTheme'); @@ -106,7 +109,10 @@ const lightThemeId = computed({ return lightTheme.value.id; }, set(id) { - ColdDeviceStorage.set('lightTheme', themes.value.find(x => x.id === id)); + const t = themes.value.find(x => x.id === id); + if (t) { // テーマエディタでテーマを作成したときなどは、themesに反映されないため undefined になる + ColdDeviceStorage.set('lightTheme', t); + } }, }); const darkMode = computed(defaultStore.makeGetterSetter('darkMode')); diff --git a/packages/client/src/pages/theme-editor.vue b/packages/client/src/pages/theme-editor.vue index 44b5a05f27..548e60614b 100644 --- a/packages/client/src/pages/theme-editor.vue +++ b/packages/client/src/pages/theme-editor.vue @@ -192,7 +192,7 @@ async function saveAs() { theme.name = name; theme.author = `@${$i.username}@${toUnicode(host)}`; if (description) theme.desc = description; - addTheme(theme); + await addTheme(theme); applyTheme(theme); if (defaultStore.state.darkMode) { ColdDeviceStorage.set('darkTheme', theme); diff --git a/packages/client/src/store.ts b/packages/client/src/store.ts index d87e05a4de..5033333313 100644 --- a/packages/client/src/store.ts +++ b/packages/client/src/store.ts @@ -304,6 +304,14 @@ export class ColdDeviceStorage { } public static set(key: T, value: typeof ColdDeviceStorage.default[T]): void { + // 呼び出し側のバグ等で undefined が来ることがある + // undefined を文字列として localStorage に入れると参照する際の JSON.parse でコケて不具合の元になるため無視 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if (value === undefined) { + console.error(`attempt to store undefined value for key '${key}'`); + return; + } + localStorage.setItem(PREFIX + key, JSON.stringify(value)); for (const watcher of this.watchers) {