|
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 | + |
| 16 | +import logging |
| 17 | + |
13 | 18 | 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') |
| 19 | + logger = logging.getLogger(__name__) |
| 20 | + logger.info("Starting async update") |
| 21 | + |
| 22 | + # Cerca il file exe tra gli asset della release |
| 23 | + exe_asset = None |
| 24 | + for asset in latest_release['assets']: |
| 25 | + if asset['name'].endswith('.exe'): |
| 26 | + exe_asset = asset |
| 27 | + break |
| 28 | + |
| 29 | + # Controlla se è stato trovato un file exe tra gli asset |
| 30 | + if exe_asset is not None: |
| 31 | + # Scarica il file exe |
| 32 | + async with aiohttp.ClientSession() as session: |
| 33 | + async with session.get(exe_asset['browser_download_url']) as response: |
| 34 | + with open(exe_asset['name'], 'wb') as f: |
| 35 | + f.write(await response.read()) |
| 36 | + |
| 37 | + # Sostituisce il file exe dell'applicazione con il nuovo file |
| 38 | + app_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 39 | + exe_path = os.path.join(app_path, lib.APP_NAME + '.exe') |
| 40 | + if os.path.exists(exe_path): |
| 41 | + os.remove(exe_path) |
| 42 | + shutil.move(exe_asset['name'], exe_path) |
| 43 | + |
| 44 | + |
| 45 | + # Rimuovere lavecchia cartella dell' applicazione |
| 46 | + shutil.rmtree(os.path.dirname(os.path.dirname(lib.resource_path("")))) |
| 47 | + |
| 48 | + # Avvia l'applicazione aggiornata |
| 49 | + os.startfile(exe_path) |
| 50 | + |
| 51 | + # Chiude la vecchia applicazione |
| 52 | + os._exit(0) |
| 53 | + else: |
| 54 | + error_message = "Nessun file exe trovato nella release più recente." |
| 55 | + logger.error(error_message) |
| 56 | + messagebox.showerror("Error", error_message) |
| 57 | + |
26 | 58 |
|
27 | 59 |
|
28 | 60 | class UpdatePage(CTkFrame): |
|
0 commit comments