Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix #451, close the search tab after an hour if it's unused
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Oct 23, 2019
1 parent 2766795 commit db5ad1e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions extension/intents/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

this.intents.search = (function() {
const exports = {};
// Close the search tab after this amount of time:
const CLOSE_TIME = 1000 * 60 * 60; // 1 hour
let closeTabTimeout = null;
let _searchTabId;
const START_URL = "https://www.google.com";
let lastSearchInfo;
let lastSearchIndex;
let lastTabId;

async function openSearchTab() {
if (closeTabTimeout) {
clearTimeout(closeTabTimeout);
closeTabTimeout = null;
}
closeTabTimeout = setTimeout(() => {
closeSearchTab();
}, CLOSE_TIME);
if (_searchTabId) {
try {
await browser.tabs.get(_searchTabId);
Expand Down Expand Up @@ -36,6 +46,15 @@ this.intents.search = (function() {
return _searchTabId;
}

async function closeSearchTab() {
if (!_searchTabId) {
return;
}
const tabId = _searchTabId;
_searchTabId = null;
await browser.tabs.remove(tabId);
}

async function performSearch(query) {
const tabId = await openSearchTab();
const url = searching.googleSearchUrl(query) + "&voice";
Expand Down

0 comments on commit db5ad1e

Please sign in to comment.