From 9ee7321c5c992fe7f78f5782b6e2c9536c3e9b5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Phil=20H=C3=B6fer?= <phil.hoefer@suma-ev.de>
Date: Tue, 25 Jul 2023 13:40:47 +0200
Subject: [PATCH] Update checkTokenStash to allow checking without refilling

---
 background.js | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/background.js b/background.js
index 01e53fe..b10c2cd 100644
--- a/background.js
+++ b/background.js
@@ -149,10 +149,11 @@ function getTargetStashSize() {
 }
 
 /**
- * Checks token stash and refills if possible
+ * Checks token stash and tries to refill if refill is set to true
+ * @param {boolean} refill
  * @returns {boolean} True if stash now holds at least as many tokens as the current tokensPerSearch value.
  */
-async function checkTokenStash() {
+async function checkTokenStash(refill) {
   console.log("checking token stash");
   let {
     tokenStash: currentStash,
@@ -169,7 +170,7 @@ async function checkTokenStash() {
   let targetStashSize = getTargetStashSize();
   if (currentStash > refillThresholdSize) {
     return true;
-  } else if (activeKey) {
+  } else if (refill && activeKey) {
     return await refillTokenStash(targetStashSize - currentStash.length);
   } else {
     return false;
@@ -177,10 +178,6 @@ async function checkTokenStash() {
 }
 setTimeout(checkTokenStash,10000);
 
-function tokensAvailable() {
-  return storageGlobal.tokenStash && storageGlobal.tokenStash.length>=tokensPerSearch;
-}
-
 
 function popTokens(count) {
   let tokens = [];
-- 
GitLab