chore(extension): proper watchdog for inactive page selector (#835)
This commit is contained in:
@@ -36,6 +36,7 @@ class TabShareExtension {
|
|||||||
constructor() {
|
constructor() {
|
||||||
chrome.tabs.onRemoved.addListener(this._onTabRemoved.bind(this));
|
chrome.tabs.onRemoved.addListener(this._onTabRemoved.bind(this));
|
||||||
chrome.tabs.onUpdated.addListener(this._onTabUpdated.bind(this));
|
chrome.tabs.onUpdated.addListener(this._onTabUpdated.bind(this));
|
||||||
|
chrome.tabs.onActivated.addListener(this._onTabActivated.bind(this));
|
||||||
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,29 +154,30 @@ class TabShareExtension {
|
|||||||
this._connectedTabId = null;
|
this._connectedTabId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _onTabUpdated(tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab): Promise<void> {
|
private _onTabActivated(activeInfo: chrome.tabs.TabActiveInfo) {
|
||||||
if (changeInfo.status === 'complete' && this._connectedTabId === tabId) {
|
for (const [tabId, pending] of this._pendingTabSelection) {
|
||||||
await this._setConnectedTabId(tabId);
|
if (tabId === activeInfo.tabId) {
|
||||||
return;
|
if (pending.timerId) {
|
||||||
}
|
|
||||||
const pending = this._pendingTabSelection.get(tabId);
|
|
||||||
if (!pending)
|
|
||||||
return;
|
|
||||||
if (tab.active && pending.timerId) {
|
|
||||||
clearTimeout(pending.timerId);
|
clearTimeout(pending.timerId);
|
||||||
pending.timerId = undefined;
|
pending.timerId = undefined;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!tab.active && !pending.timerId) {
|
continue;
|
||||||
debugLog('Starting inactivity timer', tabId);
|
}
|
||||||
pending.timerId = window.setTimeout(() => {
|
if (!pending.timerId) {
|
||||||
|
pending.timerId = setTimeout(() => {
|
||||||
const existed = this._pendingTabSelection.delete(tabId);
|
const existed = this._pendingTabSelection.delete(tabId);
|
||||||
if (existed)
|
if (existed)
|
||||||
pending.connection.close('Tab is not active');
|
pending.connection.close('Tab has been inactive for 5 seconds');
|
||||||
}, 5000);
|
}, 5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _onTabUpdated(tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) {
|
||||||
|
if (changeInfo.status === 'complete' && this._connectedTabId === tabId)
|
||||||
|
void this._setConnectedTabId(tabId);
|
||||||
|
}
|
||||||
|
|
||||||
private async _getTabs(): Promise<chrome.tabs.Tab[]> {
|
private async _getTabs(): Promise<chrome.tabs.Tab[]> {
|
||||||
const tabs = await chrome.tabs.query({});
|
const tabs = await chrome.tabs.query({});
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"outDir": "./dist/lib",
|
"outDir": "./dist/lib",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
"types": ["chrome"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "react"
|
"jsxImportSource": "react"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user