A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: sources toggle method

+60
+60
src/components/orchestrator/sources/element.js
··· 1 1 import deepDiff from "@fry69/deep-diff"; 2 2 3 + import * as Output from "~/common/output.js"; 3 4 import { BroadcastableDiffuseElement, query } from "~/common/element.js"; 4 5 import { groupTracksPerScheme } from "~/common/utils.js"; 5 6 import { signal } from "~/common/signal.js"; ··· 15 16 16 17 class Sources extends BroadcastableDiffuseElement { 17 18 static NAME = "diffuse/orchestrator/sources"; 19 + static DISABLED_KEY = "sh.diffuse.input.disabled.uris"; 18 20 19 21 // SIGNALS 20 22 ··· 24 26 25 27 sources = this.#sources.get; 26 28 29 + #output = signal(/** @type {OutputElement | null} */ (null)); 30 + 31 + // METHODS 32 + 33 + /** 34 + * @param {string} uri 35 + */ 36 + async toggle(uri) { 37 + const output = this.#output.value; 38 + if (!output) { 39 + console.warn("Output element is not available yet."); 40 + return; 41 + } 42 + 43 + const settings = await Output.data(output.settings); 44 + const existing = settings.find((s) => s.key === Sources.DISABLED_KEY); 45 + 46 + /** @type {string[]} */ 47 + let disabled = []; 48 + if (existing) { 49 + try { 50 + const parsed = JSON.parse(existing.value); 51 + disabled = Array.isArray(parsed) ? parsed : []; 52 + } catch { 53 + disabled = []; 54 + } 55 + } 56 + 57 + if (disabled.includes(uri)) { 58 + disabled = disabled.filter((u) => u !== uri); 59 + } else { 60 + disabled = [...disabled, uri]; 61 + } 62 + 63 + const value = JSON.stringify(disabled); 64 + const updated = existing 65 + ? settings.map((s) => 66 + s.key === Sources.DISABLED_KEY ? { ...s, value } : s 67 + ) 68 + : [ 69 + ...settings, 70 + { 71 + $type: /** @type {"sh.diffuse.output.setting"} */ ( 72 + "sh.diffuse.output.setting" 73 + ), 74 + id: crypto.randomUUID(), 75 + key: Sources.DISABLED_KEY, 76 + value, 77 + }, 78 + ]; 79 + 80 + await output.settings.save(updated); 81 + } 82 + 27 83 // LIFECYCLE 28 84 29 85 /** ··· 42 98 await customElements.whenDefined(input.localName); 43 99 await customElements.whenDefined(output.localName); 44 100 101 + // Signals 102 + this.#output.value = output; 103 + 104 + // Single input mode + dependencies 45 105 const singleInputMode = !!input.SCHEME; 46 106 const deps = 47 107 /** @type {{ [k: string]: InputElement }} */ (singleInputMode