** MAJOR speed improvements **

Refactored code for TRUE multithreaded performance
startup time decreased from 2 secs to 0.2 secs
updates song time decreased from 3 secs to 0.1 secs
introduced proper and full error handler, can fully recover from errors
(including performing a full restart)
implemented web server to push updates and restart application (flask)
getting lyrics is truely mulithreaded now, all in memory.
This commit is contained in:
Brandon4466
2023-05-25 17:25:20 -07:00
parent 90b1448d93
commit 1e40570d57
8 changed files with 251 additions and 113 deletions

View File

@@ -4,6 +4,9 @@ from zipfile import ZipFile
from io import BytesIO
from time import sleep
import subprocess
from pynput import mouse
from functools import partial
from os import name, path, remove
# while True:
@@ -14,6 +17,9 @@ import subprocess
# except:
# pass
if name == 'nt':
print("Windows detected. Shutting down...")
exit()
# try:
# print("Checking for updates...")
@@ -24,21 +30,38 @@ import subprocess
# print("No update available.")
# pass
def click(x, y, button, pressed, foo):
return False
bar = partial(click, foo="bar", button=True, pressed=True)
while True:
try:
urlopen('http://bbrunson.com', timeout=1)
print("Connection to server established.")
try:
if path.exists('web/update/update.zip'):
print("Update found. Installing...")
with ZipFile('web/update/update.zip') as zipObj:
zipObj.extractall()
remove('web/update/update.zip')
print("Uploaded update successfully installed.")
print("Checking for updates...")
with ZipFile(BytesIO((urlopen('http://files.bbrunson.com/spotify-gui/update.zip')).read())) as zipObj:
zipObj.extractall()
print("Update successfully installed.")
print("Update successfully downloaded and installed.")
except urllib.error.HTTPError:
print("No update available.")
pass
subprocess.Popen(['python3', 'web/web.py'])
subprocess.check_call(['python3', 'spotifycontroller.py'])
except:
print("An error has ocurred, checking server connection, checking for update, and then reestablishing the application in 10 seconds.")
sleep(10)
except Exception as e:
if e.args[0] == 1:
print("Program has requested sleep mode.")
with mouse.Listener(on_move=bar, on_click=bar, on_scroll=bar) as listener:
listener.join()
else:
print(e)
print("Restart procedure initiated: Checking server connection, checking for update, and then reestablishing the application in 10 seconds.")
sleep(10)
continue