From a793205cc20c14709edebfd20ec9f3995f183874 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 4 Apr 2025 21:41:34 +1100 Subject: wallpapers: filter by size --- src/config/defaults.ts | 1 + src/config/funcs.ts | 6 +++--- src/config/types.ts | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/config') diff --git a/src/config/defaults.ts b/src/config/defaults.ts index 570ed16..763ccc2 100644 --- a/src/config/defaults.ts +++ b/src/config/defaults.ts @@ -133,6 +133,7 @@ export default { { recursive: true, // Whether to search recursively path: "~/Pictures/Wallpapers", // Path to search + threshold: 0.8, // The threshold to filter wallpapers by size (e.g. 0.8 means wallpaper must be at least 80% of the screen size), 0 to disable }, ], }, diff --git a/src/config/funcs.ts b/src/config/funcs.ts index 5b9efa4..5d8ab44 100644 --- a/src/config/funcs.ts +++ b/src/config/funcs.ts @@ -29,12 +29,12 @@ const isCorrectType = (v: any, type: string | string[] | number[], path: string) v.splice(0, v.length, ...v.filter((item, i) => isCorrectType(item, type, `${path}[${i}]`))); } else { const valid = v.filter((item, i) => - Object.entries(type).some(([k, t]) => { - if (!item[k]) { + Object.entries(type).every(([k, t]) => { + if (!item.hasOwnProperty(k)) { console.warn(`Invalid shape for ${path}[${i}]: ${JSON.stringify(item)} != ${arrType}`); return false; } - return !isCorrectType(item[k], t as any, `${path}[${i}].${k}`); + return isCorrectType(item[k], t as any, `${path}[${i}].${k}`); }) ); v.splice(0, v.length, ...valid); // In-place filter diff --git a/src/config/types.ts b/src/config/types.ts index f5ca03a..0d875ce 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -75,7 +75,7 @@ export default { "gpu.interval": NUM, "memory.interval": NUM, "storage.interval": NUM, - "wallpapers.paths": OBJ_ARR({ recursive: BOOL, path: STR }), + "wallpapers.paths": OBJ_ARR({ recursive: BOOL, path: STR, threshold: NUM }), "calendar.webcals": ARR(STR), "calendar.upcomingDays": NUM, "calendar.notify": BOOL, -- cgit v1.2.3-freya