Compare commits
No commits in common. "e3fbe22ac038679ea281b723385ccf238ad7adb6" and "6885482aea49345c096ec5ab381d1f4093420a71" have entirely different histories.
e3fbe22ac0
...
6885482aea
@ -24,20 +24,18 @@ def get_cache_dir() -> Path:
|
|||||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||||
return cache_dir
|
return cache_dir
|
||||||
|
|
||||||
|
|
||||||
def get_egs_game_description_async(
|
def get_egs_game_description_async(
|
||||||
app_name: str,
|
app_name: str,
|
||||||
callback: Callable[[str], None],
|
callback: Callable[[str], None],
|
||||||
cache_ttl: int = 3600
|
cache_ttl: int = 3600
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Asynchronously fetches the game description from the Epic Games Store API.
|
Asynchronously fetches the game description using Epic Games Store GraphQL API.
|
||||||
Prioritizes the legacy store-content API using a derived slug.
|
Falls back to the legacy store-content API using the productSlug from GraphQL if available.
|
||||||
Falls back to GraphQL API if legacy API returns empty or 404, retrying legacy API with GraphQL productSlug if needed.
|
|
||||||
Retries GraphQL with English locale if system language yields no description.
|
|
||||||
Uses per-app cache files named egs_app_{app_name}.json in ~/.cache/PortProtonQT.
|
Uses per-app cache files named egs_app_{app_name}.json in ~/.cache/PortProtonQT.
|
||||||
Checks the cache first; if the description is cached and not expired, returns it.
|
Checks the cache first; if the description is cached and not expired, returns it.
|
||||||
Prioritizes the page with type 'productHome' for the base game description in legacy API.
|
Uses system language from get_egs_language() for the description.
|
||||||
|
Prioritizes the main game description by filtering for productSlug and excluding DLC/bundles.
|
||||||
"""
|
"""
|
||||||
cache_dir = get_cache_dir()
|
cache_dir = get_cache_dir()
|
||||||
cache_file = cache_dir / f"egs_app_{app_name.lower().replace(':', '_').replace(' ', '_')}.json"
|
cache_file = cache_dir / f"egs_app_{app_name.lower().replace(':', '_').replace(' ', '_')}.json"
|
||||||
@ -88,121 +86,114 @@ def get_egs_game_description_async(
|
|||||||
cache_file.unlink(missing_ok=True)
|
cache_file.unlink(missing_ok=True)
|
||||||
|
|
||||||
lang = get_egs_language()
|
lang = get_egs_language()
|
||||||
|
search_url = "https://graphql.epicgames.com/graphql"
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) EpicGamesLauncher"
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) EpicGamesLauncher"
|
||||||
}
|
}
|
||||||
search_url = "https://graphql.epicgames.com/graphql"
|
search_query = {
|
||||||
|
"query": "query search($keywords: String!, $locale: String) { Catalog { searchStore(keywords: $keywords, locale: $locale) { elements { title namespace productSlug description } } } }",
|
||||||
|
"variables": {
|
||||||
|
"keywords": app_name,
|
||||||
|
"locale": lang
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def fetch_description():
|
def fetch_description():
|
||||||
description = ""
|
description = ""
|
||||||
slug = app_name.lower().replace(":", "").replace(" ", "-")
|
product_slug = None
|
||||||
legacy_url = f"https://store-content.ak.epicgames.com/api/{lang}/content/products/{slug}"
|
try:
|
||||||
|
# First attempt: GraphQL search query
|
||||||
|
response = requests.post(search_url, json=search_query, headers=headers, timeout=5)
|
||||||
|
response.raise_for_status()
|
||||||
|
data = orjson.loads(response.content)
|
||||||
|
|
||||||
# Helper function to fetch description via legacy API
|
if isinstance(data, dict) and "data" in data:
|
||||||
def fetch_legacy_description(url: str) -> str:
|
elements = data.get("data", {}).get("Catalog", {}).get("searchStore", {}).get("elements", [])
|
||||||
try:
|
for element in elements:
|
||||||
response = requests.get(url, timeout=5)
|
if isinstance(element, dict) and element.get("title", "").lower() == app_name.lower() and element.get("productSlug") and not any(substring in element.get("title", "").lower() for substring in ["bundle", "pack", "edition", "dlc", "upgrade", "chapter", "набор", "пак", "дополнение"]):
|
||||||
|
description = element.get("description", "")
|
||||||
|
product_slug = element.get("productSlug", "")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
logger.warning("Invalid JSON structure for %s in GraphQL response: %s", app_name, type(data))
|
||||||
|
|
||||||
|
if not description and product_slug:
|
||||||
|
logger.info("No valid description found in GraphQL for %s, falling back to legacy API with slug %s", app_name, product_slug)
|
||||||
|
# Fallback to legacy API using productSlug
|
||||||
|
legacy_url = f"https://store-content.ak.epicgames.com/api/{lang}/content/products/{product_slug}"
|
||||||
|
response = requests.get(legacy_url, timeout=5)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = orjson.loads(response.content)
|
data = orjson.loads(response.content)
|
||||||
|
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
logger.warning("Invalid JSON structure for %s in legacy API: %s", app_name, type(data))
|
logger.warning("Invalid JSON structure for %s in legacy API: %s", app_name, type(data))
|
||||||
return ""
|
callback("")
|
||||||
|
return
|
||||||
|
|
||||||
pages = data.get("pages", [])
|
pages = data.get("pages", [])
|
||||||
if pages:
|
if pages:
|
||||||
for page in pages:
|
for page in pages:
|
||||||
if page.get("type") == "productHome":
|
if page.get("type") == "productHome":
|
||||||
return page.get("data", {}).get("about", {}).get("shortDescription", "")
|
about_data = page.get("data", {}).get("about", {})
|
||||||
|
description = about_data.get("shortDescription", "")
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
return pages[0].get("data", {}).get("about", {}).get("shortDescription", "")
|
description = (
|
||||||
return ""
|
pages[0].get("data", {})
|
||||||
except requests.HTTPError as e:
|
.get("about", {})
|
||||||
if e.response.status_code == 404:
|
.get("shortDescription", "")
|
||||||
logger.info("Legacy API returned 404 for %s", app_name)
|
)
|
||||||
else:
|
|
||||||
logger.warning("HTTP error in legacy API for %s: %s", app_name, str(e))
|
|
||||||
return ""
|
|
||||||
except requests.RequestException as e:
|
|
||||||
logger.warning("Failed to fetch legacy API for %s: %s", app_name, str(e))
|
|
||||||
return ""
|
|
||||||
except orjson.JSONDecodeError:
|
|
||||||
logger.warning("Invalid JSON response for %s in legacy API", app_name)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
# Helper function to fetch description and productSlug via GraphQL
|
|
||||||
def fetch_graphql_description(locale: str) -> tuple[str, str]:
|
|
||||||
search_query = {
|
|
||||||
"query": "query search($keywords: String!, $locale: String) { Catalog { searchStore(keywords: $keywords, locale: $locale) { elements { title namespace productSlug description } } } }",
|
|
||||||
"variables": {
|
|
||||||
"keywords": app_name,
|
|
||||||
"locale": locale
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try:
|
|
||||||
response = requests.post(search_url, json=search_query, headers=headers, timeout=5)
|
|
||||||
response.raise_for_status()
|
|
||||||
data = orjson.loads(response.content)
|
|
||||||
if isinstance(data, dict) and "data" in data:
|
|
||||||
elements = data.get("data", {}).get("Catalog", {}).get("searchStore", {}).get("elements", [])
|
|
||||||
for element in elements:
|
|
||||||
if isinstance(element, dict) and element.get("title", "").lower() == app_name.lower() and element.get("productSlug") and not any(substring in element.get("title", "").lower() for substring in ["bundle", "pack", "edition", "dlc", "upgrade", "chapter", "набор", "пак", "дополнение"]):
|
|
||||||
return element.get("description", ""), element.get("productSlug", "")
|
|
||||||
logger.warning("No valid description or productSlug found for %s in GraphQL with locale %s", app_name, locale)
|
|
||||||
return "", ""
|
|
||||||
except requests.RequestException as e:
|
|
||||||
logger.warning("Failed to fetch GraphQL data for %s with locale %s: %s", app_name, locale, str(e))
|
|
||||||
return "", ""
|
|
||||||
except orjson.JSONDecodeError:
|
|
||||||
logger.warning("Invalid JSON response for %s with locale %s", app_name, locale)
|
|
||||||
return "", ""
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Step 1: Try legacy API with derived slug
|
|
||||||
description = fetch_legacy_description(legacy_url)
|
|
||||||
product_slug = None
|
|
||||||
|
|
||||||
# Step 2: If legacy API fails, try GraphQL and possibly retry legacy with GraphQL slug
|
|
||||||
if not description:
|
|
||||||
logger.info("No valid description from legacy API for %s, falling back to GraphQL", app_name)
|
|
||||||
description, product_slug = fetch_graphql_description(lang)
|
|
||||||
# Retry legacy API with GraphQL productSlug if available
|
|
||||||
if not description and product_slug:
|
|
||||||
legacy_url = f"https://store-content.ak.epicgames.com/api/{lang}/content/products/{product_slug}"
|
|
||||||
description = fetch_legacy_description(legacy_url)
|
|
||||||
if description:
|
|
||||||
logger.debug("Fetched description from legacy API with GraphQL slug for %s: %s", app_name, (description[:100] + "...") if len(description) > 100 else description)
|
|
||||||
|
|
||||||
# Step 3: If still no description, retry GraphQL with English locale
|
|
||||||
if not description:
|
|
||||||
logger.info("No description in system language %s for %s, retrying GraphQL with en-US", lang, app_name)
|
|
||||||
description, _ = fetch_graphql_description("en-US")
|
|
||||||
|
|
||||||
if not description:
|
if not description:
|
||||||
logger.warning("No valid description found for %s after all queries", app_name)
|
logger.warning("No valid description found for %s after both queries", app_name)
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Final description for %s: %s",
|
"Fetched EGS description for %s: %s",
|
||||||
app_name,
|
app_name,
|
||||||
(description[:100] + "...") if len(description) > 100 else description
|
(description[:100] + "...") if len(description) > 100 else description
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save to cache
|
|
||||||
cache_entry = {"description": description, "timestamp": time.time()}
|
cache_entry = {"description": description, "timestamp": time.time()}
|
||||||
try:
|
try:
|
||||||
temp_file = cache_file.with_suffix('.tmp')
|
temp_file = cache_file.with_suffix('.tmp')
|
||||||
with open(temp_file, "wb") as f:
|
with open(temp_file, "wb") as f:
|
||||||
f.write(orjson.dumps(cache_entry))
|
f.write(orjson.dumps(cache_entry))
|
||||||
temp_file.replace(cache_file)
|
temp_file.replace(cache_file)
|
||||||
logger.debug("Saved description to cache for %s", app_name)
|
logger.debug(
|
||||||
|
"Saved description to cache for %s", app_name
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to save description cache for %s: %s", app_name, str(e))
|
logger.error(
|
||||||
|
"Failed to save description cache for %s: %s",
|
||||||
|
app_name,
|
||||||
|
str(e)
|
||||||
|
)
|
||||||
callback(description)
|
callback(description)
|
||||||
|
except requests.RequestException as e:
|
||||||
|
logger.warning(
|
||||||
|
"Failed to fetch EGS description for %s: %s",
|
||||||
|
app_name,
|
||||||
|
str(e)
|
||||||
|
)
|
||||||
|
callback("")
|
||||||
|
except orjson.JSONDecodeError:
|
||||||
|
logger.warning(
|
||||||
|
"Invalid JSON response for %s", app_name
|
||||||
|
)
|
||||||
|
callback("")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Unexpected error fetching EGS description for %s: %s", app_name, str(e))
|
logger.error(
|
||||||
|
"Unexpected error fetching EGS description for %s: %s",
|
||||||
|
app_name,
|
||||||
|
str(e)
|
||||||
|
)
|
||||||
callback("")
|
callback("")
|
||||||
|
|
||||||
thread = threading.Thread(target=fetch_description, daemon=True)
|
thread = threading.Thread(
|
||||||
|
target=fetch_description,
|
||||||
|
daemon=True
|
||||||
|
)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
def run_legendary_list_async(legendary_path: str, callback: Callable[[list | None], None]):
|
def run_legendary_list_async(legendary_path: str, callback: Callable[[list | None], None]):
|
||||||
|
@ -61,12 +61,6 @@ class MainWindow(QMainWindow):
|
|||||||
self.games_load_timer.timeout.connect(self.finalize_game_loading)
|
self.games_load_timer.timeout.connect(self.finalize_game_loading)
|
||||||
self.games_loaded.connect(self.on_games_loaded)
|
self.games_loaded.connect(self.on_games_loaded)
|
||||||
|
|
||||||
# Добавляем таймер для дебаунсинга сохранения настроек
|
|
||||||
self.settingsDebounceTimer = QTimer(self)
|
|
||||||
self.settingsDebounceTimer.setSingleShot(True)
|
|
||||||
self.settingsDebounceTimer.setInterval(300) # 300 мс задержка
|
|
||||||
self.settingsDebounceTimer.timeout.connect(self.applySettingsDelayed)
|
|
||||||
|
|
||||||
read_time_config()
|
read_time_config()
|
||||||
# Set LEGENDARY_CONFIG_PATH to ~/.cache/PortProtonQT/legendary
|
# Set LEGENDARY_CONFIG_PATH to ~/.cache/PortProtonQT/legendary
|
||||||
self.legendary_config_path = os.path.join(
|
self.legendary_config_path = os.path.join(
|
||||||
@ -1108,15 +1102,9 @@ class MainWindow(QMainWindow):
|
|||||||
# Показываем сообщение
|
# Показываем сообщение
|
||||||
self.statusBar().showMessage(_("Cache cleared"), 3000)
|
self.statusBar().showMessage(_("Cache cleared"), 3000)
|
||||||
|
|
||||||
def applySettingsDelayed(self):
|
|
||||||
"""Применяет настройки с учетом нового фильтра и обновляет список игр."""
|
|
||||||
read_time_config()
|
|
||||||
self.games = [] # Очищаем текущий список игр
|
|
||||||
self.loadGames() # Загружаем игры с новым фильтром
|
|
||||||
|
|
||||||
def savePortProtonSettings(self):
|
def savePortProtonSettings(self):
|
||||||
"""
|
"""
|
||||||
Сохраняет параметры конфигурации в конфигурационный файл.
|
Сохраняет параметры конфигурации в конфигурационный файл,
|
||||||
"""
|
"""
|
||||||
time_idx = self.timeDetailCombo.currentIndex()
|
time_idx = self.timeDetailCombo.currentIndex()
|
||||||
time_key = self.time_keys[time_idx]
|
time_key = self.time_keys[time_idx]
|
||||||
@ -1139,23 +1127,17 @@ class MainWindow(QMainWindow):
|
|||||||
fullscreen = self.fullscreenCheckBox.isChecked()
|
fullscreen = self.fullscreenCheckBox.isChecked()
|
||||||
save_fullscreen_config(fullscreen)
|
save_fullscreen_config(fullscreen)
|
||||||
|
|
||||||
# Запускаем отложенное применение настроек через таймер
|
# Перезагружаем настройки
|
||||||
self.settingsDebounceTimer.start()
|
read_time_config()
|
||||||
|
self.games = self.loadGames()
|
||||||
|
self.updateGameGrid()
|
||||||
self.settings_saved.emit()
|
self.settings_saved.emit()
|
||||||
|
|
||||||
if fullscreen:
|
if fullscreen:
|
||||||
self.showFullScreen()
|
self.showFullScreen()
|
||||||
else:
|
else:
|
||||||
if self.isFullScreen():
|
self.showNormal()
|
||||||
# Переходим в нормальный режим и восстанавливаем сохраненные размеры
|
save_window_geometry(self.width(), self.height())
|
||||||
width, height = read_window_geometry()
|
|
||||||
self.showNormal()
|
|
||||||
if width > 0 and height > 0:
|
|
||||||
self.resize(width, height)
|
|
||||||
# Сохраняем геометрию только если окно не в полноэкранном режиме
|
|
||||||
if not self.isFullScreen():
|
|
||||||
save_window_geometry(self.width(), self.height())
|
|
||||||
|
|
||||||
self.statusBar().showMessage(_("Settings saved"), 3000)
|
self.statusBar().showMessage(_("Settings saved"), 3000)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user