@@ -527,8 +527,51 @@ def login():
527527 # Keep browser alive for Unity deep link redirect
528528 # driver.quit()
529529
530- def open_sample_app ():
530+ def clear_unity_data ():
531+ """Clear Unity's persistent data to force fresh start"""
532+ print ("Clearing Unity persistent data..." )
533+
534+ # Clear PlayerPrefs from Windows Registry
535+ try :
536+ import winreg
537+ registry_path = r"SOFTWARE\Immutable\Immutable Sample"
538+
539+ # Try both HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE
540+ for root_key in [winreg .HKEY_CURRENT_USER , winreg .HKEY_LOCAL_MACHINE ]:
541+ try :
542+ winreg .DeleteKey (root_key , registry_path )
543+ print (f"Cleared PlayerPrefs from registry: { root_key } " )
544+ except FileNotFoundError :
545+ pass # Key doesn't exist, that's fine
546+ except Exception as e :
547+ print (f"Could not clear registry { root_key } : { e } " )
548+
549+ except ImportError :
550+ print ("Windows registry module not available" )
551+ except Exception as e :
552+ print (f"Error clearing registry: { e } " )
553+
554+ # Clear Application.persistentDataPath
555+ try :
556+ data_path = os .path .join (os .path .expanduser ("~" ), "AppData" , "LocalLow" , "Immutable" , "Immutable Sample" )
557+ if os .path .exists (data_path ):
558+ import shutil
559+ shutil .rmtree (data_path )
560+ print (f"Cleared persistent data folder: { data_path } " )
561+ else :
562+ print (f"No persistent data folder found at: { data_path } " )
563+ except Exception as e :
564+ print (f"Error clearing persistent data: { e } " )
565+
566+ print ("Unity data cleanup complete" )
567+
568+ def open_sample_app (clear_data = False ):
531569 product_name = get_product_name ()
570+
571+ # Clear any cached login state before opening (only when requested)
572+ if clear_data :
573+ clear_unity_data ()
574+
532575 print (f"Opening { product_name } ..." )
533576 subprocess .Popen ([f"{ product_name } .exe" ], shell = True )
534577 time .sleep (10 )
0 commit comments