From 2d979684453659318daf794febafb0887a12fb50 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 22 Feb 2025 20:35:20 +1100 Subject: config: dynamic service confs --- src/services/math.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/services/math.ts') diff --git a/src/services/math.ts b/src/services/math.ts index 5c7dfce..f5807ef 100644 --- a/src/services/math.ts +++ b/src/services/math.ts @@ -17,7 +17,6 @@ export default class Math extends GObject.Object { return this.instance; } - readonly #maxHistory = config.maxHistory; readonly #path = `${STATE}/math-history.json`; readonly #history: HistoryItem[] = []; @@ -42,7 +41,7 @@ export default class Math extends GObject.Object { // Try select first to prevent duplicates, if it fails, add it if (!this.select(this.#lastExpression)) { this.#history.unshift(this.#lastExpression); - if (this.#history.length > this.#maxHistory) this.#history.pop(); + while (this.#history.length > config.maxHistory.get()) this.#history.pop(); this.notify("history"); this.#save(); } @@ -148,5 +147,9 @@ export default class Math extends GObject.Object { console.error("Math - Unable to load history", e); } } + + config.maxHistory.subscribe(n => { + while (this.#history.length > n) this.#history.pop(); + }); } } -- cgit v1.2.3-freya