diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-04-01 13:36:23 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-04-01 13:36:23 +1100 |
| commit | d05b124609ca56c99ff9ef32aa2e5217bcde295e (patch) | |
| tree | 1cb164dbf4b9bac9f41296e19c6c666a16487cb3 /src/services/wallpapers.ts | |
| parent | cleanup: dispose of file monitors when unneeded (diff) | |
| download | caelestia-shell-d05b124609ca56c99ff9ef32aa2e5217bcde295e.tar.gz caelestia-shell-d05b124609ca56c99ff9ef32aa2e5217bcde295e.tar.bz2 caelestia-shell-d05b124609ca56c99ff9ef32aa2e5217bcde295e.zip | |
feat: thumbnailer utility
Fix large images in notifications being slow
GTK css background image is really slow for scaling for some reason, so thumbnail
Diffstat (limited to 'src/services/wallpapers.ts')
| -rw-r--r-- | src/services/wallpapers.ts | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/services/wallpapers.ts b/src/services/wallpapers.ts index 4c7c49b..f0a68af 100644 --- a/src/services/wallpapers.ts +++ b/src/services/wallpapers.ts @@ -1,6 +1,6 @@ -import { basename } from "@/utils/strings"; import { monitorDirectory } from "@/utils/system"; -import { execAsync, GLib, GObject, property, register } from "astal"; +import Thumbnailer from "@/utils/thumbnailer"; +import { execAsync, GObject, property, register } from "astal"; import { wallpapers as config } from "config"; export interface IWallpaper { @@ -22,8 +22,6 @@ export default class Wallpapers extends GObject.Object { return this.instance; } - #thumbnailDir = `${CACHE}/thumbnails`; - #list: IWallpaper[] = []; #categories: ICategory[] = []; @@ -37,14 +35,6 @@ export default class Wallpapers extends GObject.Object { return this.#categories; } - async #thumbnail(path: string) { - const dir = path.slice(1, path.lastIndexOf("/")).replaceAll("/", "-"); - const thumbPath = `${this.#thumbnailDir}/${dir}-${basename(path)}.jpg`; - if (!GLib.file_test(thumbPath, GLib.FileTest.EXISTS)) - await execAsync(`magick -define jpeg:size=1000x500 ${path} -thumbnail 500x250 -unsharp 0x.5 ${thumbPath}`); - return thumbPath; - } - #listDir(path: { path: string; recursive: boolean }, type: "f" | "d") { const absPath = path.path.replace("~", HOME); const maxDepth = path.recursive ? "" : "-maxdepth 1"; @@ -68,7 +58,7 @@ export default class Wallpapers extends GObject.Object { const files = successes.map(r => r.files.replaceAll("\n", " ")).join(" "); const list = (await execAsync(["fish", "-c", `identify -ping -format '%i\n' ${files} ; true`])).split("\n"); - this.#list = await Promise.all(list.map(async p => ({ path: p, thumbnail: await this.#thumbnail(p) }))); + this.#list = await Promise.all(list.map(async p => ({ path: p, thumbnail: await Thumbnailer.thumbnail(p) }))); this.notify("list"); const categories = await Promise.all(successes.map(r => this.#listDir(r.path, "d"))); @@ -82,8 +72,6 @@ export default class Wallpapers extends GObject.Object { constructor() { super(); - GLib.mkdir_with_parents(this.#thumbnailDir, 0o755); - this.update().catch(console.error); let monitors = config.paths |