add support for native popup windows
This commit is contained in:
parent
d5708de4ee
commit
ddc7c71e4f
@ -33,6 +33,7 @@ class Backend {
|
|||||||
this.isPreparedPromise = new Promise((resolve) => (this.isPreparedResolve = resolve));
|
this.isPreparedPromise = new Promise((resolve) => (this.isPreparedResolve = resolve));
|
||||||
|
|
||||||
this.clipboardPasteTarget = document.querySelector('#clipboard-paste-target');
|
this.clipboardPasteTarget = document.querySelector('#clipboard-paste-target');
|
||||||
|
this.popupWindow = null;
|
||||||
|
|
||||||
this.apiForwarder = new BackendApiForwarder();
|
this.apiForwarder = new BackendApiForwarder();
|
||||||
}
|
}
|
||||||
@ -565,8 +566,18 @@ class Backend {
|
|||||||
// Command handlers
|
// Command handlers
|
||||||
|
|
||||||
async _onCommandSearch(params) {
|
async _onCommandSearch(params) {
|
||||||
const url = chrome.runtime.getURL('/bg/search.html');
|
const {mode, query} = params || {};
|
||||||
if (!(params && params.newTab)) {
|
|
||||||
|
const optionsContext = {depth: 0};
|
||||||
|
const options = await this.getOptions(optionsContext);
|
||||||
|
const {popupWidth, popupHeight} = options.general;
|
||||||
|
|
||||||
|
const baseUrl = chrome.runtime.getURL('/bg/search.html');
|
||||||
|
const queryString = (query && query.length > 0) ? `?query=${encodeURIComponent(query)}` : '';
|
||||||
|
const url = baseUrl + queryString;
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case 'sameTab':
|
||||||
try {
|
try {
|
||||||
const tab = await Backend._findTab(1000, (url2) => (
|
const tab = await Backend._findTab(1000, (url2) => (
|
||||||
url2 !== null &&
|
url2 !== null &&
|
||||||
@ -580,8 +591,21 @@ class Backend {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// NOP
|
// NOP
|
||||||
}
|
}
|
||||||
}
|
|
||||||
chrome.tabs.create({url});
|
chrome.tabs.create({url});
|
||||||
|
return;
|
||||||
|
case 'newTab':
|
||||||
|
chrome.tabs.create({url});
|
||||||
|
return;
|
||||||
|
case 'popup':
|
||||||
|
if (this.popupWindow !== null) {
|
||||||
|
chrome.windows.remove(this.popupWindow.id);
|
||||||
|
}
|
||||||
|
chrome.windows.create(
|
||||||
|
{url, width: popupWidth, height: popupHeight, type: 'popup'},
|
||||||
|
(popupWindow) => { this.popupWindow = popupWindow; }
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCommandHelp() {
|
_onCommandHelp() {
|
||||||
|
@ -30,12 +30,12 @@ function setupButtonEvents(selector, command, url) {
|
|||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
node.addEventListener('click', (e) => {
|
node.addEventListener('click', (e) => {
|
||||||
if (e.button !== 0) { return; }
|
if (e.button !== 0) { return; }
|
||||||
apiCommandExec(command, {newTab: e.ctrlKey});
|
apiCommandExec(command, {mode: e.ctrlKey ? 'newTab' : 'sameTab'});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}, false);
|
}, false);
|
||||||
node.addEventListener('auxclick', (e) => {
|
node.addEventListener('auxclick', (e) => {
|
||||||
if (e.button !== 1) { return; }
|
if (e.button !== 1) { return; }
|
||||||
apiCommandExec(command, {newTab: true});
|
apiCommandExec(command, {mode: 'newTab'});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user