Added ablity to import settings from file

This commit is contained in:
WardPearce
2026-03-07 00:55:36 +13:00
parent 4422506003
commit 644d257841
3 changed files with 41 additions and 5 deletions
@@ -8,7 +8,7 @@
import { getSubscriptionsInvidious } from '$lib/api/invidious/feed';
import { backendInUseStore, invidiousAuthStore, invidiousInstanceStore } from '$lib/store';
import { Clipboard } from '@capacitor/clipboard';
import { settingsToJson } from '$lib/externalSettings';
import { loadSettingsFromFile, settingsToJson } from '$lib/externalSettings';
import { downloadStringAsFile } from '$lib/misc';
async function importInvidiousSubs() {
@@ -147,7 +147,7 @@
}}
>
<i>content_copy</i>
<span>{$_('copy')}</span>
<span>{$_('layout.export.exportToClipboard')}</span>
</button>
<div class="space"></div>
<button
@@ -156,6 +156,24 @@
downloadStringAsFile(settingsToJson(), 'materialious-settings.json');
}}
>
<i>download</i>
<span>{$_('player.download')}</span>
<i>file_export</i>
<span>{$_('layout.export.exportToFile')}</span>
</button>
<div class="space"></div>
<div>
<button class="surface-container-highest">
<i>attach_file</i>
<span>{$_('layout.export.importFromFile')}</span>
</button>
<input
onchange={async (event: Event) => {
const files = (event.target as HTMLInputElement).files;
if (files?.length === 0 || !files) return;
await loadSettingsFromFile(files[0]);
}}
type="file"
/>
</div>
@@ -80,6 +80,21 @@ function setStores(toSet: Record<string, unknown>, overwriteExisting = false) {
}
}
export async function loadSettingsFromFile(file: File) {
const fileContents = await file.text();
let fileJson: Record<any, any> | undefined;
try {
fileJson = JSON.parse(fileContents);
} catch {
// Handled outside of catch.
}
if (!fileJson) return;
setStores(fileJson, true);
}
export function loadSettingsFromEnv() {
const defaultSettings = getPublicEnv('DEFAULT_SETTINGS');
+4 -1
View File
@@ -277,7 +277,10 @@
"importSubSupported": "YouTube CSV/OPML/JSON, Invidious OPML/JSON, Freetube database & NewPipe JSON supported",
"importing": "Importing subscriptions (this will take a moment)",
"importingCompleted": "Subscriptions successfully imported",
"exportSub": "Export subscriptions"
"exportSub": "Export subscriptions",
"exportToClipboard": "Export to clipboard",
"exportToFile": "Export to file",
"importFromFile": "Import from file"
},
"deArrow": {
"title": "DeArrow",