adjustment of EPG cache init

This commit is contained in:
DYefremov
2024-02-10 23:55:23 +03:00
parent ba3a3ae0aa
commit 388e748673
2 changed files with 18 additions and 16 deletions

View File

@@ -131,12 +131,20 @@ class FavEpgCache(EpgCache):
def __init__(self, app): def __init__(self, app):
super().__init__(app) super().__init__(app)
self._app.connect("epg-cache-initialized", self.on_cache_initialized)
GLib.timeout_add_seconds(self._settings.epg_update_interval, self.init) GLib.timeout_add_seconds(self._settings.epg_update_interval, self.init)
def on_cache_initialized(self, app, cache):
if cache is not self:
return
self._is_run = True
GLib.timeout_add_seconds(self._settings.epg_update_interval, self.update_epg_data, priority=GLib.PRIORITY_LOW)
def init(self): def init(self):
self._src = self._settings.epg_source self._src = self._settings.epg_source
self._xml_src = self._settings.epg_xml_source self._xml_src = self._settings.epg_xml_source
self._is_run = True self._is_run = False
if self._src is EpgSource.XML: if self._src is EpgSource.XML:
url = self._settings.epg_xml_source url = self._settings.epg_xml_source
gz_file = self.current_gz_file_name gz_file = self.current_gz_file_name
@@ -168,8 +176,6 @@ class FavEpgCache(EpgCache):
self._reader = EPG.DatReader(f"{self._settings.profile_data_path}epg{os.sep}epg.dat") self._reader = EPG.DatReader(f"{self._settings.profile_data_path}epg{os.sep}epg.dat")
self._reader.download() self._reader.download()
GLib.timeout_add_seconds(self._settings.epg_update_interval, self.update_epg_data, priority=GLib.PRIORITY_LOW)
def reset(self) -> None: def reset(self) -> None:
self.events.clear() self.events.clear()
if self._is_run: if self._is_run:
@@ -232,8 +238,8 @@ class TabEpgCache(EpgCache):
if self._app.display_epg and self._xml_src == self._settings.epg_xml_source: if self._app.display_epg and self._xml_src == self._settings.epg_xml_source:
ext_cache = self._app.current_epg_cache ext_cache = self._app.current_epg_cache
if ext_cache: if ext_cache and ext_cache.is_run:
GLib.idle_add(self._app.emit, "epg-cache-initialized", ext_cache) self._app.emit("epg-cache-initialized", ext_cache)
return return
self.load_data() self.load_data()
@@ -258,20 +264,16 @@ class TabEpgCache(EpgCache):
def on_cache_initialized(self, app, cache): def on_cache_initialized(self, app, cache):
if isinstance(cache, FavEpgCache): if isinstance(cache, FavEpgCache):
self.import_cache(cache) reader = cache.current_reader
if reader:
self._reader.cache.update(reader.cache)
self._is_run = False
else: else:
if not self._app.display_epg or self._settings.epg_source is not EpgSource.XML: if not self._app.display_epg or self._settings.epg_source is not EpgSource.XML or self._xml_src is None:
self._is_run = False self._is_run = False
self.update_epg_data() self.update_epg_data()
def import_cache(self, cache):
""" Imports external reader cache data into the current one. """
reader = cache.current_reader
if reader:
self._reader.cache.update(reader.cache)
self._is_run = False
@run_task @run_task
def process_data(self): def process_data(self):
GLib.idle_add(self._app.wait_dialog.show) GLib.idle_add(self._app.wait_dialog.show)

View File

@@ -3212,8 +3212,8 @@ class Application(Gtk.Application):
if display: if display:
if self._epg_cache is None: if self._epg_cache is None:
self._epg_cache = FavEpgCache(self) self._epg_cache = FavEpgCache(self)
else: else:
self._epg_cache.reset() self._epg_cache.reset()
def on_epg_list_configuration(self, action, value=None): def on_epg_list_configuration(self, action, value=None):
if self._s_type is not SettingsType.ENIGMA_2: if self._s_type is not SettingsType.ENIGMA_2: