mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
web/debug: dump states on debug page
This commit is contained in:
parent
be7c09bd07
commit
c17db15e62
1 changed files with 37 additions and 2 deletions
|
@ -1,25 +1,60 @@
|
|||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { version } from "$lib/version";
|
||||
import { device, app } from "$lib/device";
|
||||
import { defaultNavPage } from "$lib/subnav";
|
||||
import settings, { storedSettings } from "$lib/state/settings";
|
||||
|
||||
import SectionHeading from "$components/misc/SectionHeading.svelte";
|
||||
import { type Readable, type Unsubscriber } from "svelte/store";
|
||||
|
||||
const stateSubscribers: Record<string, Unsubscriber> = {};
|
||||
let states: Record<string, unknown> = {};
|
||||
|
||||
$: sections = [
|
||||
{ title: "device", data: device },
|
||||
{ title: "app", data: app },
|
||||
{ title: "settings", data: $storedSettings },
|
||||
{ title: "version", data: $version },
|
||||
{ title: "states", data: states }
|
||||
];
|
||||
|
||||
const loadStates = () => {
|
||||
const modules = import.meta.glob("/src/lib/*/*.ts");
|
||||
const excluded = new Set(['translations.translations', 'settings']);
|
||||
|
||||
Object.entries(modules).map(async ([ name, _import ]) => {
|
||||
const moduleName = name.split('/').pop()?.split('.').shift();
|
||||
|
||||
const module = await _import() as Record<string, unknown>;
|
||||
for (const key in module) {
|
||||
const _export = module[key] as unknown as Readable<unknown>;
|
||||
if (typeof _export === 'object' && 'subscribe' in _export) {
|
||||
const name = moduleName + (key === 'default' ? '' : `.${key}`);
|
||||
if (excluded.has(name)) continue;
|
||||
|
||||
stateSubscribers[name] = _export.subscribe((value) => {
|
||||
states = {
|
||||
...states,
|
||||
[name]: value
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!$settings.advanced.debug) {
|
||||
goto(defaultNavPage("settings"), { replaceState: true });
|
||||
}
|
||||
|
||||
loadStates();
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
Object.values(stateSubscribers).map(unsub => unsub());
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if $settings.advanced.debug}
|
||||
|
|
Loading…
Reference in a new issue