Commit f33549cd authored by Roman Alifanov's avatar Roman Alifanov

applicationrow: download list of available files first, rather than trying to download each one

parent 6969d3de
...@@ -2,11 +2,13 @@ import os ...@@ -2,11 +2,13 @@ import os
import urllib.request import urllib.request
import threading import threading
from gi.repository import Adw, Gtk, GdkPixbuf, Gio, GLib, Gdk from gi.repository import Adw, Gtk, GdkPixbuf, Gio, GLib, Gdk
from bs4 import BeautifulSoup # Не забудьте установить BeautifulSoup4
class IconLoader: class IconLoader:
BASE_URL = "https://download.etersoft.ru/pub/Etersoft/XimperLinux/eepm_play_gui/icons/" BASE_URL = "https://download.etersoft.ru/pub/Etersoft/XimperLinux/eepm_play_gui/icons/"
SUPPORTED_EXTENSIONS = ['png', 'jpg', 'svg'] SUPPORTED_EXTENSIONS = ['png', 'jpg', 'svg']
CACHE_DIR = os.path.join(os.path.expanduser("~"), ".cache", "ru.eepm.PlayGUI", "apps_icons") CACHE_DIR = os.path.join(os.path.expanduser("~"), ".cache", "ru.eepm.PlayGUI", "apps_icons")
available_files = set()
@classmethod @classmethod
def ensure_cache_dir(cls): def ensure_cache_dir(cls):
...@@ -30,7 +32,11 @@ class IconLoader: ...@@ -30,7 +32,11 @@ class IconLoader:
def load_icon(): def load_icon():
for ext in cls.SUPPORTED_EXTENSIONS: for ext in cls.SUPPORTED_EXTENSIONS:
icon_url = f"{cls.BASE_URL}{icon_name}.{ext}" icon_filename = f"{icon_name}.{ext}"
if icon_filename not in cls.available_files:
continue # Пропустить загрузку, если файл отсутствует
icon_url = f"{cls.BASE_URL}{icon_filename}"
try: try:
with urllib.request.urlopen(icon_url) as response: with urllib.request.urlopen(icon_url) as response:
input_stream = Gio.MemoryInputStream.new_from_data(response.read(), None) input_stream = Gio.MemoryInputStream.new_from_data(response.read(), None)
...@@ -43,10 +49,27 @@ class IconLoader: ...@@ -43,10 +49,27 @@ class IconLoader:
return return
except Exception as e: except Exception as e:
print(f"Icon for {icon_name} not found in {ext}: {e}") print(f"Failed to load {icon_name}.{ext}: {e}")
threading.Thread(target=load_icon, daemon=True).start() threading.Thread(target=load_icon, daemon=True).start()
@classmethod
def fetch_file_list(cls):
print("fetch file list...")
try:
with urllib.request.urlopen(cls.BASE_URL) as response:
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
# Ищем ссылки на файлы
for link in soup.find_all('a'):
href = link.get('href')
if any(href.endswith(ext) for ext in cls.SUPPORTED_EXTENSIONS):
cls.available_files.add(href)
except Exception as e:
print(f"Failed to fetch file list: {e}")
class ApplicationRow(Adw.ActionRow): class ApplicationRow(Adw.ActionRow):
__gtype_name__ = 'ApplicationRow' __gtype_name__ = 'ApplicationRow'
...@@ -103,3 +126,6 @@ class ApplicationRow(Adw.ActionRow): ...@@ -103,3 +126,6 @@ class ApplicationRow(Adw.ActionRow):
else: else:
# self.add_css_class("unchanged") # self.add_css_class("unchanged")
print("marked-unchanged") print("marked-unchanged")
# Загрузить список доступных файлов при запуске
IconLoader.fetch_file_list()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment