1
Fork 0

Run the 2.0.0 data migration on settings import.

This commit is contained in:
Bauke 2023-07-18 13:13:14 +02:00
parent eace9562dd
commit 68a1399685
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import {
isValidHexColor, isValidHexColor,
isValidTildesUsername, isValidTildesUsername,
} from "../../utilities/exports.js"; } from "../../utilities/exports.js";
import {migrations} from "../../storage/migrations/migrations.js";
import {type SettingProps, Setting} from "./index.js"; import {type SettingProps, Setting} from "./index.js";
async function importFileHandler(event: Event): Promise<void> { async function importFileHandler(event: Event): Promise<void> {
@ -20,11 +21,11 @@ async function importFileHandler(event: Event): Promise<void> {
const reader = new window.FileReader(); const reader = new window.FileReader();
reader.addEventListener("load", async (): Promise<void> => { reader.addEventListener("load", async (): Promise<void> => {
let data: unknown; let data: Record<string, any>;
try { try {
// eslint-disable-next-line @typescript-eslint/no-base-to-string // eslint-disable-next-line @typescript-eslint/no-base-to-string
data = JSON.parse(reader.result!.toString()); data = JSON.parse(reader.result!.toString()) as Record<string, any>;
} catch (error: unknown) { } catch (error: unknown) {
log(error, true); log(error, true);
return; return;
@ -35,7 +36,13 @@ async function importFileHandler(event: Event): Promise<void> {
return; return;
} }
// 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); await browser.storage.sync.set(data);
}
log("Successfully imported your settings, reloading the page to apply."); log("Successfully imported your settings, reloading the page to apply.");
setTimeout(() => { setTimeout(() => {
window.location.reload(); window.location.reload();