Repository navigation
Expand file tree
/
Copy pathsettingsStore.js
More file actions
964 lines (871 loc) · 42.3 KB
/
Copy pathsettingsStore.js
File metadata and controls
964 lines (871 loc) · 42.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
const fs = require("fs");
const path = require("path");
// Validates that a value is a CSS hex color string (#RRGGBB).
function isValidHex(val) {
return typeof val === "string" && /^#[0-9a-fA-F]{6}$/.test(val);
}
// Returns input.customColors if it is an array of exactly 3 valid hex strings;
// otherwise returns the provided fallback. Used by all sanitize functions that
// expose a customColors field so corrupted settings cannot reach the renderer.
function sanitizeCustomColors(input, fallback) {
if (Array.isArray(input) && input.length === 3 && input.every(isValidHex)) {
return input;
}
return fallback;
}
const DEFAULT_SETTINGS = Object.freeze({
onboardingSeen: false,
launchOnStartup: false,
selectedTheme: "ambientWave",
colorMode: "manual",
customColors: Object.freeze(["#00f2fe", "#4facfe", "#8ee2ff"]),
themeAutomation: Object.freeze({
enabled: false,
checkIntervalMinutes: 30,
mode: "dayNight",
dayTheme: "ambientWave",
nightTheme: "reactiveBorder",
dayStartHour: 6,
nightStartHour: 18
}),
shortcuts: Object.freeze({
togglePause: "Ctrl+Alt+P",
toggleHide: "Ctrl+Alt+H",
cycleTheme: "Ctrl+Alt+T"
}),
performanceMode: "balanced",
fpsLimit: "default",
ambientWave: Object.freeze({
tone: "blue",
sensitivity: "medium",
edgeMode: "bottom",
glowStrength: "medium"
}),
reactiveBorder: Object.freeze({
colorStyle: "rainbow",
intensity: "medium",
borderThickness: "thin",
glowStrength: "medium"
}),
flowBorder: Object.freeze({
direction: "clockwise",
speedMode: "balanced",
segmentLength: "medium",
glowStrength: "medium",
colorStyle: "rainbow"
}),
sideBars: Object.freeze({
colorStyle: "multicolor",
barThickness: "thick",
sensitivity: "medium",
barDensity: "medium",
customColors: ["#00f2fe", "#4facfe", "#8ee2ff"],
customThickness: 4,
customGap: 7,
customSensitivity: 30
}),
crimsonDusk: Object.freeze({
barMode: "bottom",
barThickness: "medium",
barCount: "medium",
glowStrength: "medium",
sensitivity: "medium",
filmGrain: "off",
customThickness: 4,
customGap: 7,
customSensitivity: 30
}),
flatRipples: Object.freeze({
mode: "sideRipples",
intensity: "medium",
colorStyle: "blue",
speed: "calm"
}),
dotParticles: Object.freeze({
density: "medium",
motionStyle: "balanced",
directionBehavior: "beatReactive",
glowStrength: "medium"
}),
rippleFlow: Object.freeze({
mode: "sideRipples",
intensity: "medium",
sensitivity: "medium",
colorStyle: "blue"
}),
snowBubbleParticles: Object.freeze({
fallArea: "middle",
density: "medium",
motionStyle: "balanced",
glowStrength: "medium",
particleSize: "medium"
}),
edgeCrystals: Object.freeze({
flutterStyle: "balanced",
density: "medium",
glowStrength: "medium",
colorStyle: "blue",
edgeMode: "both"
}),
sideBraids: Object.freeze({
braidDensity: "medium",
motionStyle: "balanced",
glowStrength: "medium",
braidWidth: "medium",
colorStyle: "cyanPink",
flowDirection: "topDown",
customColors: ["#00e5ff", "#ff2d7b", "#8ee2ff"],
customThickness: 4,
customGap: 7,
customSensitivity: 30,
customSpeed: 30
}),
focusMode: Object.freeze({
enabled: false,
dimOpacity: 0.1,
idleTimeout: 5,
transitionDuration: 1.5
}),
dualTheme: Object.freeze({
enabled: false,
secondaryTheme: "none",
opacity: 0.7
}),
colorModulation: Object.freeze({
enabled: false,
mode: "amplitude",
sensitivity: 1.3,
transitionSpeed: 0.1
}),
auroraDrift: Object.freeze({
// Standard settings
auroraStyle: "cinematic",
intensity: "balanced",
height: "medium",
glowStrength: "medium",
motionSpeed: "balanced",
colorPalette: "cyanViolet",
audioReactivity: "balanced",
softness: "smooth",
layerDensity: "balanced",
// Advanced Custom settings
gradientStops: Object.freeze([
{ pos: 0.0, color: "#00e5ff" },
{ pos: 0.35, color: "#0077ff" },
{ pos: 0.7, color: "#7f00ff" },
{ pos: 1.0, color: "#ff007f" }
]),
baseGlowRadius: 1.0,
peakGlowRadius: 1.0,
crestBrightness: 1.0,
bloomStrength: 1.0,
glowFalloff: 1.0,
primaryFrequency: 1.0,
secondaryFrequency: 1.0,
turbulenceComplexity: 1.0,
motionSmoothness: 1.0,
driftSpeed: 1.0,
bassInfluence: 1.0,
midInfluence: 1.0,
highShimmer: 1.0,
audioSmoothing: 1.0,
peakSensitivity: 1.0,
ribbonHeight: 1.0,
ribbonWidth: 1.0,
edgeSoftness: 1.0,
layerSeparation: 1.0,
crestSharpness: 1.0,
layerCount: 5,
backgroundHaze: 1.0,
foregroundHighlight: 1.0,
parallaxDepth: 1.0,
ambientOpacity: 1.0,
colorSaturation: 1.0,
atmosphericFade: 1.0,
edgeFeathering: 1.0
}),
synthwaveHorizon: Object.freeze({
colorStyle: "outrun",
speed: "balanced",
horizonHeight: "medium",
sunPulse: "on",
glowStrength: "medium",
customThickness: 4,
customGlowStrength: 30,
customSpeed: 30,
customColors: Object.freeze(["#ff007f", "#00f2fe", "#ffe600"])
})
});
const VALID_MAIN_THEMES = new Set(["ambientWave", "reactiveBorder", "flowBorder", "sideBars", "crimsonDusk", "flatRipples", "dotParticles", "rippleFlow", "snowBubbleParticles", "edgeCrystals", "sideBraids", "auroraDrift", "synthwaveHorizon"]);
const VALID_SECONDARY_THEMES = new Set(["none", "ambientWave", "reactiveBorder", "flowBorder", "sideBars", "crimsonDusk", "flatRipples", "dotParticles", "rippleFlow", "snowBubbleParticles", "edgeCrystals", "sideBraids", "auroraDrift", "synthwaveHorizon"]);
const VALID_COLOR_MODES = new Set(["manual", "adaptive", "wallpaper"]);
const VALID_PERFORMANCE_MODES = new Set(["performance", "balanced", "quality"]);
const VALID_FPS_LIMITS = new Set(["default", "battery", "unlocked"]);
const VALID_AMBIENT_TONES = new Set(["blue", "purple", "warm", "custom"]);
const VALID_LEVELS = new Set(["low", "medium", "high", "custom"]);
const VALID_EDGE_MODES = new Set(["top", "bottom", "both"]);
const VALID_GLOW_STRENGTHS = new Set(["soft", "medium", "strong", "custom"]);
const VALID_REACTIVE_COLOR_STYLES = new Set(["rainbow", "neonBlue", "neonPurple", "warmGlow", "custom"]);
const VALID_BORDER_THICKNESS = new Set(["thin", "medium", "thick", "custom"]);
const VALID_FLOW_DIRECTIONS = new Set(["clockwise", "anticlockwise"]);
const VALID_FLOW_SPEEDS = new Set(["calm", "balanced", "energetic", "custom"]);
const VALID_FLOW_SEGMENTS = new Set(["short", "medium", "long", "custom"]);
const VALID_FLOW_COLOR_STYLES = new Set(["rainbow", "cool", "warm", "custom"]);
const VALID_SIDE_BARS_COLOR_STYLES = new Set(["white", "yellow", "aqua", "multicolor", "custom"]);
const VALID_SIDE_BARS_THICKNESS = new Set(["thin", "medium", "thick", "custom"]);
const VALID_SIDE_BARS_DENSITY = new Set(["low", "medium", "high", "custom"]);
const VALID_FLAT_RIPPLES_MODES = new Set(["sideRipples", "flatRipples"]);
const VALID_FLAT_RIPPLES_COLORS = new Set(["red", "blue", "white", "multicolor", "custom"]);
const VALID_FLAT_RIPPLES_SPEEDS = new Set(["calm", "balanced", "energetic", "custom"]);
const VALID_DOT_PARTICLES_MOTION_STYLES = new Set(["calm", "balanced", "energetic", "custom"]);
const VALID_DOT_PARTICLES_DIRECTIONS = new Set(["mostlyClockwise", "mostlyAnticlockwise", "beatReactive"]);
const VALID_RIPPLE_FLOW_MODES = new Set(["sideRipples", "flatRipples"]);
const VALID_RIPPLE_FLOW_COLORS = new Set(["red", "blue", "white", "custom"]);
const VALID_SNOW_FALL_AREAS = new Set(["middle", "fullWidth"]);
const VALID_PARTICLE_SIZES = new Set(["small", "medium", "large", "custom"]);
const VALID_EDGE_FLUTTER_STYLES = new Set(["soft", "balanced", "energetic", "custom"]);
const VALID_EDGE_FLUTTER_COLORS = new Set(["blue", "purple", "red", "white", "custom"]);
const VALID_EDGE_FLUTTER_MODES = new Set(["left", "right", "both"]);
const VALID_BRAID_DENSITY = new Set(["sparse", "medium", "dense", "custom"]);
const VALID_BRAID_WIDTH = new Set(["thin", "medium", "thick", "custom"]);
const VALID_BRAID_MOTION = new Set(["calm", "balanced", "energetic", "custom"]);
const VALID_BRAID_COLORS = new Set(["cyanPink", "bluePurple", "redBlue", "white", "custom"]);
const VALID_BRAID_DIRECTION = new Set(["topDown", "bottomUp"]);
const VALID_AURORA_STYLES = new Set(["ambient", "cinematic", "energetic"]);
const VALID_AURORA_INTENSITIES = new Set(["subtle", "balanced", "vivid"]);
const VALID_AURORA_HEIGHTS = new Set(["low", "medium", "tall"]);
const VALID_AURORA_GLOWS = new Set(["soft", "medium", "strong"]);
const VALID_AURORA_SPEEDS = new Set(["calm", "balanced", "fast"]);
const VALID_AURORA_PALETTES = new Set(["cyanViolet", "emeraldSky", "sunsetDream", "frozenBlue", "monochrome"]);
const VALID_AURORA_AUDIO = new Set(["subtle", "balanced", "responsive"]);
const VALID_AURORA_SOFTNESS = new Set(["misty", "smooth", "defined"]);
const VALID_AURORA_DENSITY = new Set(["light", "balanced", "rich"]);
const VALID_COLOR_MODULATION_MODES = new Set(["amplitude", "beat"]);
const VALID_THEME_AUTOMATION_MODES = new Set(["dayNight"]);
const VALID_SYNTHWAVE_COLOR_STYLES = new Set(["outrun", "sunset", "neonPink", "electricCyan", "custom"]);
const VALID_SYNTHWAVE_SPEEDS = new Set(["calm", "balanced", "energetic", "custom"]);
const VALID_SYNTHWAVE_HORIZON_HEIGHTS = new Set(["low", "medium", "tall"]);
const VALID_SYNTHWAVE_SUN_PULSE = new Set(["on", "off"]);
// Reserved / dangerous keys that must never be used as profile names, since
// they can shadow or pollute Object.prototype when profiles are later spread
// or assigned onto plain objects.
const RESERVED_PROFILE_NAMES = new Set(["__proto__", "constructor", "prototype"]);
// Profile names are restricted to a conservative safe character set
// (letters, numbers, spaces, underscores, hyphens) with a sane length cap.
// This matches the validation already applied to imported backup profiles.
const VALID_PROFILE_NAME_PATTERN = /^[A-Za-z0-9 _-]+$/;
const MAX_PROFILE_NAME_LENGTH = 100;
function createDefaultSettings() {
return {
onboardingSeen: DEFAULT_SETTINGS.onboardingSeen,
launchOnStartup: DEFAULT_SETTINGS.launchOnStartup,
selectedTheme: DEFAULT_SETTINGS.selectedTheme,
colorMode: DEFAULT_SETTINGS.colorMode,
themeAutomation: { ...DEFAULT_SETTINGS.themeAutomation },
shortcuts: { ...DEFAULT_SETTINGS.shortcuts },
performanceMode: DEFAULT_SETTINGS.performanceMode,
focusMode: { ...DEFAULT_SETTINGS.focusMode },
dualTheme: { ...DEFAULT_SETTINGS.dualTheme },
colorModulation: { ...DEFAULT_SETTINGS.colorModulation },
fpsLimit: DEFAULT_SETTINGS.fpsLimit,
ambientWave: { ...DEFAULT_SETTINGS.ambientWave },
reactiveBorder: { ...DEFAULT_SETTINGS.reactiveBorder },
flowBorder: { ...DEFAULT_SETTINGS.flowBorder },
sideBars: { ...DEFAULT_SETTINGS.sideBars },
crimsonDusk: { ...DEFAULT_SETTINGS.crimsonDusk },
flatRipples: { ...DEFAULT_SETTINGS.flatRipples },
dotParticles: { ...DEFAULT_SETTINGS.dotParticles },
rippleFlow: { ...DEFAULT_SETTINGS.rippleFlow },
snowBubbleParticles: { ...DEFAULT_SETTINGS.snowBubbleParticles },
edgeCrystals: { ...DEFAULT_SETTINGS.edgeCrystals },
sideBraids: { ...DEFAULT_SETTINGS.sideBraids },
auroraDrift: { ...DEFAULT_SETTINGS.auroraDrift },
synthwaveHorizon: { ...DEFAULT_SETTINGS.synthwaveHorizon }
};
}
function createThemeDefaults() {
return {
ambientWave: { ...DEFAULT_SETTINGS.ambientWave },
reactiveBorder: { ...DEFAULT_SETTINGS.reactiveBorder },
flowBorder: { ...DEFAULT_SETTINGS.flowBorder },
sideBars: { ...DEFAULT_SETTINGS.sideBars },
crimsonDusk: { ...DEFAULT_SETTINGS.crimsonDusk },
flatRipples: { ...DEFAULT_SETTINGS.flatRipples },
dotParticles: { ...DEFAULT_SETTINGS.dotParticles },
rippleFlow: { ...DEFAULT_SETTINGS.rippleFlow },
snowBubbleParticles: { ...DEFAULT_SETTINGS.snowBubbleParticles },
edgeCrystals: { ...DEFAULT_SETTINGS.edgeCrystals },
sideBraids: { ...DEFAULT_SETTINGS.sideBraids },
auroraDrift: { ...DEFAULT_SETTINGS.auroraDrift },
synthwaveHorizon: { ...DEFAULT_SETTINGS.synthwaveHorizon }
};
}
function pick(value, validValues, fallback) {
return validValues.has(value) ? value : fallback;
}
function legacySensitivityToLevel(value) {
if (!Number.isFinite(value)) {
return "medium";
}
if (value < 2.6) {
return "low";
}
if (value < 4.2) {
return "medium";
}
return "high";
}
// Validates and clamps a custom thickness value (range: 1 to 20, default: 4).
function sanitizeThickness(val, fallback = 4) {
const num = typeof val === "number" ? val : parseInt(val, 10);
return Number.isFinite(num) ? Math.max(1, Math.min(20, num)) : fallback;
}
// Validates and clamps a custom gap value (range: 2 to 30, default: 7).
function sanitizeGap(val, fallback = 7) {
const num = typeof val === "number" ? val : parseInt(val, 10);
return Number.isFinite(num) ? Math.max(2, Math.min(30, num)) : fallback;
}
// Validates and clamps a custom sensitivity value (range: 1 to 100, default: 30).
function sanitizeSensitivity(val, fallback = 30) {
const num = typeof val === "number" ? val : parseInt(val, 10);
return Number.isFinite(num) ? Math.max(1, Math.min(100, num)) : fallback;
}
// Validates and clamps a custom speed value (range: 1 to 100, default: 30).
function sanitizeSpeed(val, fallback = 30) {
const num = typeof val === "number" ? val : parseInt(val, 10);
return Number.isFinite(num) ? Math.max(1, Math.min(100, num)) : fallback;
}
// Validates and clamps a custom glow strength value (range: 1 to 100, default: 30).
function sanitizeCustomGlowStrength(val, fallback = 30) {
const num = typeof val === "number" ? val : parseInt(val, 10);
return Number.isFinite(num) ? Math.max(1, Math.min(100, num)) : fallback;
}
function sanitizeThemeAutomation(input = {}) {
let dayStart = typeof input.dayStartHour === "number"
? input.dayStartHour
: (input.dayStartHour !== undefined ? parseInt(input.dayStartHour, 10) : DEFAULT_SETTINGS.themeAutomation.dayStartHour);
if (isNaN(dayStart) || dayStart < 0 || dayStart > 23) {
dayStart = DEFAULT_SETTINGS.themeAutomation.dayStartHour;
}
let nightStart = typeof input.nightStartHour === "number"
? input.nightStartHour
: (input.nightStartHour !== undefined ? parseInt(input.nightStartHour, 10) : DEFAULT_SETTINGS.themeAutomation.nightStartHour);
if (isNaN(nightStart) || nightStart < 0 || nightStart > 23) {
nightStart = DEFAULT_SETTINGS.themeAutomation.nightStartHour;
}
if (dayStart === nightStart) {
dayStart = DEFAULT_SETTINGS.themeAutomation.dayStartHour;
nightStart = DEFAULT_SETTINGS.themeAutomation.nightStartHour;
}
const interval = typeof input.checkIntervalMinutes === "number"
? input.checkIntervalMinutes
: (typeof input.checkIntervalMinutes === "string" && input.checkIntervalMinutes.trim() !== ""
? Number(input.checkIntervalMinutes)
: NaN);
return {
enabled: typeof input.enabled === "boolean" ? input.enabled : DEFAULT_SETTINGS.themeAutomation.enabled,
checkIntervalMinutes: Number.isFinite(interval)
? Math.max(1, Math.min(120, interval))
: DEFAULT_SETTINGS.themeAutomation.checkIntervalMinutes,
mode: pick(input.mode, VALID_THEME_AUTOMATION_MODES, DEFAULT_SETTINGS.themeAutomation.mode),
dayTheme: pick(input.dayTheme, VALID_MAIN_THEMES, DEFAULT_SETTINGS.themeAutomation.dayTheme),
nightTheme: pick(input.nightTheme, VALID_MAIN_THEMES, DEFAULT_SETTINGS.themeAutomation.nightTheme),
dayStartHour: dayStart,
nightStartHour: nightStart
};
}
function sanitizeAmbientWave(input = {}) {
return {
tone: pick(input.tone, VALID_AMBIENT_TONES, DEFAULT_SETTINGS.ambientWave.tone),
sensitivity: pick(input.sensitivity, VALID_LEVELS, DEFAULT_SETTINGS.ambientWave.sensitivity),
edgeMode: pick(input.edgeMode, VALID_EDGE_MODES, DEFAULT_SETTINGS.ambientWave.edgeMode),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.ambientWave.glowStrength),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.customColors),
customSensitivity: sanitizeSensitivity(input.customSensitivity)
};
}
function sanitizeReactiveBorder(input = {}) {
return {
colorStyle: pick(input.colorStyle, VALID_REACTIVE_COLOR_STYLES, DEFAULT_SETTINGS.reactiveBorder.colorStyle),
intensity: pick(input.intensity, VALID_LEVELS, DEFAULT_SETTINGS.reactiveBorder.intensity),
borderThickness: pick(input.borderThickness, VALID_BORDER_THICKNESS, DEFAULT_SETTINGS.reactiveBorder.borderThickness),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.reactiveBorder.glowStrength),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.customColors),
customThickness: sanitizeThickness(input.customThickness),
customSensitivity: sanitizeSensitivity(input.customSensitivity)
};
}
function sanitizeFlowBorder(input = {}) {
return {
direction: pick(input.direction, VALID_FLOW_DIRECTIONS, DEFAULT_SETTINGS.flowBorder.direction),
speedMode: pick(input.speedMode, VALID_FLOW_SPEEDS, DEFAULT_SETTINGS.flowBorder.speedMode),
segmentLength: pick(input.segmentLength, VALID_FLOW_SEGMENTS, DEFAULT_SETTINGS.flowBorder.segmentLength),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.flowBorder.glowStrength),
colorStyle: pick(input.colorStyle, VALID_FLOW_COLOR_STYLES, DEFAULT_SETTINGS.flowBorder.colorStyle),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.customColors),
customThickness: sanitizeThickness(input.customThickness),
customSensitivity: sanitizeSensitivity(input.customSensitivity),
customSpeed: sanitizeSpeed(input.customSpeed)
};
}
function sanitizeSideBars(input = {}) {
const customColors = sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.sideBars.customColors);
return {
colorStyle: pick(input.colorStyle, VALID_SIDE_BARS_COLOR_STYLES, DEFAULT_SETTINGS.sideBars.colorStyle),
barThickness: pick(input.barThickness, VALID_SIDE_BARS_THICKNESS, DEFAULT_SETTINGS.sideBars.barThickness),
sensitivity: pick(input.sensitivity, VALID_LEVELS, DEFAULT_SETTINGS.sideBars.sensitivity),
barDensity: pick(input.barDensity, VALID_SIDE_BARS_DENSITY, DEFAULT_SETTINGS.sideBars.barDensity),
customColors,
customThickness: sanitizeThickness(input.customThickness, DEFAULT_SETTINGS.sideBars.customThickness),
customGap: sanitizeGap(input.customGap, DEFAULT_SETTINGS.sideBars.customGap),
customSensitivity: sanitizeSensitivity(input.customSensitivity, DEFAULT_SETTINGS.sideBars.customSensitivity)
};
}
function sanitizeCrimsonDusk(input = {}) {
return {
barMode: pick(input.barMode, new Set(["bottom", "bottomCompact", "side", "both"]), DEFAULT_SETTINGS.crimsonDusk.barMode),
barThickness: pick(input.barThickness, new Set(["thin", "medium", "thick", "custom"]), DEFAULT_SETTINGS.crimsonDusk.barThickness),
barCount: pick(input.barCount, new Set(["sparse", "medium", "dense"]), DEFAULT_SETTINGS.crimsonDusk.barCount),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.crimsonDusk.glowStrength),
sensitivity: pick(input.sensitivity, VALID_LEVELS, DEFAULT_SETTINGS.crimsonDusk.sensitivity),
filmGrain: pick(input.filmGrain, new Set(["off", "on"]), DEFAULT_SETTINGS.crimsonDusk.filmGrain),
customThickness: sanitizeThickness(input.customThickness, DEFAULT_SETTINGS.crimsonDusk.customThickness),
customGap: sanitizeGap(input.customGap, DEFAULT_SETTINGS.crimsonDusk.customGap),
customSensitivity: sanitizeSensitivity(input.customSensitivity, DEFAULT_SETTINGS.crimsonDusk.customSensitivity)
};
}
function sanitizeFlatRipples(input = {}) {
return {
mode: pick(input.mode, VALID_FLAT_RIPPLES_MODES, DEFAULT_SETTINGS.flatRipples.mode),
intensity: pick(input.intensity, VALID_LEVELS, DEFAULT_SETTINGS.flatRipples.intensity),
colorStyle: pick(input.colorStyle, VALID_FLAT_RIPPLES_COLORS, DEFAULT_SETTINGS.flatRipples.colorStyle),
speed: pick(input.speed, VALID_FLAT_RIPPLES_SPEEDS, DEFAULT_SETTINGS.flatRipples.speed),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.customColors),
customSensitivity: sanitizeSensitivity(input.customSensitivity),
customSpeed: sanitizeSpeed(input.customSpeed)
};
}
function sanitizeDotParticles(input = {}) {
return {
density: pick(input.density, VALID_LEVELS, DEFAULT_SETTINGS.dotParticles.density),
motionStyle: pick(input.motionStyle, VALID_DOT_PARTICLES_MOTION_STYLES, DEFAULT_SETTINGS.dotParticles.motionStyle),
directionBehavior: pick(input.directionBehavior, VALID_DOT_PARTICLES_DIRECTIONS, DEFAULT_SETTINGS.dotParticles.directionBehavior),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.dotParticles.glowStrength),
customGap: sanitizeGap(input.customGap),
customSpeed: sanitizeSpeed(input.customSpeed)
};
}
function sanitizeRippleFlow(input = {}) {
return {
mode: pick(input.mode, VALID_RIPPLE_FLOW_MODES, DEFAULT_SETTINGS.rippleFlow.mode),
intensity: pick(input.intensity, VALID_LEVELS, DEFAULT_SETTINGS.rippleFlow.intensity),
sensitivity: pick(input.sensitivity, VALID_LEVELS, DEFAULT_SETTINGS.rippleFlow.sensitivity),
colorStyle: pick(input.colorStyle, VALID_RIPPLE_FLOW_COLORS, DEFAULT_SETTINGS.rippleFlow.colorStyle),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.customColors),
customSensitivity: sanitizeSensitivity(input.customSensitivity)
};
}
function sanitizeSnowBubbleParticles(input = {}) {
return {
fallArea: pick(input.fallArea, VALID_SNOW_FALL_AREAS, DEFAULT_SETTINGS.snowBubbleParticles.fallArea),
density: pick(input.density, VALID_LEVELS, DEFAULT_SETTINGS.snowBubbleParticles.density),
motionStyle: pick(input.motionStyle, VALID_DOT_PARTICLES_MOTION_STYLES, DEFAULT_SETTINGS.snowBubbleParticles.motionStyle),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.snowBubbleParticles.glowStrength),
particleSize: pick(input.particleSize, VALID_PARTICLE_SIZES, DEFAULT_SETTINGS.snowBubbleParticles.particleSize)
};
}
function sanitizeEdgeCrystals(input = {}) {
return {
flutterStyle: pick(input.flutterStyle, VALID_EDGE_FLUTTER_STYLES, DEFAULT_SETTINGS.edgeCrystals.flutterStyle),
density: pick(input.density, VALID_LEVELS, DEFAULT_SETTINGS.edgeCrystals.density),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.edgeCrystals.glowStrength),
colorStyle: pick(input.colorStyle, VALID_EDGE_FLUTTER_COLORS, DEFAULT_SETTINGS.edgeCrystals.colorStyle),
edgeMode: pick(input.edgeMode, VALID_EDGE_FLUTTER_MODES, DEFAULT_SETTINGS.edgeCrystals.edgeMode),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.customColors),
customGap: sanitizeGap(input.customGap),
customSensitivity: sanitizeSensitivity(input.customSensitivity),
customSpeed: sanitizeSpeed(input.customSpeed)
};
}
function sanitizeSideBraids(input = {}) {
return {
braidDensity: pick(input.braidDensity, VALID_BRAID_DENSITY, DEFAULT_SETTINGS.sideBraids.braidDensity),
motionStyle: pick(input.motionStyle, VALID_BRAID_MOTION, DEFAULT_SETTINGS.sideBraids.motionStyle),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.sideBraids.glowStrength),
braidWidth: pick(input.braidWidth, VALID_BRAID_WIDTH, DEFAULT_SETTINGS.sideBraids.braidWidth),
colorStyle: pick(input.colorStyle, VALID_BRAID_COLORS, DEFAULT_SETTINGS.sideBraids.colorStyle),
flowDirection: pick(input.flowDirection, VALID_BRAID_DIRECTION, DEFAULT_SETTINGS.sideBraids.flowDirection),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.sideBraids.customColors),
customThickness: sanitizeThickness(input.customThickness, DEFAULT_SETTINGS.sideBraids.customThickness),
customGap: sanitizeGap(input.customGap, DEFAULT_SETTINGS.sideBraids.customGap),
customSensitivity: sanitizeSensitivity(input.customSensitivity, DEFAULT_SETTINGS.sideBraids.customSensitivity),
customSpeed: sanitizeSpeed(input.customSpeed, DEFAULT_SETTINGS.sideBraids.customSpeed)
};
}
function sanitizeAuroraDrift(input = {}) {
function sanitizeNum(val, fallback, min = 0.0, max = 5.0) {
const num = parseFloat(val);
return Number.isFinite(num) ? Math.max(min, Math.min(max, num)) : fallback;
}
let stops = DEFAULT_SETTINGS.auroraDrift.gradientStops;
if (Array.isArray(input.gradientStops)) {
const parsedStops = input.gradientStops
.map(stop => {
const pos = Math.max(0.0, Math.min(1.0, parseFloat(stop?.pos)));
const color = typeof stop?.color === "string" && /^#[0-9a-fA-F]{6}$/.test(stop.color)
? stop.color
: "#ffffff";
return { pos, color };
})
.filter(stop => Number.isFinite(stop.pos))
.sort((a, b) => a.pos - b.pos);
if (parsedStops.length >= 2 && parsedStops.length <= 6) {
stops = parsedStops;
}
}
return {
auroraStyle: pick(input.auroraStyle, VALID_AURORA_STYLES, DEFAULT_SETTINGS.auroraDrift.auroraStyle),
intensity: pick(input.intensity, VALID_AURORA_INTENSITIES, DEFAULT_SETTINGS.auroraDrift.intensity),
height: pick(input.height, VALID_AURORA_HEIGHTS, DEFAULT_SETTINGS.auroraDrift.height),
glowStrength: pick(input.glowStrength, VALID_AURORA_GLOWS, DEFAULT_SETTINGS.auroraDrift.glowStrength),
motionSpeed: pick(input.motionSpeed, VALID_AURORA_SPEEDS, DEFAULT_SETTINGS.auroraDrift.motionSpeed),
colorPalette: pick(input.colorPalette, VALID_AURORA_PALETTES, DEFAULT_SETTINGS.auroraDrift.colorPalette),
audioReactivity: pick(input.audioReactivity, VALID_AURORA_AUDIO, DEFAULT_SETTINGS.auroraDrift.audioReactivity),
softness: pick(input.softness, VALID_AURORA_SOFTNESS, DEFAULT_SETTINGS.auroraDrift.softness),
layerDensity: pick(input.layerDensity, VALID_AURORA_DENSITY, DEFAULT_SETTINGS.auroraDrift.layerDensity),
gradientStops: stops,
baseGlowRadius: sanitizeNum(input.baseGlowRadius, DEFAULT_SETTINGS.auroraDrift.baseGlowRadius, 0.1, 3.0),
peakGlowRadius: sanitizeNum(input.peakGlowRadius, DEFAULT_SETTINGS.auroraDrift.peakGlowRadius, 0.1, 3.0),
crestBrightness: sanitizeNum(input.crestBrightness, DEFAULT_SETTINGS.auroraDrift.crestBrightness, 0.1, 3.0),
bloomStrength: sanitizeNum(input.bloomStrength, DEFAULT_SETTINGS.auroraDrift.bloomStrength, 0.0, 3.0),
glowFalloff: sanitizeNum(input.glowFalloff, DEFAULT_SETTINGS.auroraDrift.glowFalloff, 0.1, 3.0),
primaryFrequency: sanitizeNum(input.primaryFrequency, DEFAULT_SETTINGS.auroraDrift.primaryFrequency, 0.1, 3.0),
secondaryFrequency: sanitizeNum(input.secondaryFrequency, DEFAULT_SETTINGS.auroraDrift.secondaryFrequency, 0.1, 3.0),
turbulenceComplexity: sanitizeNum(input.turbulenceComplexity, DEFAULT_SETTINGS.auroraDrift.turbulenceComplexity, 0.1, 3.0),
motionSmoothness: sanitizeNum(input.motionSmoothness, DEFAULT_SETTINGS.auroraDrift.motionSmoothness, 0.1, 3.0),
driftSpeed: sanitizeNum(input.driftSpeed, DEFAULT_SETTINGS.auroraDrift.driftSpeed, 0.0, 3.0),
bassInfluence: sanitizeNum(input.bassInfluence, DEFAULT_SETTINGS.auroraDrift.bassInfluence, 0.0, 3.0),
midInfluence: sanitizeNum(input.midInfluence, DEFAULT_SETTINGS.auroraDrift.midInfluence, 0.0, 3.0),
highShimmer: sanitizeNum(input.highShimmer, DEFAULT_SETTINGS.auroraDrift.highShimmer, 0.0, 3.0),
audioSmoothing: sanitizeNum(input.audioSmoothing, DEFAULT_SETTINGS.auroraDrift.audioSmoothing, 0.1, 3.0),
peakSensitivity: sanitizeNum(input.peakSensitivity, DEFAULT_SETTINGS.auroraDrift.peakSensitivity, 0.1, 3.0),
ribbonHeight: sanitizeNum(input.ribbonHeight, DEFAULT_SETTINGS.auroraDrift.ribbonHeight, 0.1, 3.0),
ribbonWidth: sanitizeNum(input.ribbonWidth, DEFAULT_SETTINGS.auroraDrift.ribbonWidth, 0.1, 3.0),
edgeSoftness: sanitizeNum(input.edgeSoftness, DEFAULT_SETTINGS.auroraDrift.edgeSoftness, 0.1, 3.0),
layerSeparation: sanitizeNum(input.layerSeparation, DEFAULT_SETTINGS.auroraDrift.layerSeparation, 0.1, 3.0),
crestSharpness: sanitizeNum(input.crestSharpness, DEFAULT_SETTINGS.auroraDrift.crestSharpness, 0.1, 3.0),
layerCount: Math.round(sanitizeNum(input.layerCount, DEFAULT_SETTINGS.auroraDrift.layerCount, 1, 6)),
backgroundHaze: sanitizeNum(input.backgroundHaze, DEFAULT_SETTINGS.auroraDrift.backgroundHaze, 0.0, 3.0),
foregroundHighlight: sanitizeNum(input.foregroundHighlight, DEFAULT_SETTINGS.auroraDrift.foregroundHighlight, 0.0, 3.0),
parallaxDepth: sanitizeNum(input.parallaxDepth, DEFAULT_SETTINGS.auroraDrift.parallaxDepth, 0.0, 3.0),
ambientOpacity: sanitizeNum(input.ambientOpacity, DEFAULT_SETTINGS.auroraDrift.ambientOpacity, 0.0, 3.0),
colorSaturation: sanitizeNum(input.colorSaturation, DEFAULT_SETTINGS.auroraDrift.colorSaturation, 0.0, 3.0),
atmosphericFade: sanitizeNum(input.atmosphericFade, DEFAULT_SETTINGS.auroraDrift.atmosphericFade, 0.0, 3.0),
edgeFeathering: sanitizeNum(input.edgeFeathering, DEFAULT_SETTINGS.auroraDrift.edgeFeathering, 0.0, 3.0)
};
}
function sanitizeSynthwaveHorizon(input = {}) {
return {
colorStyle: pick(input.colorStyle, VALID_SYNTHWAVE_COLOR_STYLES, DEFAULT_SETTINGS.synthwaveHorizon.colorStyle),
speed: pick(input.speed, VALID_SYNTHWAVE_SPEEDS, DEFAULT_SETTINGS.synthwaveHorizon.speed),
horizonHeight: pick(input.horizonHeight, VALID_SYNTHWAVE_HORIZON_HEIGHTS, DEFAULT_SETTINGS.synthwaveHorizon.horizonHeight),
sunPulse: pick(input.sunPulse, VALID_SYNTHWAVE_SUN_PULSE, DEFAULT_SETTINGS.synthwaveHorizon.sunPulse),
glowStrength: pick(input.glowStrength, VALID_GLOW_STRENGTHS, DEFAULT_SETTINGS.synthwaveHorizon.glowStrength),
customColors: sanitizeCustomColors(input.customColors, DEFAULT_SETTINGS.synthwaveHorizon.customColors),
customThickness: sanitizeThickness(input.customThickness, DEFAULT_SETTINGS.synthwaveHorizon.customThickness),
customGlowStrength: sanitizeCustomGlowStrength(input.customGlowStrength ?? input.customGlow, DEFAULT_SETTINGS.synthwaveHorizon.customGlowStrength),
customSpeed: sanitizeSpeed(input.customSpeed, DEFAULT_SETTINGS.synthwaveHorizon.customSpeed)
};
}
function migrateLegacySettings(input = {}) {
if (VALID_MAIN_THEMES.has(input.selectedTheme) && !input.edgeFlutter) {
return input;
}
const normalizedInput = { ...input };
if (normalizedInput.selectedTheme === "edgeFlutter") {
normalizedInput.selectedTheme = "edgeCrystals";
}
if (normalizedInput.edgeFlutter && !normalizedInput.edgeCrystals) {
normalizedInput.edgeCrystals = normalizedInput.edgeFlutter;
}
if (VALID_MAIN_THEMES.has(normalizedInput.selectedTheme)) {
return normalizedInput;
}
const migrated = createDefaultSettings();
const legacyTheme = normalizedInput.theme;
const legacyLevel = legacySensitivityToLevel(normalizedInput.sensitivity);
migrated.ambientWave.sensitivity = legacyLevel;
if (VALID_EDGE_MODES.has(normalizedInput.edgeMode)) {
migrated.ambientWave.edgeMode = normalizedInput.edgeMode;
}
if (legacyTheme === "purple" || legacyTheme === "warm") {
migrated.ambientWave.tone = legacyTheme;
}
if (legacyTheme === "rainbow") {
migrated.selectedTheme = "reactiveBorder";
migrated.reactiveBorder.intensity = legacyLevel;
} else if (legacyTheme === "flow") {
migrated.selectedTheme = "flowBorder";
} else {
migrated.selectedTheme = "ambientWave";
if (legacyTheme === "blue" || legacyTheme === "purple" || legacyTheme === "warm") {
migrated.ambientWave.tone = legacyTheme;
}
}
return migrated;
}
// Coerces a value to a finite number, accepting numbers as well as numeric
// strings (e.g. "0.4", "20", "2.5"). Returns null when the value cannot be
// interpreted as a finite number, so callers can fall back to a default.
function toFiniteNumber(val) {
if (typeof val === "number") {
return Number.isFinite(val) ? val : null;
}
if (typeof val === "string" && val.trim() !== "") {
const num = Number(val);
return Number.isFinite(num) ? num : null;
}
return null;
}
function sanitizeFocusMode(input = {}) {
const enabled = typeof input.enabled === "boolean" ? input.enabled : DEFAULT_SETTINGS.focusMode.enabled;
const dimOpacityNum = toFiniteNumber(input.dimOpacity);
const dimOpacity = dimOpacityNum !== null
? Math.max(0, Math.min(1, dimOpacityNum))
: DEFAULT_SETTINGS.focusMode.dimOpacity;
const idleTimeoutNum = toFiniteNumber(input.idleTimeout);
const idleTimeout = idleTimeoutNum !== null
? Math.max(1, Math.min(60, idleTimeoutNum))
: DEFAULT_SETTINGS.focusMode.idleTimeout;
const transitionDurationNum = toFiniteNumber(input.transitionDuration);
const transitionDuration = transitionDurationNum !== null
? Math.max(0.1, Math.min(10, transitionDurationNum))
: DEFAULT_SETTINGS.focusMode.transitionDuration;
return { enabled, dimOpacity, idleTimeout, transitionDuration };
}
function sanitizeColorModulation(input = {}) {
const enabled = typeof input.enabled === "boolean" ? input.enabled : DEFAULT_SETTINGS.colorModulation.enabled;
const mode = pick(input.mode, VALID_COLOR_MODULATION_MODES, DEFAULT_SETTINGS.colorModulation.mode);
const sensitivity = typeof input.sensitivity === "number" && Number.isFinite(input.sensitivity)
? Math.max(1.0, Math.min(5.0, input.sensitivity))
: DEFAULT_SETTINGS.colorModulation.sensitivity;
const transitionSpeed = typeof input.transitionSpeed === "number" && Number.isFinite(input.transitionSpeed)
? Math.max(0.01, Math.min(1.0, input.transitionSpeed))
: DEFAULT_SETTINGS.colorModulation.transitionSpeed;
return { enabled, mode, sensitivity, transitionSpeed };
}
function sanitizeDualTheme(input = {}) {
const safeInput = (input && typeof input === "object") ? input : {};
const enabled = typeof safeInput.enabled === "boolean" ? safeInput.enabled : DEFAULT_SETTINGS.dualTheme.enabled;
const secondaryTheme = pick(safeInput.secondaryTheme, VALID_SECONDARY_THEMES, DEFAULT_SETTINGS.dualTheme.secondaryTheme);
const opacityNum = toFiniteNumber(safeInput.opacity);
const opacity = opacityNum !== null
? Math.max(0.1, Math.min(1.0, opacityNum))
: DEFAULT_SETTINGS.dualTheme.opacity;
return { enabled, secondaryTheme, opacity };
}
function sanitizeShortcuts(input) {
const safeInput = (input && typeof input === "object") ? input : {};
const keys = ["togglePause", "toggleHide", "cycleTheme"];
const shortcuts = {
togglePause: typeof safeInput.togglePause === "string" ? safeInput.togglePause : DEFAULT_SETTINGS.shortcuts.togglePause,
toggleHide: typeof safeInput.toggleHide === "string" ? safeInput.toggleHide : DEFAULT_SETTINGS.shortcuts.toggleHide,
cycleTheme: typeof safeInput.cycleTheme === "string" ? safeInput.cycleTheme : DEFAULT_SETTINGS.shortcuts.cycleTheme
};
// Normalize any casing/whitespace variant of "none" (e.g. "none", "NONE",
// " None ") to the canonical "None" sentinel used to mean "no shortcut
// assigned". Without this, Electron may try to register the literal
// string as an accelerator and fail instead of leaving the shortcut unset.
for (const key of keys) {
if (typeof shortcuts[key] === "string" && shortcuts[key].trim().toLowerCase() === "none") {
shortcuts[key] = "None";
}
}
// Resolve duplicates by resetting subsequent duplicate actions to "None"
const seen = new Set();
for (const key of keys) {
const val = shortcuts[key];
if (val && val !== "None") {
const normalized = val.toLowerCase().replace(/\s+/g, "");
if (seen.has(normalized)) {
shortcuts[key] = "None";
} else {
seen.add(normalized);
}
}
}
return shortcuts;
}
function sanitizeSettings(input = {}) {
const source = migrateLegacySettings(input);
const customColors = sanitizeCustomColors(source.customColors, DEFAULT_SETTINGS.customColors);
return {
onboardingSeen: typeof source.onboardingSeen === "boolean" ? source.onboardingSeen : DEFAULT_SETTINGS.onboardingSeen,
launchOnStartup: typeof source.launchOnStartup === "boolean" ? source.launchOnStartup : DEFAULT_SETTINGS.launchOnStartup,
selectedTheme: pick(source.selectedTheme, VALID_MAIN_THEMES, DEFAULT_SETTINGS.selectedTheme),
colorMode: pick(source.colorMode, VALID_COLOR_MODES, DEFAULT_SETTINGS.colorMode),
customColors: customColors,
wallpaperColors: sanitizeCustomColors(source.wallpaperColors, undefined),
themeAutomation: sanitizeThemeAutomation(source.themeAutomation),
shortcuts: sanitizeShortcuts(source.shortcuts),
performanceMode: pick(source.performanceMode, VALID_PERFORMANCE_MODES, DEFAULT_SETTINGS.performanceMode),
fpsLimit: pick(source.fpsLimit, VALID_FPS_LIMITS, DEFAULT_SETTINGS.fpsLimit),
focusMode: sanitizeFocusMode(source.focusMode),
dualTheme: sanitizeDualTheme(source.dualTheme),
colorModulation: sanitizeColorModulation(source.colorModulation),
ambientWave: sanitizeAmbientWave(source.ambientWave),
reactiveBorder: sanitizeReactiveBorder(source.reactiveBorder),
flowBorder: sanitizeFlowBorder(source.flowBorder),
sideBars: sanitizeSideBars(source.sideBars),
crimsonDusk: sanitizeCrimsonDusk(source.crimsonDusk),
flatRipples: sanitizeFlatRipples(source.flatRipples),
dotParticles: sanitizeDotParticles(source.dotParticles),
rippleFlow: sanitizeRippleFlow(source.rippleFlow),
snowBubbleParticles: sanitizeSnowBubbleParticles(source.snowBubbleParticles),
edgeCrystals: sanitizeEdgeCrystals(source.edgeCrystals),
sideBraids: sanitizeSideBraids(source.sideBraids),
auroraDrift: sanitizeAuroraDrift(source.auroraDrift),
synthwaveHorizon: sanitizeSynthwaveHorizon(source.synthwaveHorizon)
};
}
// Validates a theme profile name. Rejects non-strings, empty/overlong names,
// reserved keys that could shadow Object.prototype (__proto__, constructor,
// prototype), and any characters outside the safe allow-list.
function isValidProfileName(name) {
return typeof name === "string" &&
name.length > 0 &&
name.length <= MAX_PROFILE_NAME_LENGTH &&
!RESERVED_PROFILE_NAMES.has(name) &&
VALID_PROFILE_NAME_PATTERN.test(name);
}
// Sanitizes a saved/imported theme-profiles map: drops entries with invalid
// or unsafe names, drops entries whose value isn't a plain object, and runs
// each remaining profile's settings through sanitizeSettings so corrupted or
// hand-edited data can never reach the renderer.
function sanitizeProfiles(profiles) {
if (profiles === null || typeof profiles !== "object" || Array.isArray(profiles)) {
return {};
}
const safeProfiles = {};
for (const name of Object.keys(profiles)) {
if (!isValidProfileName(name)) {
continue;
}
const profile = profiles[name];
if (profile === null || typeof profile !== "object" || Array.isArray(profile)) {
continue;
}
safeProfiles[name] = sanitizeSettings(profile);
}
return safeProfiles;
}
function createSettingsStore(userDataPath) {
const settingsPath = path.join(userDataPath, "settings.json");
const profilesPath = path.join(userDataPath, "themeProfiles.json");
function load() {
try {
if (!fs.existsSync(settingsPath)) {
return createDefaultSettings();
}
const fileContent = fs.readFileSync(settingsPath, "utf8");
const parsed = JSON.parse(fileContent);
const settings = sanitizeSettings(parsed);
// Existing installs before onboarding: do not show the welcome overlay on update.
if (parsed.onboardingSeen === undefined) {
settings.onboardingSeen = true;
}
return settings;
} catch (_error) {
console.error("[Paraline] Failed to load settings from:", settingsPath, _error);
try {
if (fs.existsSync(settingsPath)) {
let backupPath = settingsPath + ".bak";
if (fs.existsSync(backupPath)) {
backupPath = `${settingsPath}.${Date.now()}.bak`;
}
fs.renameSync(settingsPath, backupPath);
console.log(`[Paraline] Corrupted settings backed up to: ${backupPath}`);
}
} catch (backupError) {
console.error("[Paraline] Failed to backup corrupted settings:", backupError);
}
try {
const { app, dialog, Notification } = require("electron");
if (app && app.isReady()) {
// Show dialog warning to user. Use the async dialog.showMessageBox()
// so startup is never blocked by a synchronous modal on headless
// systems or automated environments.
dialog.showMessageBox({
type: "warning",
title: "Settings Reset to Defaults",
message: "Paraline detected a corrupted settings file. Your settings have been reset to defaults.",
detail: `The corrupted file has been backed up, and default settings have been loaded.\n\nError details:\n${_error.message}`,
buttons: ["OK"]
});
// Show tray/system notification
if (Notification.isSupported()) {
new Notification({
title: "Settings Reset to Defaults",
body: "A corrupted settings file was detected. Defaults have been applied."
}).show();
}
}
} catch (notifyError) {
console.error("[Paraline] Failed to notify user about settings corruption:", notifyError);
}
return createDefaultSettings();
}
}
function save(settings) {
const cleanSettings = sanitizeSettings(settings);
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
fs.writeFileSync(settingsPath, JSON.stringify(cleanSettings, null, 2));
return cleanSettings;
}
function loadProfiles() {
try {
if (!fs.existsSync(profilesPath)) {
return {};
}
const fileContent = fs.readFileSync(profilesPath, "utf8");
const parsed = JSON.parse(fileContent);
// JSON.parse can return null, arrays, or primitives. Guard against any
// non-plain-object result so callers always receive a key-value map.
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
return {};
}
// The file can be hand-edited outside the app, so treat its contents
// as untrusted input: drop unsafe/invalid profile names (e.g.
// "__proto__", names with disallowed characters) and sanitize every
// remaining profile's settings before they reach the renderer.
return sanitizeProfiles(parsed);
} catch (_error) {
return {};
}
}
function saveProfiles(profiles) {
fs.mkdirSync(path.dirname(profilesPath), { recursive: true });
fs.writeFileSync(
profilesPath,
JSON.stringify(profiles, null, 2)
);
return profiles;
}
return {
load,
save,
loadProfiles,
saveProfiles,
path: settingsPath,
profilesPath
};
}
module.exports = {
DEFAULT_SETTINGS,
createDefaultSettings,
createThemeDefaults,
createSettingsStore,
sanitizeSettings,
sanitizeProfiles,
isValidProfileName
};