Skip to content

Commit

Permalink
Unregister TraktListsPlugin if no lists to update
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 28, 2024
1 parent c9bcfeb commit c748da2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plextraktsync/sync/TraktListsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from plextraktsync.plugin import hookimpl

if TYPE_CHECKING:
from .plugin.SyncPluginInterface import Media, TraktUserListCollection
from .plugin.SyncPluginInterface import (Media, SyncPluginManager,
TraktUserListCollection)


class TraktListsPlugin:
Expand All @@ -22,18 +23,21 @@ def __init__(self):

@staticmethod
def enabled(config):
# Use True for now, would need to keep in sync with other plugins
# Check for need is performed in init()
return True

@classmethod
def factory(cls, sync):
return cls()

@hookimpl(trylast=True)
def init(self, trakt_lists: TraktUserListCollection):
def init(self, pm: SyncPluginManager, trakt_lists: TraktUserListCollection):
self.trakt_lists = trakt_lists
# Skip updating lists if it's empty
self.add_to_lists = not trakt_lists.is_empty
# Skip updating lists if it's empty
if trakt_lists.is_empty:
self.logger.warning("Disabling TraktListsPlugin: No lists to process")
pm.unregister(self)

@hookimpl
def fini(self, dry_run: bool):
Expand Down

0 comments on commit c748da2

Please sign in to comment.