Merge pull request #791 from croneter/fix-widget-loading

Wait for PKC to authorize before loading widgets
This commit is contained in:
croneter 2019-03-26 18:48:51 +01:00 committed by GitHub
commit 648d88b9b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,6 +57,30 @@ def guess_content_type():
return content_type return content_type
def _wait_for_auth():
"""
Call to be sure that PKC is authenticated, e.g. for widgets on Kodi startup.
Will wait for at most 30s, then fail if not authenticated. Will set
xbmcplugin.endOfDirectory(int(argv[1]), False) if failed
WARNING - this will potentially stall the shutdown of Kodi since we cannot
poll xbmc.Monitor().abortRequested() or waitForAbort() or
xbmc.abortRequested
"""
counter = 0
startupdelay = int(utils.settings('startupDelay') or 0)
# Wait for <startupdelay in seconds> + 10 seconds at most
startupdelay = 10 * startupdelay + 100
while utils.window('plex_authenticated') != 'true':
counter += 1
if counter == startupdelay:
LOG.error('Aborting view, we were not authenticated for PMS')
xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
return False
xbmc.sleep(100)
return True
def directory_item(label, path, folder=True): def directory_item(label, path, folder=True):
""" """
Adds a xbmcplugin.addDirectoryItem() directory itemlistitem Adds a xbmcplugin.addDirectoryItem() directory itemlistitem
@ -228,6 +252,8 @@ def get_video_files(plex_id, params):
if plex_id is None: if plex_id is None:
LOG.info('No Plex ID found, abort getting Extras') LOG.info('No Plex ID found, abort getting Extras')
return xbmcplugin.endOfDirectory(int(sys.argv[1])) return xbmcplugin.endOfDirectory(int(sys.argv[1]))
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
app.init(entrypoint=True) app.init(entrypoint=True)
item = PF.GetPlexMetadata(plex_id) item = PF.GetPlexMetadata(plex_id)
try: try:
@ -285,6 +311,8 @@ def extra_fanart(plex_id, plex_path):
# because of the caching system in xbmc # because of the caching system in xbmc
fanart_dir = path_ops.translate_path("special://thumbnails/plex/%s/" fanart_dir = path_ops.translate_path("special://thumbnails/plex/%s/"
% plex_id) % plex_id)
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
if not path_ops.exists(fanart_dir): if not path_ops.exists(fanart_dir):
# Download the images to the cache directory # Download the images to the cache directory
path_ops.makedirs(fanart_dir) path_ops.makedirs(fanart_dir)
@ -329,6 +357,8 @@ def playlists(content_type):
""" """
content_type = content_type or guess_content_type() content_type = content_type or guess_content_type()
LOG.debug('Listing Plex %s playlists', content_type) LOG.debug('Listing Plex %s playlists', content_type)
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
app.init(entrypoint=True) app.init(entrypoint=True)
from .playlists.pms import all_playlists from .playlists.pms import all_playlists
xml = all_playlists() xml = all_playlists()
@ -352,6 +382,8 @@ def hub(content_type):
""" """
content_type = content_type or guess_content_type() content_type = content_type or guess_content_type()
LOG.debug('Showing Plex Hub entries for %s', content_type) LOG.debug('Showing Plex Hub entries for %s', content_type)
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
app.init(entrypoint=True) app.init(entrypoint=True)
xml = PF.get_plex_hub() xml = PF.get_plex_hub()
try: try:
@ -385,6 +417,8 @@ def watchlater():
""" """
Listing for plex.tv Watch Later section (if signed in to plex.tv) Listing for plex.tv Watch Later section (if signed in to plex.tv)
""" """
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
if utils.window('plex_token') == '': if utils.window('plex_token') == '':
LOG.error('No watch later - not signed in to plex.tv') LOG.error('No watch later - not signed in to plex.tv')
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False) return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
@ -412,6 +446,8 @@ def browse_plex(key=None, plex_type=None, section_id=None, synched=True,
""" """
LOG.debug('Browsing to key %s, section %s, plex_type: %s, synched: %s, ' LOG.debug('Browsing to key %s, section %s, plex_type: %s, synched: %s, '
'prompt "%s"', key, section_id, plex_type, synched, prompt) 'prompt "%s"', key, section_id, plex_type, synched, prompt)
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
app.init(entrypoint=True) app.init(entrypoint=True)
if prompt: if prompt:
prompt = utils.dialog('input', prompt) prompt = utils.dialog('input', prompt)
@ -437,6 +473,8 @@ def extras(plex_id):
""" """
Lists all extras for plex_id Lists all extras for plex_id
""" """
if not _wait_for_auth():
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
app.init(entrypoint=True) app.init(entrypoint=True)
xml = PF.GetPlexMetadata(plex_id) xml = PF.GetPlexMetadata(plex_id)
try: try: