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) <noreply@anthropic.com>
This commit is contained in:
Jules
2026-03-20 20:07:51 +01:00
parent c5236c1e54
commit de3e83b57e

36
main.py
View File

@@ -76,7 +76,7 @@ def _check_license_online(key):
hname = _get_hostname() hname = _get_hostname()
url = f"{LICENSE_API}?key={urllib.parse.quote(key)}&machine_id={urllib.parse.quote(mid)}&hostname={urllib.parse.quote(hname)}" 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"}) 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()) data = json.loads(resp.read().decode())
if data.get("valid"): if data.get("valid"):
cache = { cache = {
@@ -99,21 +99,38 @@ def _check_license_online(key):
return None, str(e) # None = hors-ligne 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(): def _check_license():
"""Verifier la licence au lancement.""" """Verifier la licence au lancement."""
cache = _load_license_cache() 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"): if cache and cache.get("key"):
key = cache["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) result, msg = _check_license_online(key)
if result is True: if result is True:
# Licence valide en ligne
return True return True
if result is False: if result is False:
# Licence refusee par le serveur
QMessageBox.critical( QMessageBox.critical(
None, "Licence invalide", None, "Licence invalide",
f"Votre licence a ete refusee :\n{msg}\n\n" f"Votre licence a ete refusee :\n{msg}\n\n"
@@ -121,16 +138,7 @@ def _check_license():
) )
return False return False
# result is None = hors-ligne, verifier le timeout # Hors-ligne et cache expire
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
QMessageBox.critical( QMessageBox.critical(
None, "Licence expiree hors-ligne", None, "Licence expiree hors-ligne",
f"Impossible de verifier votre licence depuis {int(elapsed_hours)}h.\n" f"Impossible de verifier votre licence depuis {int(elapsed_hours)}h.\n"