[#1330] [Core] Fix pausing and resuming session
* The paused state of torrents is now correctly stored on shutdown if the session is paused. * core.pause_all_torrents now uses libtorrent session.pause and resume_all_torrents also refreshes all torrents' state. This fixes only torrents that changed state being updated so queued torrents would be incorrectly displayed as paused. * Scheduler and Blocklist now use updated core methods rather than calling libtorrent directly.
This commit is contained in:
parent
eab7850ed6
commit
7315255831
|
@ -409,15 +409,18 @@ class Core(component.Component):
|
|||
@export
|
||||
def pause_all_torrents(self):
|
||||
"""Pause all torrents in the session"""
|
||||
for torrent in self.torrentmanager.torrents.values():
|
||||
torrent.pause()
|
||||
if not self.session.is_paused():
|
||||
self.session.pause()
|
||||
component.get("EventManager").emit(SessionPausedEvent())
|
||||
|
||||
@export
|
||||
def resume_all_torrents(self):
|
||||
"""Resume all torrents in the session"""
|
||||
for torrent in self.torrentmanager.torrents.values():
|
||||
torrent.resume()
|
||||
component.get("EventManager").emit(SessionResumedEvent())
|
||||
if self.session.is_paused():
|
||||
self.session.resume()
|
||||
for torrent in self.torrentmanager.torrents.values():
|
||||
torrent.update_state()
|
||||
component.get("EventManager").emit(SessionResumedEvent())
|
||||
|
||||
@export
|
||||
def resume_torrent(self, torrent_ids):
|
||||
|
|
|
@ -674,9 +674,12 @@ class TorrentManager(component.Component):
|
|||
state = TorrentManagerState()
|
||||
# Create the state for each Torrent and append to the list
|
||||
for torrent in self.torrents.values():
|
||||
paused = False
|
||||
if torrent.state == "Paused":
|
||||
if self.session.is_paused():
|
||||
paused = torrent.handle.is_paused()
|
||||
elif torrent.state == "Paused":
|
||||
paused = True
|
||||
else:
|
||||
paused = False
|
||||
|
||||
torrent_state = TorrentState(
|
||||
torrent.torrent_id,
|
||||
|
|
|
@ -425,12 +425,12 @@ class Core(CorePluginBase):
|
|||
|
||||
def pause_session(self):
|
||||
if not self.core.session.is_paused():
|
||||
self.core.session.pause()
|
||||
self.core.pause_all_torrents()
|
||||
self.need_to_resume_session = True
|
||||
else:
|
||||
self.need_to_resume_session = False
|
||||
|
||||
def resume_session(self, result):
|
||||
self.core.session.resume()
|
||||
self.core.resume_all_torrents()
|
||||
self.need_to_resume_session = False
|
||||
return result
|
||||
|
|
|
@ -129,7 +129,7 @@ class Core(CorePluginBase):
|
|||
for setting in CONTROLLED_SETTINGS:
|
||||
core_config.apply_set_functions(setting)
|
||||
# Resume the session if necessary
|
||||
component.get("Core").session.resume()
|
||||
component.get("Core").resume_all_torrents()
|
||||
|
||||
def do_schedule(self, timer=True):
|
||||
"""
|
||||
|
@ -153,10 +153,10 @@ class Core(CorePluginBase):
|
|||
settings.active_seeds = self.config["low_active_up"]
|
||||
session.set_settings(settings)
|
||||
# Resume the session if necessary
|
||||
component.get("Core").session.resume()
|
||||
component.get("Core").resume_all_torrents()
|
||||
elif state == "Red":
|
||||
# This is Red (Stop), so pause the libtorrent session
|
||||
component.get("Core").session.pause()
|
||||
component.get("Core").pause_all_torrents()
|
||||
|
||||
if state != self.state:
|
||||
# The state has changed since last update so we need to emit an event
|
||||
|
|
Loading…
Reference in New Issue