From f38b2db27333713ef81518bf4e7e3f0c653bc21f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 13 Jan 2019 23:45:03 +0100 Subject: [PATCH] Fixed interaction with modal dialogs to prevent browser race conditions when touchscreen events are involved --- platypush/backend/http/static/js/application.js | 9 ++++++++- platypush/backend/http/static/js/music.mpd.js | 7 +++++-- platypush/backend/http/static/js/music.snapcast.js | 6 +++--- platypush/plugins/utils.py | 2 ++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/platypush/backend/http/static/js/application.js b/platypush/backend/http/static/js/application.js index ecedb7bb4..a8ab4768f 100644 --- a/platypush/backend/http/static/js/application.js +++ b/platypush/backend/http/static/js/application.js @@ -4,6 +4,7 @@ $(document).ready(function() { openedWebsocket, dateTimeInterval, websocketTimeoutId, + modalFadingInTimeoutId, websocketReconnectMsecs = 30000, eventListeners = []; @@ -155,6 +156,10 @@ $(document).ready(function() { var top = 40 + $(window).scrollTop(); $container.css('margin-top', top + 'px'); + modalFadingInTimeoutId = setTimeout(function() { + modalFadingInTimeoutId = undefined; + }, 100); + $modal.fadeIn(); }); }; @@ -171,7 +176,9 @@ $(document).ready(function() { if (!$source.parents('.modal').length && !$source.data('modal') && !$source.data('dismiss-modal')) { - $('.modal').filter(':visible').fadeOut(); + if (!modalFadingInTimeoutId) { + $('.modal').filter(':visible').fadeOut(); + } } }); }; diff --git a/platypush/backend/http/static/js/music.mpd.js b/platypush/backend/http/static/js/music.mpd.js index 207d14c19..184d4e435 100644 --- a/platypush/backend/http/static/js/music.mpd.js +++ b/platypush/backend/http/static/js/music.mpd.js @@ -1,5 +1,6 @@ $(document).ready(function() { var seekInterval, + longPressTimeout, curPath = [], curTrackUpdateHandler, curTrackElapsed = { @@ -225,8 +226,10 @@ $(document).ready(function() { }); } - clearTimeout(longPressTimeout); - longPressTimeout = undefined; + if (longPressTimeout) { + clearTimeout(longPressTimeout); + longPressTimeout = undefined; + } }; var updatePlaylist = function(tracks) { diff --git a/platypush/backend/http/static/js/music.snapcast.js b/platypush/backend/http/static/js/music.snapcast.js index d22e93ce3..6078a85ee 100644 --- a/platypush/backend/http/static/js/music.snapcast.js +++ b/platypush/backend/http/static/js/music.snapcast.js @@ -308,7 +308,7 @@ $(document).ready(function() { }); }); - $container.on('click touch', '.snapcast-host-settings', function(evt) { + $container.on('mousedown touchstart', '.snapcast-host-settings', function(evt) { var host = $(this).parents('.snapcast-host-container').data('host'); var hostName = $(this).parents('.snapcast-host-container').data('name'); var $modal = $($(this).data('modal')); @@ -324,7 +324,7 @@ $(document).ready(function() { } }); - $container.on('click touch', '.snapcast-group-settings', function(evt) { + $container.on('mousedown touchstart', '.snapcast-group-settings', function(evt) { var host = $(this).parents('.snapcast-host-container').data('host'); var groupId = $(this).parents('.snapcast-group-container').data('id'); var groupName = $(this).parents('.snapcast-group-container').data('name'); @@ -375,7 +375,7 @@ $(document).ready(function() { .find('select[name=stream]').html($streams.html()); }); - $container.on('click touch', '.snapcast-client-settings', function(evt) { + $container.on('mousedown touchstart', '.snapcast-client-settings', function(evt) { var host = $(this).parents('.snapcast-host-container').data('host'); var clientId = $(this).parents('.snapcast-client-container').data('id'); var clientName = $(this).parents('.snapcast-client-container').data('name'); diff --git a/platypush/plugins/utils.py b/platypush/plugins/utils.py index fe494cd67..99c237e37 100644 --- a/platypush/plugins/utils.py +++ b/platypush/plugins/utils.py @@ -18,7 +18,9 @@ class UtilsPlugin(Plugin): _interval_hndl_idx = 0 _interval_hndl_idx_lock = threading.RLock() + _pending_timeouts = {} _pending_intervals = {} + _pending_timemouts_lock = threading.RLock() _pending_intervals_lock = threading.RLock() @action