From 523a61edece5d025205dc77e52a007f0848a7f2c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 2 May 2015 14:30:25 +0100 Subject: Fix vomnibar messaging. This essentially reinstates 02ca5eafb6aca5a9a09b3b592be76d3b834ccde6, however fixed properly this time. --- pages/vomnibar.coffee | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index f8ed0c78..ce0eb61c 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -171,6 +171,7 @@ class VomnibarUI # cancel scheduled update if (@updateTimer != null) window.clearTimeout(@updateTimer) + @updateTimer = null @updateCompletions(callback) else if (@updateTimer != null) # an update is already scheduled, don't do anything @@ -212,29 +213,30 @@ class BackgroundCompleter # - name: The background page completer that you want to interface with. Either "omni", "tabs", or # "bookmarks". */ constructor: (@name) -> - @filterPort = chrome.runtime.connect({ name: "filterCompleter" }) + @filterPort = chrome.runtime.connect name: "filterCompleter" refresh: -> - BackgroundCompleter.messageId += 1 - chrome.runtime.sendMessage({ handler: "refreshCompleter", name: @name }) + chrome.runtime.sendMessage handler: "refreshCompleter", name: @name filter: (query, callback) -> - @filterPort.onMessage.addListener (msg) => - @filterPort.onMessage.removeListener(arguments.callee) - if msg.id == BackgroundCompleter.messageId - # The result objects coming from the background page will be of the form: - # { html: "", type: "", url: "" } - # type will be one of [tab, bookmark, history, domain]. - results = msg.results.map (result) -> - functionToCall = if (result.type == "tab") - BackgroundCompleter.completionActions.switchToTab.curry(result.tabId) - else - BackgroundCompleter.completionActions.navigateToUrl.curry(result.url) - result.performAction = functionToCall - result - callback(results) - - @filterPort.postMessage({ id: ++BackgroundCompleter.messageId, name: @name, query: query }) + id = BackgroundCompleter.messageId += 1 + @filterPort.onMessage.addListener handler = (msg) => + if msg.id == id + @filterPort.onMessage.removeListener handler + if id == BackgroundCompleter.messageId + # The result objects coming from the background page will be of the form: + # { html: "", type: "", url: "" } + # type will be one of [tab, bookmark, history, domain]. + results = msg.results.map (result) -> + functionToCall = if (result.type == "tab") + BackgroundCompleter.completionActions.switchToTab.curry(result.tabId) + else + BackgroundCompleter.completionActions.navigateToUrl.curry(result.url) + result.performAction = functionToCall + result + callback(results) + + @filterPort.postMessage id: id, name: @name, query: query extend BackgroundCompleter, # -- cgit v1.2.3