From 3246c2e883fd6aa2e60714892c6c66ade56c4f7c Mon Sep 17 00:00:00 2001
From: Steven Vandevelde
Date: Thu, 9 Jul 2026 15:28:41 +0200
Subject: [PATCH] chore: export/import settings
---
src/facets/data/export-import/index.html | 6 ++++
src/facets/data/export-import/index.inline.js | 36 +++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/src/facets/data/export-import/index.html b/src/facets/data/export-import/index.html
index fc8d26cc..a6eca61a 100644
--- a/src/facets/data/export-import/index.html
+++ b/src/facets/data/export-import/index.html
@@ -95,6 +95,12 @@
Import facets
+
+
+
diff --git a/src/facets/data/export-import/index.inline.js b/src/facets/data/export-import/index.inline.js
index 4db5e8dd..8e498c07 100644
--- a/src/facets/data/export-import/index.inline.js
+++ b/src/facets/data/export-import/index.inline.js
@@ -22,6 +22,8 @@ const importPlaylistItemsBtn =
));
const importFacetsBtn =
/** @type {HTMLButtonElement} */ (document.querySelector("#import-facets"));
+const importSettingsBtn =
+ /** @type {HTMLButtonElement} */ (document.querySelector("#import-settings"));
const statusEl = /** @type {HTMLElement} */ (document.querySelector("#status"));
const replaceCheckbox =
/** @type {HTMLInputElement} */ (document.querySelector("#replace"));
@@ -49,12 +51,14 @@ effect(() => {
exportBtn.onclick = async () => {
const facets = await Output.data(output.facets);
const playlistItems = await Output.data(output.playlistItems);
+ const settings = await Output.data(output.settings);
const tracks = await Output.data(output.tracks);
const data = {
exportedAt: new Date().toISOString(),
facets,
playlistItems,
+ settings,
tracks,
};
@@ -82,6 +86,7 @@ fileInput.onchange = async () => {
importTracksBtn.disabled = true;
importPlaylistItemsBtn.disabled = true;
importFacetsBtn.disabled = true;
+ importSettingsBtn.disabled = true;
if (!file) return;
@@ -107,6 +112,10 @@ fileInput.onchange = async () => {
if (Array.isArray(json?.facets) && json.facets.length > 0) {
importFacetsBtn.disabled = false;
}
+
+ if (Array.isArray(json?.settings) && json.settings.length > 0) {
+ importSettingsBtn.disabled = false;
+ }
};
/**
@@ -199,6 +208,33 @@ importFacetsBtn.onclick = async () => {
}
};
+// Import settings
+importSettingsBtn.onclick = async () => {
+ /** @type {any[]} */
+ const settings = json?.settings;
+ if (!Array.isArray(settings) || settings.length === 0) return;
+
+ importSettingsBtn.disabled = true;
+ setButtonLabel(importSettingsBtn, " Importing ...");
+ try {
+ if (replaceCheckbox.checked) {
+ await output.settings.save(settings);
+ showStatus(`Imported ${settings.length} setting(s).`, "success");
+ } else {
+ const existing = await Output.data(output.settings);
+ const merged = Output.mergeById(existing, settings);
+ await output.settings.save(merged);
+ showStatus(`Merged ${settings.length} setting(s).`, "success");
+ }
+ } catch (err) {
+ console.error("Import failed:", err);
+ showStatus(`Import failed: ${/** @type {Error} */ (err).message}`, "error");
+ } finally {
+ setButtonLabel(importSettingsBtn, " Import settings");
+ importSettingsBtn.disabled = false;
+ }
+};
+
////////////////////////////////////////////
// 🚀
////////////////////////////////////////////
--
2.51.2