reuse existing popup window
This commit is contained in:
parent
56f1f8384d
commit
89729d8c20
@ -614,17 +614,21 @@ class Backend {
|
|||||||
return baseUrl2 === baseUrl && (queryParams2.mode === mode || (!queryParams2.mode && mode === 'existingOrNewTab'));
|
return baseUrl2 === baseUrl && (queryParams2.mode === mode || (!queryParams2.mode && mode === 'existingOrNewTab'));
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (mode) {
|
const openInTab = async () => {
|
||||||
case 'existingOrNewTab':
|
|
||||||
try {
|
|
||||||
const tab = await Backend._findTab(1000, isTabMatch);
|
const tab = await Backend._findTab(1000, isTabMatch);
|
||||||
if (tab !== null) {
|
if (tab !== null) {
|
||||||
await Backend._focusTab(tab);
|
await Backend._focusTab(tab);
|
||||||
if (queryParams.query) {
|
if (queryParams.query) {
|
||||||
await new Promise((resolve) => chrome.tabs.update(tab.id, {url}, resolve));
|
await new Promise((resolve) => chrome.tabs.update(tab.id, {url}, resolve));
|
||||||
}
|
}
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case 'existingOrNewTab':
|
||||||
|
try {
|
||||||
|
if (await openInTab()) { return; }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
@ -634,18 +638,23 @@ class Backend {
|
|||||||
chrome.tabs.create({url});
|
chrome.tabs.create({url});
|
||||||
return;
|
return;
|
||||||
case 'popup':
|
case 'popup':
|
||||||
if (!isObject(chrome.windows)) {
|
try {
|
||||||
// chrome.windows not supported (e.g. on Firefox mobile)
|
// chrome.windows not supported (e.g. on Firefox mobile)
|
||||||
return;
|
if (!isObject(chrome.windows)) { return; }
|
||||||
}
|
if (await openInTab()) { return; }
|
||||||
|
// if the previous popup is open in an invalid state, close it
|
||||||
if (this.popupWindow !== null) {
|
if (this.popupWindow !== null) {
|
||||||
const callback = () => this.checkLastError(chrome.runtime.lastError);
|
const callback = () => this.checkLastError(chrome.runtime.lastError);
|
||||||
chrome.windows.remove(this.popupWindow.id, callback);
|
chrome.windows.remove(this.popupWindow.id, callback);
|
||||||
}
|
}
|
||||||
|
// open new popup
|
||||||
this.popupWindow = await new Promise((resolve) => chrome.windows.create(
|
this.popupWindow = await new Promise((resolve) => chrome.windows.create(
|
||||||
{url, width: popupWidth, height: popupHeight, type: 'popup'},
|
{url, width: popupWidth, height: popupHeight, type: 'popup'},
|
||||||
resolve
|
resolve
|
||||||
));
|
));
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user