diff options
| author | Phil Crosby | 2014-05-11 16:24:15 -0700 |
|---|---|---|
| committer | Phil Crosby | 2014-05-11 16:24:15 -0700 |
| commit | 70feaf233034f2cec8d20adf3a99ddc50b399156 (patch) | |
| tree | d5b4c34275fcfe1ac08b4e43d6d4adcb26051280 | |
| parent | 1aa7ba3a5810742d14edfb738120b70f4a0f7619 (diff) | |
| parent | 6dfe8462690082b0a3c6e4d0d4ee7c56175e3536 (diff) | |
| download | vimium-70feaf233034f2cec8d20adf3a99ddc50b399156.tar.bz2 | |
Merge pull request #791 from deiga/restore-closed-tab
Added support for chromes upcoming sessionRestore API
| -rw-r--r-- | background_scripts/main.coffee | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index b2b4669c..ab633d8e 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -238,23 +238,28 @@ BackgroundCommands = chrome.tabs.getSelected(null, (tab) -> chrome.tabs.remove(tab.id)) restoreTab: (callback) -> - # TODO(ilya): Should this be getLastFocused instead? - chrome.windows.getCurrent((window) -> - return unless (tabQueue[window.id] && tabQueue[window.id].length > 0) - tabQueueEntry = tabQueue[window.id].pop() - # Clean out the tabQueue so we don't have unused windows laying about. - delete tabQueue[window.id] if (tabQueue[window.id].length == 0) - - # We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until the - # tab is created because the content script is not available during the "loading" state. We need to - # wait until that's over before we can call setScrollPosition. - chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) -> - tabLoadedHandlers[tab.id] = -> - chrome.tabs.sendMessage(tab.id, - name: "setScrollPosition", - scrollX: tabQueueEntry.scrollX, - scrollY: tabQueueEntry.scrollY) - callback())) + # TODO: remove if-else -block when adopted into stable + if chrome.sessionRestore + chrome.sessionRestore.getRecentlyClosed((closed) -> + chrome.sessionRestore.restore(closed[0])) + else + # TODO(ilya): Should this be getLastFocused instead? + chrome.windows.getCurrent((window) -> + return unless (tabQueue[window.id] && tabQueue[window.id].length > 0) + tabQueueEntry = tabQueue[window.id].pop() + # Clean out the tabQueue so we don't have unused windows laying about. + delete tabQueue[window.id] if (tabQueue[window.id].length == 0) + + # We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until the + # tab is created because the content script is not available during the "loading" state. We need to + # wait until that's over before we can call setScrollPosition. + chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) -> + tabLoadedHandlers[tab.id] = -> + chrome.tabs.sendRequest(tab.id, + name: "setScrollPosition", + scrollX: tabQueueEntry.scrollX, + scrollY: tabQueueEntry.scrollY) + callback())) openCopiedUrlInCurrentTab: (request) -> openUrlInCurrentTab({ url: Clipboard.paste() }) openCopiedUrlInNewTab: (request) -> openUrlInNewTab({ url: Clipboard.paste() }) togglePinTab: (request) -> |
