Skip to content

Commit

Permalink
Further fixes for busy dialog crash workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Apr 30, 2024
1 parent 543e582 commit 75a2fae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions resources/lib/youtube_plugin/kodion/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ABORT_FLAG = 'abort_requested'
BUSY_FLAG = 'busy'
CHECK_SETTINGS = 'check_settings'
PLAYLIST_PATH = 'playlist_path'
PLAYLIST_POSITION = 'playlist_position'
REROUTE = 'reroute'
SLEEPING = 'sleeping'
Expand All @@ -50,6 +51,7 @@
'CHECK_SETTINGS',
'DATA_PATH',
'MEDIA_PATH',
'PLAYLIST_PATH',
'PLAYLIST_POSITION',
'RESOURCE_PATH',
'REROUTE',
Expand Down
34 changes: 26 additions & 8 deletions resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@

from ..abstract_plugin import AbstractPlugin
from ...compatibility import xbmcplugin
from ...constants import BUSY_FLAG, PLAYLIST_POSITION, REROUTE, SLEEPING
from ...constants import (
BUSY_FLAG,
PLAYLIST_PATH,
PLAYLIST_POSITION,
REROUTE,
SLEEPING,
)
from ...exceptions import KodionException
from ...items import (
DirectoryItem,
Expand Down Expand Up @@ -66,12 +72,23 @@ def run(self, provider, context):

playlist = XbmcPlaylist('auto', context, retry=3)
position, remaining = playlist.get_position()
items = playlist.get_items() if remaining else None
items = playlist.get_items()
playlist.clear()

context.log_warning('Multiple busy dialogs active - '
'playlist cleared to avoid Kodi crash')

if items:
path = items[position - 1]['file']
old_path = ui.get_property(PLAYLIST_PATH)
old_position = ui.get_property(PLAYLIST_POSITION)
if (old_position and position == int(old_position)
and old_path and path == old_path):
if remaining:
position += 1
else:
items = None

if items:
max_wait_time = 30
while ui.busy_dialog_active():
Expand All @@ -84,12 +101,8 @@ def run(self, provider, context):

context.log_warning('Multiple busy dialogs active - '
'reloading playlist')
num_items = playlist.add_items(items)

old_position = ui.get_property(PLAYLIST_POSITION)
if old_position and position == int(old_position):
position += 1

num_items = playlist.add_items(items)
max_wait_time = min(position, num_items)
while ui.busy_dialog_active() or playlist.size() < position:
max_wait_time -= 1
Expand All @@ -102,10 +115,12 @@ def run(self, provider, context):
playlist.play_playlist_item(position)

ui.clear_property(BUSY_FLAG)
ui.clear_property(PLAYLIST_PATH)
ui.clear_property(PLAYLIST_POSITION)
return False

ui.clear_property(BUSY_FLAG)
ui.clear_property(PLAYLIST_PATH)
ui.clear_property(PLAYLIST_POSITION)

if ui.get_property(SLEEPING):
Expand Down Expand Up @@ -188,7 +203,10 @@ def _set_resolved_url(self, context, base_item):
ui.set_property(BUSY_FLAG, 'true')
playlist = XbmcPlaylist('auto', context)
position, _ = playlist.get_position()
ui.set_property(PLAYLIST_POSITION, str(position))
items = playlist.get_items()
if items:
ui.set_property(PLAYLIST_PATH, items[position - 1]['file'])
ui.set_property(PLAYLIST_POSITION, str(position))

item = self._PLAY_ITEM_MAP[base_item.__class__.__name__](
context,
Expand Down

0 comments on commit 75a2fae

Please sign in to comment.