From c5d0ed09b8ed5c0351e11f985ceeae244f0f0caa Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 9 Apr 2016 08:44:21 +0100 Subject: A UI component isn't ready until it's ready. 1. Do not initialize UI components until the DOm is ready. 2. Do not register UI components as ready (specifically the HUD) until the full initialization sequence is complete. This goes some way towards fixing the issue described in this comment: https://github.com/philc/vimium/issues/2081#issuecomment-205758102 It relates to link-hints mode hanging when launched during a navigation. This problem exists in 1.54, but emerged during testing of global link hints. "Some way toeards fixing..." because it is still possible to trigger issues. --- content_scripts/hud.coffee | 11 +++-------- content_scripts/ui_component.coffee | 3 +++ content_scripts/vimium_frontend.coffee | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 92de975b..bbf7c5e9 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -23,13 +23,13 @@ HUD = @_showForDurationTimerId = setTimeout((=> @hide()), duration) show: (text) -> - return unless @enabled() + return unless @isReady() clearTimeout(@_showForDurationTimerId) @hudUI.show {name: "show", text} @tween.fade 1.0, 150 showFindMode: (@findMode = null) -> - return unless @enabled() + return unless @isReady() @hudUI.show {name: "showFindMode", text: ""} @tween.fade 1.0, 150 @@ -83,12 +83,7 @@ HUD = @findMode.exit() postExit?() - isReady: do -> - ready = false - DomUtils.documentReady -> ready = true - -> ready and document.body != null and @hudUI? - - enabled: -> true + isReady: -> @hudUI?.uiComponentIsReady class Tween opacity: 0 diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 4c9b18e1..92640eb2 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -1,4 +1,5 @@ class UIComponent + uiComponentIsReady: false iframeElement: null iframePort: null showing: null @@ -53,6 +54,8 @@ class UIComponent @postMessage name: "frameFocused", focusFrameId: request.focusFrameId false # Free up the sendResponse handler. + @styleSheetGetter.use => @iframePort.use => Utils.nextTick => @uiComponentIsReady = true + # Posts a message (if one is provided), then calls continuation (if provided). The continuation is only # ever called *after* the message has been posted. postMessage: (message = null, continuation = null) -> diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 58cf6115..39e87648 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -138,8 +138,7 @@ installModes = -> initializeOnEnabledStateKnown = Utils.makeIdempotent -> installModes() -initializeUIComponents = -> - # Both of these are idempotent. +initializeUIComponents = Utils.makeIdempotent -> DomUtils.documentReady -> HUD.init() Vomnibar.init() if DomUtils.isTopFrame() -- cgit v1.2.3