Skip to content

Commit

Permalink
Fix Spotify update detection and improve updating experience
Browse files Browse the repository at this point in the history
  • Loading branch information
Elip100 committed Jan 28, 2025
1 parent 6a526dd commit 1a8576c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SpotMod-dat/data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"mods": []}
{"mods": [], "version": 0.3}
35 changes: 27 additions & 8 deletions inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def patch_spotify(spotify_path, delete_data = False):
extract_xpui(spotify_path)

replace_spotmod_dat()
open(f"{spotify_path}/SpotMod.txt", "w").write("This file tells SpotMod that you have patched Spotify.")

data = json.load(open("SpotMod-dat/data.json"))
data["version"] = utils.version
json.dump(data, open(f"SpotMod-dat/data.json", "w"))

print("Adding JavaScript libraries...")
soup = BeautifulSoup(open("xpui-spa/index.html"), features="lxml")
Expand All @@ -41,7 +44,7 @@ def patch_spotify(spotify_path, delete_data = False):
print_pink("Patch applied!\nPress enter to continue...")
keyboard.wait("Enter")

def unpatch_spotify(spotify_path, delete_data = True):
def unpatch_spotify(spotify_path, delete_data = True, quit_after = True):
utils.clear()
print_blue("Uninstalling SpotMod...")

Expand All @@ -50,7 +53,7 @@ def unpatch_spotify(spotify_path, delete_data = True):
print("Undoing modifications...")

shutil.rmtree("xpui-spa/SpotMod-dat")
os.remove(f"{spotify_path}/SpotMod.txt")
if os.path.exists(f"{spotify_path}/SpotMod.txt"): os.remove(f"{spotify_path}/SpotMod.txt")

soup = BeautifulSoup(open("xpui-spa/index.html"), features="lxml")
soup.find("script", {"src": "SpotMod-dat/loader.js"}).decompose()
Expand All @@ -62,9 +65,10 @@ def unpatch_spotify(spotify_path, delete_data = True):
if delete_data: delete_local_files()
clean_up()

print_pink("SpotMod has been uninstalled.\nPress enter to quit...")
keyboard.wait("Enter")
quit()
if quit_after:
print_pink("SpotMod has been uninstalled.\nPress enter to quit...")
keyboard.wait("Enter")
quit()

def delete_local_files():
print("Deleting local files...")
Expand Down Expand Up @@ -99,8 +103,11 @@ def replace_spotmod_dat():

def clean_up():
print("Cleaning up...")
shutil.rmtree("xpui-spa")
os.remove("xpui.spa")
try:
shutil.rmtree("xpui-spa")
os.remove("xpui.spa")
except:
pass

def add_mod(mod_path, spotify_path):
utils.clear()
Expand Down Expand Up @@ -155,5 +162,17 @@ def toggle_mod(mod_id, mod_ids, spotify_path, enable = True):
compile_xpui(spotify_path)
clean_up()

def get_spotmod_version(spotify_path):
if os.path.exists(f"{spotify_path}/SpotMod.txt"):
return 0.2
extract_xpui(spotify_path)
if os.path.exists("xpui-spa/SpotMod-dat"):
data = json.load(open("xpui-spa/SpotMod-dat/data.json"))["version"]
clean_up()
return data
else:
clean_up()
return None

def quit():
sys.exit()
11 changes: 10 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ def main():
if not data["path"] == "": spotify_path = data["path"]
if not os.path.exists(f"{spotify_path}/Spotify.exe"):
not_installed()
if not os.path.exists(f"{spotify_path}/SpotMod.txt"):
loader_version = inject.get_spotmod_version(spotify_path)
utils.clear()
if loader_version is None:
not_detected()
if loader_version != utils.version:
loader_update_required()
main_menu()

def main_menu():
Expand Down Expand Up @@ -77,6 +81,11 @@ def not_installed():
json.dump(data, open("data.json", "w"))
main()

def loader_update_required():
option_list(["Update", "Quit"], [None, quit], "The SpotMod loader is out of date.\n")
inject.unpatch_spotify(spotify_path, False, False)
inject.patch_spotify(spotify_path, False)

def patch(delete_data = False):
inject.patch_spotify(spotify_path, delete_data)
main()
Expand Down

0 comments on commit 1a8576c

Please sign in to comment.