From de3e83b57e1f295df0a55e13145050be619a0df0 Mon Sep 17 00:00:00 2001 From: Jules Date: Fri, 20 Mar 2026 20:07:51 +0100 Subject: [PATCH] Lancement instantane si cache licence valide - Si cache licence non expire, lance l'app immediatement - Verification en ligne en arriere-plan (thread) - Timeout reseau reduit de 10s a 5s - Plus d'attente au demarrage pour les licences deja activees Co-Authored-By: Claude Opus 4.6 (1M context) --- main.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 124780f..cac0c9c 100644 --- a/main.py +++ b/main.py @@ -76,7 +76,7 @@ def _check_license_online(key): hname = _get_hostname() url = f"{LICENSE_API}?key={urllib.parse.quote(key)}&machine_id={urllib.parse.quote(mid)}&hostname={urllib.parse.quote(hname)}" req = urllib.request.Request(url, headers={"User-Agent": "CopydevImposingTool/1.0"}) - with urllib.request.urlopen(req, timeout=10) as resp: + with urllib.request.urlopen(req, timeout=5) as resp: data = json.loads(resp.read().decode()) if data.get("valid"): cache = { @@ -99,21 +99,38 @@ def _check_license_online(key): return None, str(e) # None = hors-ligne +def _check_license_background(key): + """Verification en arriere-plan (thread).""" + import threading + def _bg(): + _check_license_online(key) + t = threading.Thread(target=_bg, daemon=True) + t.start() + + def _check_license(): """Verifier la licence au lancement.""" cache = _load_license_cache() - # Si on a un cache, essayer de valider en ligne + # Si on a un cache valide, lancer direct et verifier en arriere-plan if cache and cache.get("key"): key = cache["key"] + timeout_hours = cache.get("offline_timeout_hours", 72) + last_validated = cache.get("last_validated", 0) + elapsed_hours = (time.time() - last_validated) / 3600 + + if elapsed_hours < timeout_hours: + # Cache encore valide — lancer l'app et verifier en background + _check_license_background(key) + return True + + # Cache expire — on doit verifier en ligne result, msg = _check_license_online(key) if result is True: - # Licence valide en ligne return True if result is False: - # Licence refusee par le serveur QMessageBox.critical( None, "Licence invalide", f"Votre licence a ete refusee :\n{msg}\n\n" @@ -121,16 +138,7 @@ def _check_license(): ) return False - # result is None = hors-ligne, verifier le timeout - timeout_hours = cache.get("offline_timeout_hours", 72) - last_validated = cache.get("last_validated", 0) - elapsed_hours = (time.time() - last_validated) / 3600 - - if elapsed_hours < timeout_hours: - remaining = timeout_hours - elapsed_hours - return True - - # Timeout depasse + # Hors-ligne et cache expire QMessageBox.critical( None, "Licence expiree hors-ligne", f"Impossible de verifier votre licence depuis {int(elapsed_hours)}h.\n"