Skip to content

Commit 191c460

Browse files
committed
revert
1 parent 89ca000 commit 191c460

File tree

8 files changed

+33
-63
lines changed

8 files changed

+33
-63
lines changed

src/constants/defaults.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ export interface AppSettings {
3737
* - Binary data is NEVER stored here.
3838
*/
3939
localFileName?: string;
40+
/**
41+
* Local media ID used for IndexedDB lookups.
42+
*
43+
* - Typically this will be set to the presetId so that each preset
44+
* owns at most one local media record.
45+
* - This value is NOT exported into .nzxt-esc-preset files; it is
46+
* used only at runtime and in local storage.
47+
*/
48+
localMediaId?: string;
4049
}
4150

4251
/**

src/hooks/useConfig.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,7 @@ export function useConfig() {
6262
const merged = { ...settings, ...newSettings };
6363
setSettingsState(merged);
6464

65-
// Background settings are preset-specific; do not persist
66-
const {
67-
scale,
68-
x,
69-
y,
70-
fit,
71-
align,
72-
loop,
73-
autoplay,
74-
mute,
75-
resolution,
76-
backgroundColor,
77-
...configWithoutBackgroundFields
78-
} = merged;
79-
80-
const configJson = JSON.stringify(configWithoutBackgroundFields);
65+
const configJson = JSON.stringify(merged);
8166
localStorage.setItem(STORAGE_KEYS.CONFIG, configJson);
8267
localStorage.setItem(STORAGE_KEYS.CONFIG_COMPAT, configJson);
8368

src/hooks/useLocalMedia.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface UseLocalMediaParams {
2222
*
2323
* Responsibilities:
2424
* - Only active when settings.sourceType === 'local'.
25-
* - Reads blob from IndexedDB using activePresetId as the key.
25+
* - Reads blob from IndexedDB using settings.localMediaId (or activePresetId as fallback).
2626
* - Creates and manages a blob URL, revoking old URLs to avoid leaks.
2727
* - Protects against race conditions when source or preset changes rapidly.
2828
*
@@ -55,7 +55,9 @@ export function useLocalMedia({ settings, activePresetId }: UseLocalMediaParams)
5555
return;
5656
}
5757

58-
if (!activePresetId) {
58+
const mediaId = settings.localMediaId || activePresetId;
59+
60+
if (!mediaId) {
5961
// Local mode but we don't have an identifier yet – treat as missing
6062
setBlobUrl(null);
6163
setIsLoading(false);
@@ -76,7 +78,7 @@ export function useLocalMedia({ settings, activePresetId }: UseLocalMediaParams)
7678

7779
(async () => {
7880
try {
79-
const record = await getLocalMedia(activePresetId);
81+
const record = await getLocalMedia(mediaId);
8082

8183
// Ignore if this request is stale
8284
if (cancelled || currentRequestId !== requestIdRef.current) return;
@@ -128,11 +130,15 @@ export function useLocalMedia({ settings, activePresetId }: UseLocalMediaParams)
128130
return () => {
129131
cancelled = true;
130132
};
133+
<<<<<<< HEAD
131134
<<<<<<< HEAD
132135
}, [settings.sourceType, settings.localFileName, activePresetId]);
133136
=======
134137
}, [settings.sourceType, settings.localMediaId, activePresetId]);
135138
>>>>>>> parent of 2b04aa5 (Repeated Local Media Select Fix)
139+
=======
140+
}, [settings.sourceType, settings.localMediaId, settings.localFileName, activePresetId]);
141+
>>>>>>> parent of bd81320 (Preset Problems Fix (1))
136142

137143
// Cleanup on unmount
138144
useEffect(() => {

src/hooks/useSettingsSync.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,34 +83,16 @@ export function useSettingsSync(
8383
// Don't save on initial load or before user interaction
8484
if (!hasLoadedRef.current || !hasInteractedRef.current) return;
8585

86-
// Skip save if autosave is disabled (during preset apply)
87-
if (typeof window !== 'undefined' && window.__disableAutosave) return;
88-
8986
// Throttle: Only save if 100ms has passed since last save
9087
const now = Date.now();
9188
if (now - lastSync.current < 100) return;
9289
lastSync.current = now;
9390

94-
// Background settings are preset-specific; do not persist
95-
const {
96-
scale,
97-
x,
98-
y,
99-
fit,
100-
align,
101-
loop,
102-
autoplay,
103-
mute,
104-
resolution,
105-
backgroundColor,
106-
...settingsWithoutBackgroundFields
107-
} = settings;
108-
10991
// Save settings with URL for backward compatibility
11092
// Note: URL is also stored separately in storage.ts (media_url key)
11193
// But we include it here for legacy config format compatibility
11294
const save: AppSettings & { url?: string } = {
113-
...settingsWithoutBackgroundFields,
95+
...settings,
11496
url: mediaUrl || undefined, // Include URL in config for backward compatibility
11597
};
11698

src/ui/Config.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export default function Config() {
345345
// Local mode but user typed a URL → validate and switch to remote mode
346346
if (isValidRemoteMediaUrl(trimmedUrl)) {
347347
// Delete IndexedDB local media record
348-
const presetId = activePresetId || getActivePresetId();
348+
const presetId = settings.localMediaId || activePresetId || getActivePresetId();
349349
if (presetId) {
350350
deleteLocalMedia(presetId).catch(() => {
351351
// Silently handle deletion errors
@@ -357,6 +357,7 @@ export default function Config() {
357357
...settings,
358358
sourceType: 'remote',
359359
localFileName: undefined,
360+
localMediaId: undefined,
360361
});
361362

362363
// Continue with remote URL processing below (will set mediaUrl and transform settings)
@@ -384,6 +385,7 @@ export default function Config() {
384385
...settings,
385386
sourceType: 'remote',
386387
localFileName: undefined,
388+
localMediaId: undefined,
387389
scale: 1,
388390
x: 0,
389391
y: 0,
@@ -423,6 +425,7 @@ export default function Config() {
423425
...settings,
424426
sourceType: 'remote',
425427
localFileName: undefined,
428+
localMediaId: undefined,
426429
scale: 1,
427430
x: 0,
428431
y: 0,
@@ -454,6 +457,7 @@ export default function Config() {
454457
...settings,
455458
sourceType: 'remote',
456459
localFileName: undefined,
460+
localMediaId: undefined,
457461
scale: 1,
458462
x: 0,
459463
y: 0,
@@ -466,7 +470,7 @@ export default function Config() {
466470
const handleClear = () => {
467471
// Local mode: delete local media record and reset to remote/empty
468472
if (settings.sourceType === 'local') {
469-
const presetId = activePresetId || getActivePresetId();
473+
const presetId = settings.localMediaId || activePresetId || getActivePresetId();
470474
if (presetId) {
471475
// Fire and forget deletion; errors will surface via local media hook if needed
472476
deleteLocalMedia(presetId).catch(() => {
@@ -478,6 +482,7 @@ export default function Config() {
478482
...settings,
479483
sourceType: 'remote',
480484
localFileName: undefined,
485+
localMediaId: undefined,
481486
});
482487
setMediaUrl('');
483488
setUrlInput('');
@@ -538,6 +543,7 @@ export default function Config() {
538543
...settings,
539544
sourceType: 'local',
540545
localFileName: file.name,
546+
localMediaId: presetId,
541547
});
542548
setMediaUrl('');
543549
// Show file name in input for user visibility (read-only indicator) with i18n

src/ui/components/PresetManager/PresetManager.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@
421421
}
422422

423423
.preset-modal-button {
424-
padding: 6px 16px;
424+
padding: 8px 16px;
425425
border-radius: 8px;
426426
border: 1px solid;
427427
cursor: pointer;

src/ui/styles/ConfigPreview.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@
118118
align-items: center;
119119
}
120120
.url-input {
121-
width: 100%;
121+
width: 70%;
122122
background: #2c2c2c;
123123
border: 1px solid #3a3a3a;
124124
color: #f2f2f2;
125-
padding: 7px 18px 8px 10px;
125+
padding: 5px 18px 5px 10px;
126126
border-radius: 6px;
127127
}
128128
.url-input:hover {

src/utils/settings.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,12 @@ import { DEFAULT_OVERLAY } from '../types/overlay';
88
* @returns Complete settings object with defaults applied
99
*/
1010
export function mergeSettings(saved: any): AppSettings {
11-
// Safely ignore localMediaId if present in saved settings (legacy field, no longer used)
12-
const { localMediaId, ...savedWithoutLocalMediaId } = saved || {};
13-
14-
// Background settings are preset-specific; ignore them from localStorage merge
15-
const {
16-
scale,
17-
x,
18-
y,
19-
fit,
20-
align,
21-
loop,
22-
autoplay,
23-
mute,
24-
resolution,
25-
backgroundColor,
26-
...savedWithoutBackgroundFields
27-
} = savedWithoutLocalMediaId || {};
28-
2911
return {
3012
...DEFAULT_SETTINGS,
31-
...savedWithoutBackgroundFields,
13+
...saved,
3214
overlay: {
3315
...DEFAULT_OVERLAY,
34-
...(savedWithoutBackgroundFields?.overlay || {}),
16+
...(saved?.overlay || {}),
3517
},
3618
};
3719
}

0 commit comments

Comments
 (0)