From 338acdf398137ed04d6ecf8fdd5835d95a6a7b31 Mon Sep 17 00:00:00 2001 From: ww24 Date: Mon, 1 Jul 2024 00:23:18 +0900 Subject: [PATCH] fix(settings): fix restore default settings --- src/configuration.ts | 4 ++++ src/element/settings.ts | 2 +- src/service_worker.ts | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/configuration.ts b/src/configuration.ts index dd08e80..efdb020 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -33,6 +33,10 @@ export class Configuration { this.updatedAt = 0 this.userId = '' } + static restoreDefault({ userId }: Configuration): Configuration { + const config = new Configuration() + return { ...config, userId } + } static videoFormat(config: Configuration): VideoFormat { if (config.videoFormat.videoBitrate === 0) { return { diff --git a/src/element/settings.ts b/src/element/settings.ts index 92f03ee..8d5201a 100644 --- a/src/element/settings.ts +++ b/src/element/settings.ts @@ -189,7 +189,7 @@ export class Settings extends LitElement { } private async restore() { const oldVal = this.config - this.config = new Configuration() + this.config = Configuration.restoreDefault(this.config) this.requestUpdate('config', oldVal) this.resetValidityError() Settings.setConfiguration(this.config) diff --git a/src/service_worker.ts b/src/service_worker.ts index 69b031f..c9807ae 100644 --- a/src/service_worker.ts +++ b/src/service_worker.ts @@ -19,6 +19,7 @@ chrome.runtime.onInstalled.addListener(async () => { if (config.userId === '') { config.userId = uuidv7() } + await storage.set(Configuration.key, config) console.debug('config:', config) const msg: OffscreenSyncConfigMessage = {