-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncherConfig.js
More file actions
95 lines (83 loc) · 3.48 KB
/
Copy pathLauncherConfig.js
File metadata and controls
95 lines (83 loc) · 3.48 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
// Config merge for LauncherPlease: file config (~/.config/omarchy/launcherplease.json)
// overrides defaults, IPC payload overrides the file. Pure for node --test.
var DEFAULTS = {
columns: 8,
layout: "compact",
showChords: true,
showCategories: true,
captureChords: true,
duration: 0,
groupOrder: ["Most used", "Web apps", "Games", "Development", "Office", "Multimedia", "Internet", "System", "TUIs", "Apps"],
favorites: [],
exclude: [],
categories: {},
mostUsedCount: 8,
mostUsedDays: 14,
effects: { pulse: true, glow: true, bounce: true }
}
function parseJson(raw, fallback) {
try {
return JSON.parse(String(raw || ""))
} catch (e) {
return fallback
}
}
function isObject(v) {
return v !== null && typeof v === "object" && !Array.isArray(v)
}
function boolOr(value, fallback) {
if (value === undefined || value === null) return fallback
return !!value
}
function numberOr(value, fallback) {
var n = Number(value)
return isFinite(n) && n >= 0 ? n : fallback
}
function layoutOr(value, fallback) {
if (value === "roomy" || value === "compact") return value
return fallback
}
function stringArray(value) {
if (!Array.isArray(value)) return []
var out = []
for (var i = 0; i < value.length; i++) {
var v = String(value[i] || "").trim()
if (v) out.push(v)
}
return out
}
function mergeEffects(fileEffects, payloadEffects) {
var base = isObject(fileEffects) ? fileEffects : {}
var extra = isObject(payloadEffects) ? payloadEffects : {}
return {
pulse: boolOr(extra.pulse, boolOr(base.pulse, DEFAULTS.effects.pulse)),
glow: boolOr(extra.glow, boolOr(base.glow, DEFAULTS.effects.glow)),
bounce: boolOr(extra.bounce, boolOr(base.bounce, DEFAULTS.effects.bounce))
}
}
function merge(fileRaw, payloadRaw) {
var file = parseJson(fileRaw, {})
if (!isObject(file)) file = {}
var payload = parseJson(payloadRaw, {})
if (!isObject(payload)) payload = {}
var groupOrder = Array.isArray(file.groupOrder) ? stringArray(file.groupOrder) : DEFAULTS.groupOrder
if (groupOrder.length === 0) groupOrder = DEFAULTS.groupOrder
return {
columns: Math.max(1, Math.floor(numberOr(payload.columns, numberOr(file.columns, DEFAULTS.columns)))),
layout: layoutOr(payload.layout, layoutOr(file.layout, DEFAULTS.layout)),
showChords: boolOr(payload.showChords, boolOr(file.showChords, DEFAULTS.showChords)),
showCategories: boolOr(payload.showCategories, boolOr(file.showCategories, DEFAULTS.showCategories)),
captureChords: boolOr(payload.captureChords, boolOr(file.captureChords, DEFAULTS.captureChords)),
duration: numberOr(payload.duration, numberOr(file.duration, DEFAULTS.duration)),
groupOrder: stringArray(payload.groupOrder).length ? stringArray(payload.groupOrder) : groupOrder,
favorites: stringArray(payload.favorites).length ? stringArray(payload.favorites) : stringArray(file.favorites),
exclude: stringArray(file.exclude),
categories: isObject(file.categories) ? file.categories : {},
mostUsedCount: Math.max(0, Math.floor(numberOr(payload.mostUsedCount, numberOr(file.mostUsedCount, DEFAULTS.mostUsedCount)))),
mostUsedDays: Math.max(1, Math.floor(numberOr(payload.mostUsedDays, numberOr(file.mostUsedDays, DEFAULTS.mostUsedDays)))),
effects: mergeEffects(file.effects, payload.effects)
}
}
if (typeof module !== "undefined" && module.exports) {
module.exports = { DEFAULTS: DEFAULTS, parseJson: parseJson, boolOr: boolOr, numberOr: numberOr, stringArray: stringArray, layoutOr: layoutOr, merge: merge }
}