|
1 | 1 | import asyncio |
| 2 | +import shutil |
2 | 3 | from tkinter import messagebox |
3 | 4 | import aiohttp |
4 | 5 | import webbrowser |
|
10 | 11 | from ...libs.lib import CONFIG_FILE |
11 | 12 |
|
12 | 13 |
|
| 14 | +import logging |
| 15 | + |
13 | 16 | 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 | + |
26 | 52 |
|
27 | 53 |
|
28 | 54 | class UpdatePage(CTkFrame): |
|
0 commit comments