Skip to content

Commit 5dc35ad

Browse files
committed
fix(desk): cache token in case of program crash
1 parent 42a43ed commit 5dc35ad

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

python/rcsss/control/fr3_desk.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hashlib
44
import json as json_module
55
import logging
6+
import os
67
import ssl
78
import threading
89
import time
@@ -298,6 +299,16 @@ def take_control(self, force: bool = False) -> bool:
298299
"""
299300
active = self._get_active_token()
300301

302+
# try to read token from cache file
303+
token_path = os.path.expanduser('~/.cache/rcs_fr3_token')
304+
if active.id != "" and self._token.id == "" and os.path.exists(token_path):
305+
with open(token_path, "r") as f:
306+
content = f.read()
307+
content = content.split("/n")
308+
self._token = Token(content[0], content[1], content[2])
309+
310+
311+
301312
# we already have control
302313
if active.id != "" and self._token.id == active.id:
303314
_logger.info("Retaken control.")
@@ -334,12 +345,14 @@ def take_control(self, force: bool = False) -> bool:
334345
if event["circle"]:
335346
break
336347
self._token = Token(str(response["id"]), self._username, response["token"])
348+
with open(token_path, "w") as f:
349+
f.write("/n".join([self._token.id, self._token.owned_by, self._token.token]))
337350
_logger.info("Taken control.")
338351
return True
339352

340353
def release_control(self) -> None:
341354
"""
342-
Explicitly relinquish control of the Desk. This will allow
355+
Explicitly relinquish cofilentrol of the Desk. This will allow
343356
other users to take control or transfer control to the next
344357
user if there is an active queue of control requests.
345358
"""

0 commit comments

Comments
 (0)