mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
chore: cleanup and optmise size
This commit is contained in:
1 parent
5dba4ba8b5
commit
a19b43ef37
6 files changed
+94
-257
No files matched your search
@@ -8,9 +8,7 @@
|
|||||||
|
|
||||||
let { isEditMode, selectNoBackground = $bindable(), selectedBackground = $bindable() } = $props<{ isEditMode: boolean, selectNoBackground: () => void, selectedBackground: string | null }>();
|
let { isEditMode, selectNoBackground = $bindable(), selectedBackground = $bindable() } = $props<{ isEditMode: boolean, selectNoBackground: () => void, selectedBackground: string | null }>();
|
||||||
let backgrounds = $state<{ id: string; type: string; blob: Blob | null; url?: string }[]>([]);
|
let backgrounds = $state<{ id: string; type: string; blob: Blob | null; url?: string }[]>([]);
|
||||||
let error = $state<string | null>(null);
|
let feedback = $state<{ kind: 'error' | 'warn'; text: string } | null>(null);
|
||||||
let notice = $state<string | null>(null);
|
|
||||||
let uploading = $state(false);
|
|
||||||
|
|
||||||
let imageBackgrounds = $derived(backgrounds.filter(bg => bg.type === 'image'));
|
let imageBackgrounds = $derived(backgrounds.filter(bg => bg.type === 'image'));
|
||||||
let videoBackgrounds = $derived(backgrounds.filter(bg => bg.type === 'video'));
|
let videoBackgrounds = $derived(backgrounds.filter(bg => bg.type === 'video'));
|
||||||
@@ -20,39 +18,12 @@
|
|||||||
if (mime.startsWith('video/')) return 'video';
|
if (mime.startsWith('video/')) return 'video';
|
||||||
if (mime.startsWith('image/')) return 'image';
|
if (mime.startsWith('image/')) return 'image';
|
||||||
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
|
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
|
||||||
if (['mp4', 'mov', 'webm', 'm4v', 'mkv'].includes(ext)) return 'video';
|
return ['mp4', 'mov', 'webm', 'm4v', 'mkv'].includes(ext) ? 'video' : 'image';
|
||||||
return 'image';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setError(e: unknown) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
error = e.message;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (typeof e === 'string' && e) {
|
|
||||||
error = e;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
error = 'An unknown error occurred';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isHeicFile(file: File): boolean {
|
|
||||||
const mime = file.type.toLowerCase();
|
|
||||||
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
|
|
||||||
return (
|
|
||||||
mime.includes('heic') ||
|
|
||||||
mime.includes('heif') ||
|
|
||||||
ext === 'heic' ||
|
|
||||||
ext === 'heif'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleFileChange(file: File): Promise<void> {
|
async function handleFileChange(file: File): Promise<void> {
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
feedback = null;
|
||||||
uploading = true;
|
|
||||||
error = null;
|
|
||||||
notice = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!isIndexedDBSupported()) {
|
if (!isIndexedDBSupported()) {
|
||||||
@@ -75,42 +46,36 @@
|
|||||||
];
|
];
|
||||||
backgroundUpdates.triggerUpdate();
|
backgroundUpdates.triggerUpdate();
|
||||||
|
|
||||||
if (isHeicFile(file)) {
|
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
|
||||||
notice =
|
if (['heic', 'heif'].includes(ext) || file.type.toLowerCase().includes('hei')) {
|
||||||
'HEIC saved, but Chrome and Edge often cannot preview it. Export as JPEG or PNG if the thumbnail stays blank.';
|
feedback = {
|
||||||
|
kind: 'warn',
|
||||||
|
text: 'HEIC saved, but Chrome and Edge often cannot preview it. Export as JPEG or PNG if the thumbnail stays blank.',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e);
|
feedback = {
|
||||||
} finally {
|
kind: 'error',
|
||||||
uploading = false;
|
text: e instanceof Error ? e.message : 'An unknown error occurred',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTheme() {
|
|
||||||
return localStorage.getItem('selectedBackground');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setTheme(theme: string) {
|
|
||||||
localStorage.setItem('selectedBackground', theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function syncBackgrounds(): Promise<void> {
|
async function syncBackgrounds(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
error = null;
|
feedback = null;
|
||||||
|
|
||||||
if (!isIndexedDBSupported()) {
|
if (!isIndexedDBSupported()) {
|
||||||
throw new Error("Your browser doesn't support IndexedDB. Unable to load backgrounds.");
|
throw new Error("Your browser doesn't support IndexedDB. Unable to load backgrounds.");
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedBackground = await getTheme();
|
selectedBackground = localStorage.getItem('selectedBackground');
|
||||||
const dbData = await readAllData();
|
const dbData = await readAllData();
|
||||||
|
|
||||||
// Release existing object URLs to prevent memory leaks
|
|
||||||
backgrounds.forEach(bg => {
|
backgrounds.forEach(bg => {
|
||||||
if (bg.url) URL.revokeObjectURL(bg.url);
|
if (bg.url) URL.revokeObjectURL(bg.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create fresh background objects with new object URLs
|
|
||||||
backgrounds = dbData.map(bg => ({
|
backgrounds = dbData.map(bg => ({
|
||||||
id: bg.id,
|
id: bg.id,
|
||||||
type: bg.type,
|
type: bg.type,
|
||||||
@@ -118,12 +83,14 @@
|
|||||||
url: URL.createObjectURL(bg.blob)
|
url: URL.createObjectURL(bg.blob)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Check if selected background still exists
|
|
||||||
if (selectedBackground && !backgrounds.some(bg => bg.id === selectedBackground)) {
|
if (selectedBackground && !backgrounds.some(bg => bg.id === selectedBackground)) {
|
||||||
selectNoBackground();
|
selectNoBackground();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e);
|
feedback = {
|
||||||
|
kind: 'error',
|
||||||
|
text: e instanceof Error ? e.message : 'An unknown error occurred',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +101,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedBackground = fileId;
|
selectedBackground = fileId;
|
||||||
setTheme(fileId);
|
localStorage.setItem('selectedBackground', fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteBackground(fileId: string): Promise<void> {
|
async function deleteBackground(fileId: string): Promise<void> {
|
||||||
@@ -147,13 +114,16 @@
|
|||||||
}
|
}
|
||||||
backgroundUpdates.triggerUpdate();
|
backgroundUpdates.triggerUpdate();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e);
|
feedback = {
|
||||||
|
kind: 'error',
|
||||||
|
text: e instanceof Error ? e.message : 'An unknown error occurred',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectNoBackground = () => {
|
selectNoBackground = () => {
|
||||||
selectedBackground = null;
|
selectedBackground = null;
|
||||||
setTheme('');
|
localStorage.setItem('selectedBackground', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -161,12 +131,6 @@
|
|||||||
selectedBackground
|
selectedBackground
|
||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
syncBackgrounds();
|
syncBackgrounds();
|
||||||
backgroundUpdates.addListener(syncBackgrounds);
|
backgroundUpdates.addListener(syncBackgrounds);
|
||||||
@@ -184,21 +148,14 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative px-1 { !( isEditMode && imageBackgrounds.length === 0 && videoBackgrounds.length === 0 ) && 'pt-2' }">
|
<div class="relative px-1 { !( isEditMode && imageBackgrounds.length === 0 && videoBackgrounds.length === 0 ) && 'pt-2' }">
|
||||||
{#if notice}
|
{#if feedback}
|
||||||
<div
|
<div
|
||||||
class="mx-1 mb-3 rounded-lg border border-amber-300/60 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-900/50 dark:bg-amber-950/40 dark:text-amber-100"
|
class="mx-1 mb-3 rounded-lg border px-3 py-2 text-sm {feedback.kind === 'warn'
|
||||||
role="status"
|
? 'border-amber-300/60 bg-amber-50 text-amber-900 dark:border-amber-900/50 dark:bg-amber-950/40 dark:text-amber-100'
|
||||||
|
: 'border-red-300/60 bg-red-50 text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200'}"
|
||||||
|
role={feedback.kind === 'warn' ? 'status' : 'alert'}
|
||||||
>
|
>
|
||||||
{notice}
|
{feedback.text}
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if error}
|
|
||||||
<div
|
|
||||||
class="mx-1 mb-3 rounded-lg border border-red-300/60 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200"
|
|
||||||
role="alert"
|
|
||||||
>
|
|
||||||
{error}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -207,11 +164,6 @@
|
|||||||
<div class="flex flex-wrap gap-4 mb-4">
|
<div class="flex flex-wrap gap-4 mb-4">
|
||||||
{#if !isEditMode}
|
{#if !isEditMode}
|
||||||
<BackgroundUploader onFileChange={handleFileChange} />
|
<BackgroundUploader onFileChange={handleFileChange} />
|
||||||
{#if uploading}
|
|
||||||
<div class="flex h-16 w-16 items-center justify-center rounded-xl bg-zinc-100 dark:bg-zinc-900">
|
|
||||||
<div class="h-5 w-5 animate-spin rounded-full border-2 border-zinc-400 border-t-transparent"></div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{/if}
|
{/if}
|
||||||
{#each imageBackgrounds as bg (bg.id)}
|
{#each imageBackgrounds as bg (bg.id)}
|
||||||
{#if bg.url}
|
{#if bg.url}
|
||||||
|
|||||||
@@ -1,107 +1,49 @@
|
|||||||
type BackgroundRecord = { id: string; type: string; blob: Blob };
|
type BackgroundRecord = { id: string; type: string; blob: Blob };
|
||||||
|
|
||||||
const DB_NAME = "BackgroundDB";
|
const DB_NAME = "BackgroundDB";
|
||||||
const STORE_NAME = "backgrounds";
|
const STORE = "backgrounds";
|
||||||
const DB_VERSION = 1;
|
|
||||||
|
|
||||||
let dbPromise: Promise<IDBDatabase> | null = null;
|
let dbPromise: Promise<IDBDatabase> | null = null;
|
||||||
|
|
||||||
function promisifyRequest<T>(request: IDBRequest<T>): Promise<T> {
|
function req<T>(request: IDBRequest<T>): Promise<T> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request.onsuccess = () => resolve(request.result);
|
request.onsuccess = () => resolve(request.result);
|
||||||
request.onerror = () => reject(request.error);
|
request.onerror = () => reject(request.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitForTransaction(tx: IDBTransaction): Promise<void> {
|
function txDone(tx: IDBTransaction): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
tx.oncomplete = () => resolve();
|
tx.oncomplete = () => resolve();
|
||||||
tx.onerror = () => reject(tx.error);
|
tx.onerror = () => reject(tx.error);
|
||||||
tx.onabort = () => reject(tx.error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openDatabaseInternal(): Promise<IDBDatabase> {
|
export function openDatabase(): Promise<IDBDatabase> {
|
||||||
if (!dbPromise) {
|
if (!dbPromise) {
|
||||||
dbPromise = new Promise((resolve, reject) => {
|
dbPromise = new Promise((resolve, reject) => {
|
||||||
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
const open = indexedDB.open(DB_NAME, 1);
|
||||||
|
open.onerror = () => {
|
||||||
request.onerror = () => {
|
|
||||||
dbPromise = null;
|
dbPromise = null;
|
||||||
reject(request.error);
|
reject(open.error);
|
||||||
};
|
};
|
||||||
|
open.onupgradeneeded = () => {
|
||||||
request.onupgradeneeded = () => {
|
if (!open.result.objectStoreNames.contains(STORE)) {
|
||||||
const db = request.result;
|
open.result.createObjectStore(STORE, { keyPath: "id" });
|
||||||
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
||||||
db.createObjectStore(STORE_NAME, { keyPath: "id" });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
open.onsuccess = () => resolve(open.result);
|
||||||
request.onsuccess = () => resolve(request.result);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbPromise;
|
return dbPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeUsesInlineKeys(store: IDBObjectStore): boolean {
|
|
||||||
return store.keyPath !== null && store.keyPath !== "";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function withStore<T>(
|
|
||||||
mode: IDBTransactionMode,
|
|
||||||
run: (store: IDBObjectStore) => Promise<T>,
|
|
||||||
): Promise<T> {
|
|
||||||
const db = await openDatabaseInternal();
|
|
||||||
const tx = db.transaction(STORE_NAME, mode);
|
|
||||||
const result = await run(tx.objectStore(STORE_NAME));
|
|
||||||
await waitForTransaction(tx);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function openDatabase(): Promise<IDBDatabase> {
|
|
||||||
return openDatabaseInternal();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function readAllData(): Promise<BackgroundRecord[]> {
|
export async function readAllData(): Promise<BackgroundRecord[]> {
|
||||||
return withStore("readonly", async (store) => {
|
const db = await openDatabase();
|
||||||
const items: BackgroundRecord[] = [];
|
const tx = db.transaction(STORE, "readonly");
|
||||||
|
const items = await req(tx.objectStore(STORE).getAll());
|
||||||
await new Promise<void>((resolve, reject) => {
|
await txDone(tx);
|
||||||
const request = store.openCursor();
|
return items;
|
||||||
|
|
||||||
request.onsuccess = () => {
|
|
||||||
const cursor = request.result;
|
|
||||||
if (!cursor) {
|
|
||||||
resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = cursor.value as Partial<BackgroundRecord> | undefined;
|
|
||||||
const id =
|
|
||||||
typeof value?.id === "string"
|
|
||||||
? value.id
|
|
||||||
: cursor.key == null
|
|
||||||
? ""
|
|
||||||
: String(cursor.key);
|
|
||||||
|
|
||||||
if (id && value?.blob instanceof Blob) {
|
|
||||||
items.push({
|
|
||||||
id,
|
|
||||||
type: typeof value.type === "string" ? value.type : "image",
|
|
||||||
blob: value.blob,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.continue();
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onerror = () => reject(request.error);
|
|
||||||
});
|
|
||||||
|
|
||||||
return items;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function writeData(
|
export async function writeData(
|
||||||
@@ -109,15 +51,14 @@ export async function writeData(
|
|||||||
type: string,
|
type: string,
|
||||||
blob: Blob,
|
blob: Blob,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const record: BackgroundRecord = { id, type, blob };
|
const record = { id, type, blob };
|
||||||
|
const db = await openDatabase();
|
||||||
|
const tx = db.transaction(STORE, "readwrite");
|
||||||
|
const store = tx.objectStore(STORE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await withStore("readwrite", async (store) => {
|
await req(store.keyPath ? store.put(record) : store.put(record, id));
|
||||||
const request = storeUsesInlineKeys(store)
|
await txDone(tx);
|
||||||
? store.put(record)
|
|
||||||
: store.put(record, id);
|
|
||||||
await promisifyRequest(request);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const detail = e instanceof Error ? e.message : String(e);
|
const detail = e instanceof Error ? e.message : String(e);
|
||||||
throw new Error(`Failed to save background: ${detail}`);
|
throw new Error(`Failed to save background: ${detail}`);
|
||||||
@@ -125,30 +66,27 @@ export async function writeData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteData(id: string): Promise<void> {
|
export async function deleteData(id: string): Promise<void> {
|
||||||
try {
|
const db = await openDatabase();
|
||||||
await withStore("readwrite", async (store) => {
|
const tx = db.transaction(STORE, "readwrite");
|
||||||
await promisifyRequest(store.delete(id));
|
await req(tx.objectStore(STORE).delete(id));
|
||||||
});
|
await txDone(tx);
|
||||||
} catch (e) {
|
|
||||||
const detail = e instanceof Error ? e.message : String(e);
|
|
||||||
throw new Error(`Failed to delete background: ${detail}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function clearAllData(): Promise<void> {
|
export async function clearAllData(): Promise<void> {
|
||||||
await withStore("readwrite", async (store) => {
|
const db = await openDatabase();
|
||||||
await promisifyRequest(store.clear());
|
const tx = db.transaction(STORE, "readwrite");
|
||||||
});
|
await req(tx.objectStore(STORE).clear());
|
||||||
|
await txDone(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDataById(
|
export async function getDataById(
|
||||||
id: string,
|
id: string,
|
||||||
): Promise<BackgroundRecord | undefined> {
|
): Promise<BackgroundRecord | undefined> {
|
||||||
const item = await withStore("readonly", async (store) =>
|
const db = await openDatabase();
|
||||||
promisifyRequest(store.get(id)),
|
const tx = db.transaction(STORE, "readonly");
|
||||||
);
|
const item = await req(tx.objectStore(STORE).get(id));
|
||||||
if (!item?.id || !(item.blob instanceof Blob)) return undefined;
|
await txDone(tx);
|
||||||
return item as BackgroundRecord;
|
return item?.blob instanceof Blob ? item : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function closeDatabase(): void {
|
export function closeDatabase(): void {
|
||||||
@@ -165,11 +103,7 @@ export function isIndexedDBSupported(): boolean {
|
|||||||
export async function hasEnoughStorageSpace(
|
export async function hasEnoughStorageSpace(
|
||||||
requiredSpace: number,
|
requiredSpace: number,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if ("storage" in navigator && "estimate" in navigator.storage) {
|
if (!("storage" in navigator) || !navigator.storage.estimate) return true;
|
||||||
const { quota, usage } = await navigator.storage.estimate();
|
const { quota, usage } = await navigator.storage.estimate();
|
||||||
if (quota !== undefined && usage !== undefined) {
|
return quota == null || usage == null || quota - usage > requiredSpace;
|
||||||
return quota - usage > requiredSpace;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Component } from "svelte";
|
|
||||||
import type { SettingsSectionId, SettingsSectionSharedProps } from "./shared";
|
|
||||||
import { SECTION_LOADERS } from "./sectionLoaders";
|
|
||||||
|
|
||||||
let {
|
|
||||||
section,
|
|
||||||
...rest
|
|
||||||
}: SettingsSectionSharedProps & { section: SettingsSectionId } = $props();
|
|
||||||
|
|
||||||
let Comp = $state<Component | null>(null);
|
|
||||||
let loadToken = 0;
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
section;
|
|
||||||
Comp = null;
|
|
||||||
const token = ++loadToken;
|
|
||||||
void SECTION_LOADERS[section]().then((mod) => {
|
|
||||||
if (token === loadToken) Comp = mod.default;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if Comp}
|
|
||||||
<Comp {section} {...rest} />
|
|
||||||
{:else}
|
|
||||||
<div class="px-5 py-6 text-sm text-zinc-400 animate-pulse">Loading…</div>
|
|
||||||
{/if}
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import LazySection from "./LazySection.svelte";
|
import LazyPanel from "../../components/LazyPanel.svelte";
|
||||||
import {
|
import {
|
||||||
ALL_SETTINGS_SECTIONS,
|
ALL_SETTINGS_SECTIONS,
|
||||||
type SettingsSectionId,
|
type SettingsSectionId,
|
||||||
type SettingsSectionSharedProps,
|
type SettingsSectionSharedProps,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
|
import { SECTION_LOADERS } from "./sectionLoaders";
|
||||||
import { isPerformanceMode } from "@/seqta/utils/performanceMode";
|
import { isPerformanceMode } from "@/seqta/utils/performanceMode";
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -12,31 +13,29 @@
|
|||||||
...rest
|
...rest
|
||||||
}: SettingsSectionSharedProps & { activeSection?: string } = $props();
|
}: SettingsSectionSharedProps & { activeSection?: string } = $props();
|
||||||
|
|
||||||
let mountedSectionCount = $state(ALL_SETTINGS_SECTIONS.length);
|
let mountedSectionCount = $state(1);
|
||||||
|
|
||||||
|
function scheduleIdle(step: () => void) {
|
||||||
|
const delay = isPerformanceMode() ? 64 : 32;
|
||||||
|
const timeout = isPerformanceMode() ? 800 : 500;
|
||||||
|
if (typeof requestIdleCallback === "function") {
|
||||||
|
requestIdleCallback(step, { timeout });
|
||||||
|
} else {
|
||||||
|
setTimeout(step, delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (activeSection !== "all") {
|
|
||||||
mountedSectionCount = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mountedSectionCount = 1;
|
mountedSectionCount = 1;
|
||||||
|
if (activeSection !== "all") return;
|
||||||
|
|
||||||
let idx = 1;
|
let idx = 1;
|
||||||
const step = () => {
|
const step = () => {
|
||||||
if (idx >= ALL_SETTINGS_SECTIONS.length) return;
|
if (idx >= ALL_SETTINGS_SECTIONS.length) return;
|
||||||
mountedSectionCount = ++idx;
|
mountedSectionCount = ++idx;
|
||||||
if (typeof requestIdleCallback === "function") {
|
scheduleIdle(step);
|
||||||
requestIdleCallback(step, { timeout: isPerformanceMode() ? 800 : 500 });
|
|
||||||
} else {
|
|
||||||
setTimeout(step, isPerformanceMode() ? 64 : 32);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
scheduleIdle(step);
|
||||||
if (typeof requestIdleCallback === "function") {
|
|
||||||
requestIdleCallback(step, { timeout: isPerformanceMode() ? 800 : 500 });
|
|
||||||
} else {
|
|
||||||
setTimeout(step, isPerformanceMode() ? 64 : 32);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const sectionsToShow = $derived.by((): SettingsSectionId[] => {
|
const sectionsToShow = $derived.by((): SettingsSectionId[] => {
|
||||||
@@ -52,6 +51,10 @@
|
|||||||
|
|
||||||
<div class="flex flex-col divide-y divide-zinc-100 dark:divide-zinc-700">
|
<div class="flex flex-col divide-y divide-zinc-100 dark:divide-zinc-700">
|
||||||
{#each sectionsToShow as section (section)}
|
{#each sectionsToShow as section (section)}
|
||||||
<LazySection {section} {...rest} />
|
<LazyPanel
|
||||||
|
loader={SECTION_LOADERS[section]}
|
||||||
|
remountKey={section}
|
||||||
|
props={{ section, ...rest }}
|
||||||
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -138,11 +138,6 @@ export function syncPerformanceModeEffects(): void {
|
|||||||
applyPerformanceModeClass();
|
applyPerformanceModeClass();
|
||||||
applyPerformanceModeTransparency();
|
applyPerformanceModeTransparency();
|
||||||
applyPerformanceModeSidebarLook();
|
applyPerformanceModeSidebarLook();
|
||||||
|
|
||||||
if (isPerformanceMode()) {
|
|
||||||
removeAnimatedBackgroundLayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncPerformanceModePlugins();
|
void syncPerformanceModePlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,26 +29,7 @@ export function animatePopupOpen(background: HTMLElement): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function animatePopupClose(background: HTMLElement): Promise<void> {
|
export function animatePopupClose(background: HTMLElement): Promise<void> {
|
||||||
if (!useCssPopupAnimation()) {
|
if (!useCssPopupAnimation()) return Promise.resolve();
|
||||||
return Promise.resolve();
|
background.classList.remove(OPEN_CLASS);
|
||||||
}
|
return new Promise((resolve) => window.setTimeout(resolve, CLOSE_FALLBACK_MS));
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
let settled = false;
|
|
||||||
const finish = () => {
|
|
||||||
if (settled) return;
|
|
||||||
settled = true;
|
|
||||||
background.removeEventListener("transitionend", onEnd);
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onEnd = (event: TransitionEvent) => {
|
|
||||||
if (event.target !== background || event.propertyName !== "opacity") return;
|
|
||||||
finish();
|
|
||||||
};
|
|
||||||
|
|
||||||
background.addEventListener("transitionend", onEnd);
|
|
||||||
background.classList.remove(OPEN_CLASS);
|
|
||||||
window.setTimeout(finish, CLOSE_FALLBACK_MS);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user