summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-04 21:41:34 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-04 21:41:34 +1100
commita793205cc20c14709edebfd20ec9f3995f183874 (patch)
treeb436bec863329afdf8fa937f9ddd5924088293db /src/services
parentfeat: uwsm app -> app2unit (diff)
downloadcaelestia-shell-a793205cc20c14709edebfd20ec9f3995f183874.tar.gz
caelestia-shell-a793205cc20c14709edebfd20ec9f3995f183874.tar.bz2
caelestia-shell-a793205cc20c14709edebfd20ec9f3995f183874.zip
wallpapers: filter by size
Diffstat (limited to 'src/services')
-rw-r--r--src/services/wallpapers.ts30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/services/wallpapers.ts b/src/services/wallpapers.ts
index f1f13a5..77b22ad 100644
--- a/src/services/wallpapers.ts
+++ b/src/services/wallpapers.ts
@@ -2,6 +2,7 @@ import { monitorDirectory } from "@/utils/system";
import Thumbnailer from "@/utils/thumbnailer";
import { execAsync, GObject, property, register } from "astal";
import { wallpapers as config } from "config";
+import Monitors from "./monitors";
export interface IWallpaper {
path: string;
@@ -35,10 +36,35 @@ export default class Wallpapers extends GObject.Object {
return this.#categories;
}
- #listDir(path: { path: string; recursive: boolean }, type: "f" | "d") {
+ async #listDir(path: { path: string; recursive: boolean; threshold: number }, type: "f" | "d") {
const absPath = path.path.replace("~", HOME);
const maxDepth = path.recursive ? "" : "-maxdepth 1";
- return execAsync(`find ${absPath} ${maxDepth} -path '*/.*' -prune -o -type ${type} -print`);
+ const files = await execAsync(`find ${absPath} ${maxDepth} -path '*/.*' -prune -o -type ${type} -print`);
+
+ if (path.threshold > 0) {
+ const data = (
+ await execAsync([
+ "fish",
+ "-c",
+ `identify -ping -format '%i %w %h\n' ${files.replaceAll("\n", " ")} ; true`,
+ ])
+ ).split("\n");
+
+ return data
+ .filter(l => l && this.#filterSize(l, path.threshold))
+ .map(l => l.split(" ").slice(0, -2).join(" "))
+ .join("\n");
+ }
+
+ return files;
+ }
+
+ #filterSize(line: string, threshold: number) {
+ const [width, height] = line.split(" ").slice(-2).map(Number);
+ const mWidth = Math.max(...Monitors.get_default().list.map(m => m.width));
+ const mHeight = Math.max(...Monitors.get_default().list.map(m => m.height));
+
+ return width >= mWidth * threshold && height >= mHeight * threshold;
}
async update() {