Skip to content

Commit eb7926a

Browse files
committed
Update update_page.py
update_async edit
1 parent 43c3e70 commit eb7926a

1 file changed

Lines changed: 38 additions & 12 deletions

File tree

src/gui/pages/update_page.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import shutil
23
from tkinter import messagebox
34
import aiohttp
45
import webbrowser
@@ -10,19 +11,44 @@
1011
from ...libs.lib import CONFIG_FILE
1112

1213

14+
import logging
15+
1316
async def update_async(latest_release):
14-
print("update_async")
15-
# Scarica l'aggiornamento dal repository su GitHub
16-
async with aiohttp.ClientSession() as session:
17-
async with session.get(latest_release['zipball_url']) as response:
18-
with open('latest_release.zip', 'wb') as f:
19-
f.write(await response.read())
20-
21-
# Aggiorna il file di configurazione locale con la nuova versione
22-
lib.update_key_json(CONFIG_FILE, "version", latest_release['tag_name'])
23-
24-
# Avvia l'applicazione aggiornata
25-
os.startfile('latest_release.zip')
17+
logger = logging.getLogger(__name__)
18+
logger.info("Starting async update")
19+
20+
# Cerca il file exe tra gli asset della release
21+
exe_asset = None
22+
for asset in latest_release['assets']:
23+
if asset['name'].endswith('.exe'):
24+
exe_asset = asset
25+
break
26+
27+
# Controlla se è stato trovato un file exe tra gli asset
28+
if exe_asset is not None:
29+
# Scarica il file exe
30+
async with aiohttp.ClientSession() as session:
31+
async with session.get(exe_asset['browser_download_url']) as response:
32+
with open(exe_asset['name'], 'wb') as f:
33+
f.write(await response.read())
34+
35+
# Sostituisce il file exe dell'applicazione con il nuovo file
36+
app_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
37+
exe_path = os.path.join(app_path, lib.APP_NAME + '.exe')
38+
if os.path.exists(exe_path):
39+
os.remove(exe_path)
40+
shutil.move(exe_asset['name'], exe_path)
41+
42+
43+
# remove old directory
44+
45+
# Avvia l'applicazione aggiornata
46+
os.startfile(exe_path)
47+
else:
48+
error_message = "Nessun file exe trovato nella release più recente."
49+
logger.error(error_message)
50+
messagebox.showerror("Error", error_message)
51+
2652

2753

2854
class UpdatePage(CTkFrame):

0 commit comments

Comments
 (0)