From 68a1399685368f3308c1bbc24fe036dcdd54a622 Mon Sep 17 00:00:00 2001 From: Bauke Date: Tue, 18 Jul 2023 13:13:14 +0200 Subject: [PATCH] Run the 2.0.0 data migration on settings import. --- source/options/components/about.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/options/components/about.tsx b/source/options/components/about.tsx index 7fe773a..ed7c5b2 100644 --- a/source/options/components/about.tsx +++ b/source/options/components/about.tsx @@ -6,6 +6,7 @@ import { isValidHexColor, isValidTildesUsername, } from "../../utilities/exports.js"; +import {migrations} from "../../storage/migrations/migrations.js"; import {type SettingProps, Setting} from "./index.js"; async function importFileHandler(event: Event): Promise { @@ -20,11 +21,11 @@ async function importFileHandler(event: Event): Promise { const reader = new window.FileReader(); reader.addEventListener("load", async (): Promise => { - let data: unknown; + let data: Record; try { // eslint-disable-next-line @typescript-eslint/no-base-to-string - data = JSON.parse(reader.result!.toString()); + data = JSON.parse(reader.result!.toString()) as Record; } catch (error: unknown) { log(error, true); return; @@ -35,7 +36,13 @@ async function importFileHandler(event: Event): Promise { return; } - await browser.storage.sync.set(data); + // eslint-disable-next-line unicorn/prefer-ternary + if (data.version === "1.1.2") { + await migrations[0].migrate(data); + } else { + await browser.storage.sync.set(data); + } + log("Successfully imported your settings, reloading the page to apply."); setTimeout(() => { window.location.reload();