diff options
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/modules/xbox.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/deckit/modules/xbox.py b/deckit/modules/xbox.py index bd2fd6e..60f402e 100644 --- a/deckit/modules/xbox.py +++ b/deckit/modules/xbox.py @@ -72,6 +72,7 @@ COMMANDS = { FAST = 30 # seconds between presence and console reads SLOW = 600 # seconds between profile, games, achievements and friends reads +QUICK, QUICK_FOR = 3, 30 # after a command: read every 3s for 30s, until the power state follows # ponytail: renewed by age, not by the XSTS NotAfter (about 16h); a 401 renews early too. XSTS_FOR = 8 * 3600 TITLES = 12 # recent games shown @@ -245,6 +246,7 @@ class Xbox: self.status_lock = threading.Lock() self.slow_at, self.slow_title = None, None self.wake, self.stopping = threading.Event(), False + self.quick_until = 0.0 # read every QUICK seconds until then # --- the refresh token file ---------------------------------------- def _load(self): @@ -512,16 +514,20 @@ class Xbox: raise ModuleError("The console is not reachable from Xbox Live: turn it on by hand once, then retry.") if status.get("errorCode", "OK") != "OK": raise ModuleError(status.get("errorMessage") or status["errorCode"]) + self.quick_until = time.monotonic() + QUICK_FOR self.wake.set() # --- the reader thread ---------------------------------------------- + def next_read(self) -> float: + return QUICK if time.monotonic() < self.quick_until else FAST + def run(self): while not self.stopping: try: self.tick() except Exception as e: self.offline, self.reason = True, str(e) - self.wake.wait(FAST) + self.wake.wait(self.next_read()) self.wake.clear() def start(self): |
