helpers/wallfx.py finds the subject with BiRefNet (onnxruntime, CPU), bakes outline maps per wallpaper and caches them; scans warm the cache in the background. The transition shader gains an outline mode: the line is drawn, the subject fills in, then the rest grows out of it. Uncached or subject-less wallpapers keep the colonies. wallpaper.outlineExclude opts wallpapers out. The Nix package provides the interpreter and the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
158 lines
16 KiB
JavaScript
158 lines
16 KiB
JavaScript
function merge(defaults, user) {
|
||
if (Array.isArray(defaults)) {
|
||
if (user !== undefined && !Array.isArray(user)) throw Error("Expected a configuration array");
|
||
return user === undefined ? defaults.slice() : user.slice();
|
||
}
|
||
if (defaults && typeof defaults === "object") {
|
||
if (user !== undefined && (!user || typeof user !== "object" || Array.isArray(user))) throw Error("Expected a configuration object");
|
||
const result = Object.assign({}, user && typeof user === "object" && !Array.isArray(user) ? user : {});
|
||
for (const key of Object.keys(defaults)) result[key] = merge(defaults[key], result[key]);
|
||
return result;
|
||
}
|
||
return user === undefined ? defaults : user;
|
||
}
|
||
function validate(c) {
|
||
if (!c || typeof c !== "object" || Array.isArray(c)) throw Error("Configuration must be an object");
|
||
if (c.schemaVersion !== 3) throw Error("Unsupported configuration version");
|
||
if (!["system", "custom", "matugen"].includes(c.appearance.accentSource)) throw Error("Invalid accent source");
|
||
if (!/^#[0-9a-fA-F]{6}$/.test(c.appearance.customAccent)) throw Error("Accent must be #RRGGBB");
|
||
if (!/^#[0-9a-fA-F]{6}$/.test(c.appearance.glassTint)) throw Error("Glass tint must be #RRGGBB");
|
||
for (const [key, min, max] of [["glassOpacity",0.15,1],["borderOpacity",0,1],["radius",0,48]]) {
|
||
const n = c.appearance[key];
|
||
if (typeof n !== "number" || !Number.isFinite(n) || n < min || n > max) throw Error("Invalid " + key);
|
||
}
|
||
if (typeof c.animation.reducedMotion !== "boolean" || !Number.isFinite(c.animation.duration) || c.animation.duration < 0 || c.animation.duration > 1000) throw Error("Invalid animation settings");
|
||
if (!Number.isFinite(c.bar.height) || c.bar.height < 32 || c.bar.height > 80 || !Number.isFinite(c.bar.margin) || c.bar.margin < 0 || c.bar.margin > 100) throw Error("Invalid bar geometry");
|
||
if(!Number.isInteger(c.bar.workspaces.count) || c.bar.workspaces.count<1 || c.bar.workspaces.count>20 || !["numbers","roman","dots","pacman"].includes(c.bar.workspaces.style) || ["showDate","use24Hour","showSeconds"].some(k=>typeof c.bar.clock[k]!=="boolean"))throw Error("Invalid bar module options");
|
||
const cava=c.bar.cava;
|
||
if(!cava || !Number.isInteger(cava.bars) || cava.bars<4 || cava.bars>24 || !["bars","mirror"].includes(cava.style) || typeof cava.hideWhenIdle!=="boolean")throw Error("Invalid bar visualizer preferences");
|
||
const validModules = list => {
|
||
const seen = new Set();
|
||
if (!Array.isArray(list)) throw Error("Bar modules must be an array");
|
||
for (const m of list) {
|
||
if (!m || typeof m.id !== "string" || seen.has(m.id) || !["left","center","right"].includes(m.position) || typeof m.enabled !== "boolean") throw Error("Invalid bar module");
|
||
// Optional per-module options (the cog in Settings → Bar).
|
||
if (m.options !== undefined && (!m.options || typeof m.options !== "object" || Array.isArray(m.options))) throw Error("Invalid bar module options");
|
||
seen.add(m.id);
|
||
}
|
||
};
|
||
validModules(c.bar.modules);
|
||
// Per-screen layouts: screen name -> {modules}.
|
||
if (!c.bar.screens || typeof c.bar.screens !== "object" || Array.isArray(c.bar.screens)) throw Error("Invalid per-screen bar layouts");
|
||
for (const name of Object.keys(c.bar.screens)) {
|
||
const entry = c.bar.screens[name];
|
||
if (!name || !entry || typeof entry !== "object") throw Error("Invalid per-screen bar layout");
|
||
validModules(entry.modules);
|
||
}
|
||
if (typeof c.tray.enabled !== "boolean" || typeof c.tray.hoverMenus !== "boolean") throw Error("Invalid tray toggle");
|
||
for (const [key, min, max] of [["hoverDelay", 100, 2000], ["iconSize", 16, 32], ["spacing", 0, 24]]) {
|
||
if (!Number.isInteger(c.tray[key]) || c.tray[key] < min || c.tray[key] > max) throw Error("Invalid tray " + key);
|
||
}
|
||
if (!["pill", "transparent", "icons"].includes(c.tray.background)) throw Error("Invalid tray background");
|
||
if (!["bottom", "left", "right"].includes(c.dock.position) || !["always", "auto", "intelligent"].includes(c.dock.visibility)) throw Error("Invalid dock position/visibility");
|
||
if (typeof c.dock.monitor !== "string" || !c.dock.monitor.length) throw Error("Invalid dock monitor");
|
||
for (const key of ["enabled", "magnification", "showRunningApps", "runningIndicators", "tooltips"]) if (typeof c.dock[key] !== "boolean") throw Error("Invalid dock " + key);
|
||
for (const [key,min,max] of [["iconSize",24,80],["spacing",0,24],["margin",0,80],["magnificationStrength",0,0.8],["animationSpeed",0.25,3]]) {
|
||
if (!Number.isFinite(c.dock[key]) || c.dock[key] < min || c.dock[key] > max) throw Error("Invalid dock " + key);
|
||
}
|
||
if (!Array.isArray(c.dock.pinnedApps) || c.dock.pinnedApps.some(id => typeof id !== "string" || !id.length || id.includes("/")) || new Set(c.dock.pinnedApps.map(id => id.replace(/\.desktop$/i, ""))).size !== c.dock.pinnedApps.length) throw Error("Invalid pinned apps");
|
||
if (!Array.isArray(c.dock.terminalCommand) || c.dock.terminalCommand.some(arg => typeof arg !== "string")) throw Error("Terminal command must be an argument array");
|
||
if (!c.dock.appOverrides || typeof c.dock.appOverrides !== "object" || Array.isArray(c.dock.appOverrides) || Object.values(c.dock.appOverrides).some(id => typeof id !== "string")) throw Error("Invalid app matching overrides");
|
||
if (!Number.isInteger(c.launcher.maxResults) || c.launcher.maxResults<10 || c.launcher.maxResults>100 || !Number.isFinite(c.launcher.width) || c.launcher.width<420 || c.launcher.width>960 || typeof c.launcher.showDescriptions!=="boolean" || typeof c.launcher.recentFiles!=="boolean") throw Error("Invalid launcher preferences");
|
||
for (const key of ["highlights","shadows"]) if(typeof c.appearance[key]!=="boolean")throw Error("Invalid appearance toggle");
|
||
if(!Number.isFinite(c.appearance.panelOpacity) || c.appearance.panelOpacity<0.15 || c.appearance.panelOpacity>1)throw Error("Invalid panel opacity");
|
||
if(!Number.isFinite(c.animation.intensity) || c.animation.intensity<0 || c.animation.intensity>1)throw Error("Invalid animation intensity");
|
||
if(typeof c.matugen.executable!=="string" || !c.matugen.executable.trim() || typeof c.matugen.regenerateOnWallpaperChange!=="boolean" || !Number.isFinite(c.matugen.contrast) || c.matugen.contrast < -1 || c.matugen.contrast>1)throw Error("Invalid Matugen options");
|
||
if(!["scheme-content","scheme-expressive","scheme-fidelity","scheme-fruit-salad","scheme-monochrome","scheme-neutral","scheme-rainbow","scheme-tonal-spot","scheme-vibrant","scheme-smart"].includes(c.matugen.scheme))throw Error("Unsupported Matugen scheme");
|
||
if(!["native","auto","serpantinum","awww","custom"].includes(c.wallpaper.backend) || !Array.isArray(c.wallpaper.directories) || c.wallpaper.directories.some(p=>typeof p!=="string" || !p.length) || !Array.isArray(c.wallpaper.command) || c.wallpaper.command.some(a=>typeof a!=="string") || typeof c.wallpaper.paletteMonitor!=="string")throw Error("Invalid wallpaper preferences");
|
||
if(!c.wallpaper.byMonitor || typeof c.wallpaper.byMonitor!=="object" || Array.isArray(c.wallpaper.byMonitor) || Object.values(c.wallpaper.byMonitor).some(p=>typeof p!=="string"))throw Error("Invalid wallpaper map");
|
||
if(!c.wallpaper.providerPaths || typeof c.wallpaper.providerPaths!=="object" || Array.isArray(c.wallpaper.providerPaths) || Object.values(c.wallpaper.providerPaths).some(p=>typeof p!=="string"))throw Error("Invalid provider wallpaper map");
|
||
for(const key of ["showAlbumArt","showProgress","showAlbum","showCava"])if(typeof c.media[key]!=="boolean")throw Error("Invalid media toggle");
|
||
if(typeof c.media.preferredPlayer!=="string")throw Error("Invalid media preferences");
|
||
const lock=c.lock;
|
||
if(!lock || ["enabled","glass","media","dashboard","notificationPreviews","powerButtons"].some(k=>typeof lock[k]!=="boolean") || !["wallpaper","screenshot"].includes(lock.backdrop) || typeof lock.pamService!=="string" || !/^[A-Za-z0-9._-]{0,64}$/.test(lock.pamService))throw Error("Invalid lock screen preferences");
|
||
const dw=c.desktopWidgets;
|
||
if(!dw || dw.version!==1 || typeof dw.grid!=="boolean" || !Array.isArray(dw.items))throw Error("Invalid desktop widgets");
|
||
const widgetIds=new Set();
|
||
for(const w of dw.items) {
|
||
// Unknown types are preserved (and skipped when rendering) for forward compatibility.
|
||
if(!w || typeof w.id!=="string" || !/^[a-z0-9-]{1,40}$/.test(w.id) || widgetIds.has(w.id) || typeof w.type!=="string" || typeof w.variant!=="string" || typeof w.monitor!=="string" || ![w.x,w.y,w.w,w.h,w.opacity].every(Number.isFinite) || w.w<40 || w.h<40 || w.w>4000 || w.h>4000 || w.opacity<0.1 || w.opacity>1 || (w.options!==undefined && (!w.options || typeof w.options!=="object" || Array.isArray(w.options))))throw Error("Invalid desktop widget");
|
||
widgetIds.add(w.id);
|
||
}
|
||
if(!c.plugins || !Array.isArray(c.plugins.enabled) || c.plugins.enabled.some(id=>typeof id!=="string" || !id))throw Error("Invalid plugin preferences");
|
||
const dash=c.dashboard;
|
||
if(!dash || ["enabled","openFromClock","rememberTab","easyEffects"].some(k=>typeof dash[k]!=="boolean") || !["top-left","top-center","top-right","center"].includes(dash.position) || !Array.isArray(dash.tabs))throw Error("Invalid dashboard preferences");
|
||
const dashTabs=new Set();
|
||
for(const t of dash.tabs) { if(!t || typeof t.id!=="string" || dashTabs.has(t.id) || typeof t.enabled!=="boolean")throw Error("Invalid dashboard tab"); dashTabs.add(t.id); }
|
||
if(typeof c.osd.enabled!=="boolean" || !["slide","drop","fade","shrink"].includes(c.osd.animation) || !["top-right","top-center","bottom-center"].includes(c.osd.position) || !Number.isInteger(c.osd.timeout) || c.osd.timeout<500 || c.osd.timeout>5000 || !Number.isInteger(c.osd.step) || c.osd.step<1 || c.osd.step>20)throw Error("Invalid OSD preferences");
|
||
const notes=c.notifications;
|
||
if(!notes || ["enabled","doNotDisturb","criticalInDnd"].some(k=>typeof notes[k]!=="boolean") || !["slide","drop","fade","shrink"].includes(notes.animation) || !["top-right","top-center"].includes(notes.position) || !Number.isInteger(notes.timeout) || notes.timeout<1000 || notes.timeout>30000 || !Number.isInteger(notes.maxPopups) || notes.maxPopups<1 || notes.maxPopups>6)throw Error("Invalid notification preferences");
|
||
if(c.controlCenter.version !== 2 || !Number.isFinite(c.controlCenter.width) || c.controlCenter.width < 320 || c.controlCenter.width > 600 || !Array.isArray(c.controlCenter.modules))throw Error("Invalid Control Center configuration");
|
||
if(!c.gameMode || ["effects","doNotDisturb","performance"].some(k=>typeof c.gameMode[k]!=="boolean"))throw Error("Invalid Game Mode preferences");
|
||
const controlIds=new Set();
|
||
for(const m of c.controlCenter.modules) { if(!m || typeof m.id!=="string" || controlIds.has(m.id) || typeof m.enabled!=="boolean" || ["w","h"].some(k=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<1 || m[k]>4)) || [["x",3],["y",63]].some(([k,max])=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<0 || m[k]>max)))throw Error("Invalid Control Center module"); controlIds.add(m.id); }
|
||
for(const group of [c.system.brightness,c.system.nightLight]) for(const key of ["statusCommand","setCommand"])if(!Array.isArray(group[key]) || group[key].some(v=>typeof v!=="string" || !v.length))throw Error("Provider command must be an argument array");
|
||
if(typeof c.system.brightness.device!=="string" || !c.system.brightness.device || !Number.isInteger(c.system.nightLight.temperature) || c.system.nightLight.temperature<1000 || c.system.nightLight.temperature>6500 || !Array.isArray(c.system.power.lockCommand) || c.system.power.lockCommand.some(v=>typeof v!=="string" || !v.length))throw Error("Invalid system provider settings");
|
||
if(!Number.isInteger(c.metrics.interval) || c.metrics.interval<1 || c.metrics.interval>30)throw Error("Invalid metrics geometry or interval");
|
||
if(!Array.isArray(c.metrics.storagePaths) || c.metrics.storagePaths.length>8 || c.metrics.storagePaths.some(p=>typeof p!=="string" || !p.startsWith("/") || p.includes("\u0000")) || new Set(c.metrics.storagePaths).size!==c.metrics.storagePaths.length || typeof c.metrics.networkInterface!=="string" || !c.metrics.networkInterface || typeof c.metrics.gpu!=="string" || !c.metrics.gpu)throw Error("Invalid metrics sources");
|
||
if(!Array.isArray(c.wallpaper.history) || c.wallpaper.history.length>50 || c.wallpaper.history.some(p=>typeof p!=="string"))throw Error("Invalid wallpaper history");
|
||
if(!Array.isArray(c.wallpaper.outlineExclude) || c.wallpaper.outlineExclude.some(p=>typeof p!=="string"))throw Error("Invalid wallpaper outline exclusions");
|
||
if(typeof c.hyprglass.enabled!=="boolean" || typeof c.hyprglass.layers!=="boolean" || typeof c.hyprglass.effectEnabled!=="boolean")throw Error("Invalid glass toggle");
|
||
for(const [key,min,max] of [["blur_strength",0,5],["blur_iterations",1,5],["refraction_strength",0,8],["chromatic_aberration",0,1],["fresnel_strength",0,1],["specular_strength",0,1],["edge_thickness",0,.15],["lens_distortion",0,1],["brightness",.2,2],["contrast",.2,2],["saturation",0,2],["vibrancy",0,1],["adaptive_dim",0,1]])if(!Number.isFinite(c.hyprglass.values[key]) || c.hyprglass.values[key]<min || c.hyprglass.values[key]>max)throw Error("Invalid glass "+key);
|
||
if(!Number.isInteger(c.hyprglass.values.blur_iterations))throw Error("Invalid blur passes");
|
||
return c;
|
||
}
|
||
function load(defaults, user) {
|
||
if (!user || typeof user !== "object" || Array.isArray(user)) throw Error("Configuration must be an object");
|
||
const migrated = JSON.parse(JSON.stringify(user));
|
||
const version = migrated.schemaVersion === undefined ? 1 : migrated.schemaVersion;
|
||
if (version !== 1 && version !== 2 && version !== 3) throw Error("Unsupported configuration version");
|
||
if (version === 1) {
|
||
// Preserve every existing module and its order. Insert the newly available tray
|
||
// before system, or append when the user has removed that module.
|
||
if (migrated.bar && Array.isArray(migrated.bar.modules) && !migrated.bar.modules.some(m => m.id === "tray")) {
|
||
const index = migrated.bar.modules.findIndex(m => m.id === "system");
|
||
migrated.bar.modules.splice(index < 0 ? migrated.bar.modules.length : index, 0, {id:"tray", position:"right", enabled:true});
|
||
}
|
||
migrated.schemaVersion = 2;
|
||
}
|
||
if (migrated.controlCenter !== undefined && (!migrated.controlCenter || typeof migrated.controlCenter !== "object" || Array.isArray(migrated.controlCenter))) throw Error("Control Center must be an object");
|
||
// Phase 1–6 saved an unused empty list. Migrate it exactly once; retain
|
||
// nonempty custom layouts and deliberate empty layouts after version 1.
|
||
if (!migrated.controlCenter || migrated.controlCenter.version === undefined) {
|
||
migrated.controlCenter = Object.assign({}, migrated.controlCenter || {});
|
||
if (migrated.controlCenter.modules === undefined || (Array.isArray(migrated.controlCenter.modules) && migrated.controlCenter.modules.length === 0))
|
||
migrated.controlCenter.modules = defaults.controlCenter.modules;
|
||
migrated.controlCenter.version = 1;
|
||
}
|
||
// Version 2 lays modules on a grid: the combined Connectivity and Audio
|
||
// cards split into their own tiles, in place, and Caffeine is offered.
|
||
if (migrated.controlCenter.version === 1 && Array.isArray(migrated.controlCenter.modules)) {
|
||
const parts = {connectivity: ["wifi", "bluetooth", "network"], audio: ["output", "input"]};
|
||
const old = migrated.controlCenter.modules, modules = [];
|
||
for (const m of old) {
|
||
if (!m || !parts[m.id]) {
|
||
modules.push(m);
|
||
continue;
|
||
}
|
||
for (const id of parts[m.id])
|
||
if (!old.some(o => o && o.id === id) && !modules.some(o => o && o.id === id))
|
||
modules.push({id: id, enabled: m.enabled});
|
||
}
|
||
if (old.length && !modules.some(m => m && m.id === "caffeine"))
|
||
modules.push({id: "caffeine", enabled: true});
|
||
migrated.controlCenter = Object.assign({}, migrated.controlCenter, {version: 2, modules: modules});
|
||
}
|
||
migrated.schemaVersion = 3;
|
||
return validate(merge(defaults, migrated));
|
||
}
|
||
function update(config, path, value) {
|
||
const result = JSON.parse(JSON.stringify(config));
|
||
const keys = path.split(".");
|
||
if (keys.some(k => ["__proto__","constructor","prototype"].includes(k))) throw Error("Invalid setting path");
|
||
let target = result;
|
||
for (let i = 0; i < keys.length - 1; ++i) target = target[keys[i]];
|
||
target[keys[keys.length - 1]] = value;
|
||
return validate(result);
|
||
}
|