Instance checks and wipe on complete

This commit is contained in:
SimplifiedPrivacy 2026-10-09 14:33:19 -04:00
parent 430696b480
commit 4aa6e2fb8b

View file

@ -20,7 +20,6 @@ MAX_FAILED_CONNECTIONS = 8
class CheckPaidTimer:
_instance = None # CLASS VARIABLE - survives across __init__ calls
@ -48,8 +47,16 @@ class CheckPaidTimer:
self.failed_connections = 0
self.total_attempts = 0
logger.info("Check Paid Timer initialized. Starting polling..")
self.start_polling()
logger.info("Check Paid Timer initialized.")
# self.start_polling()
@classmethod
def get_instance(cls, *args, **kwargs):
if cls._instance is None:
cls(*args, **kwargs)
return cls._instance
def start_polling(self):
logger.info("Starting polling")
@ -65,8 +72,9 @@ class CheckPaidTimer:
self.poll_thread.start()
def stop_polling(self):
"""Stops checking if paid"""
self.is_running = False
"""Stops checking if paid and wipes the instance"""
self.is_running = False # stop checking if paid
CheckPaidTimer._instance = None # wipes instance
logger.info("Polling stopped")
def _poll_loop(self):
@ -101,6 +109,9 @@ class CheckPaidTimer:
print("PAID! Stopping timer")
self.stop_polling()
# Reset instance:
CheckPaidTimer._instance = None
# SAVE:
marked = mark_as_paid(profile_id=self.profile_id)
if not marked.valid:
@ -122,11 +133,13 @@ class CheckPaidTimer:
elif result.error_type == ResultError.INVALID_INPUT:
print("immediately stop, the billing code or other input is invalid")
self.stop_polling()
CheckPaidTimer._instance = None # Reset instance
self.view_callback(paid=False, stopped=True, message=result.message)
# connection error (timed out). Not related to payment status:
elif self.failed_connections > MAX_FAILED_CONNECTIONS:
self.stop_polling()
CheckPaidTimer._instance = None # Reset instance
message = f"Your network connection timed out after {self.failed_connections} failed attempts"
self.view_callback(paid=False, stopped=True, message=message)
@ -141,5 +154,6 @@ class CheckPaidTimer:
print(f"result.error_type is {result.error_type}")
print(f"result.message is {result.error_type}")
self.stop_polling()
CheckPaidTimer._instance = None
self.view_callback(paid=False, stopped=True, message=result.message)