From ded52a0f1d980bb9d9ef82866ab57e1b117ac8cc Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:17:42 +1100 Subject: thumbnailer: add configs --- src/utils/thumbnailer.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/utils/thumbnailer.ts') diff --git a/src/utils/thumbnailer.ts b/src/utils/thumbnailer.ts index 8a879b0..0f9448c 100644 --- a/src/utils/thumbnailer.ts +++ b/src/utils/thumbnailer.ts @@ -1,4 +1,5 @@ -import { execAsync, Gio, GLib } from "astal"; +import { execAsync, GLib, type Variable } from "astal"; +import { thumbnailer as config } from "config"; export interface ThumbOpts { width?: number; @@ -9,19 +10,10 @@ export interface ThumbOpts { export default class Thumbnailer { static readonly thumbnailDir = `${CACHE}/thumbnails`; - static lazy: boolean = true; - static maxAttempts: number = 5; - static timeBetweenAttempts: number = 300; - static defaults: Required = { - width: 100, - height: 100, - exact: true, - }; - static readonly #running = new Set(); static getOpt(opt: T, opts: ThumbOpts) { - return opts[opt] ?? this.defaults[opt]; + return opts[opt] ?? (config.defaults[opt] as Variable>).get(); } static async getThumbPath(path: string, opts: ThumbOpts) { @@ -45,12 +37,12 @@ export default class Thumbnailer { const cropCmd = this.getOpt("exact", opts) ? `-gravity Center -extent ${width}x${height}` : ""; await execAsync(`magick ${path} -thumbnail ${width}x${height}^ ${cropCmd} -unsharp 0x.5 ${thumbPath}`); } catch { - if (attempts >= this.maxAttempts) { + if (attempts >= config.maxAttempts.get()) { console.error(`Failed to generate thumbnail for ${path}`); return path; } - await new Promise(r => setTimeout(r, this.timeBetweenAttempts)); + await new Promise(r => setTimeout(r, config.timeBetweenAttempts.get())); return this.#thumbnail(path, opts, attempts + 1); } @@ -62,9 +54,6 @@ export default class Thumbnailer { let thumbPath = await this.getThumbPath(path, opts); - // If not lazy (i.e. force gen), delete existing thumbnail - if (!this.lazy) Gio.File.new_for_path(thumbPath).delete(null); - // Wait for existing thumbnail for path to finish while (this.#running.has(path)) await new Promise(r => setTimeout(r, 100)); -- cgit v1.2.3-freya