Change: reuse editor in openEditor

This commit is contained in:
eight 2020-02-01 17:21:52 +08:00
parent f86a678a1f
commit 3b24e6a928
2 changed files with 12 additions and 7 deletions

View File

@ -403,13 +403,12 @@ function openEditor(params) {
searchParams.set(key, params[key]);
}
const search = searchParams.toString();
const url = chrome.runtime.getURL('edit.html') + (search && `?${search}`);
if (chrome.windows && prefs.get('openEditInWindow')) {
// FIXME: should we reuse the editor window?
chrome.windows.create(Object.assign({url}, prefs.get('windowPosition')));
} else {
openURL({url});
}
return openURL({
url: 'edit.html' + (search && `?${search}`),
newWindow: prefs.get('openEditInWindow'),
windowPosition: prefs.get('windowPosition'),
currentWindow: null
});
}
function openManage({options = false, search} = {}) {

View File

@ -99,6 +99,7 @@ const updateTab = promisify(chrome.tabs.update.bind(chrome.tabs));
const moveTabs = promisify(chrome.tabs.move.bind(chrome.tabs));
// FIXME: is it possible that chrome.windows is undefined?
const updateWindow = promisify(chrome.windows.update.bind(chrome.windows));
const createWindow = promisify(chrome.windows.create.bind(chrome.windows));
function getTab(id) {
return new Promise(resolve =>
@ -238,6 +239,8 @@ function openURL(options) {
index,
active,
currentWindow = true,
newWindow = false,
windowPosition
} = options;
if (!url.includes('://')) {
@ -271,6 +274,9 @@ function openURL(options) {
if (emptyTab && !chromeInIncognito) {
return activateTab(tab, {url, index}); // FIXME: should we move current empty tab?
}
if (newWindow) {
return createWindow(Object.assign({url}, windowPosition));
}
const options = {url, index, active};
// FF57+ supports openerTabId, but not in Android (indicated by the absence of chrome.windows)
// FIXME: is it safe to assume that the current tab is the opener?