option to open editor in a simple window (no omnibox) (#1067)

This commit is contained in:
tophf 2020-10-18 16:37:42 +03:00 committed by GitHub
parent d405bc64ae
commit e6d73be049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 34 deletions

View File

@ -1122,6 +1122,10 @@
"message": "Action menu",
"description": "Tooltip for menu button in popup."
},
"popupOpenEditInPopup": {
"message": "Use a simple window (no omnibox)",
"description": "Label for the checkbox controlling 'edit' action behavior in the popup."
},
"popupOpenEditInWindow": {
"message": "Open editor in a new window",
"description": "Label for the checkbox controlling 'edit' action behavior in the popup."

View File

@ -303,9 +303,10 @@ function openEditor(params) {
u.search = new URLSearchParams(params);
return openURL({
url: `${u}`,
newWindow: prefs.get('openEditInWindow'),
windowPosition: prefs.get('windowPosition'),
currentWindow: null
currentWindow: null,
newWindow: prefs.get('openEditInWindow') && Object.assign({},
prefs.get('openEditInWindow.popup') && {type: 'popup'},
prefs.get('windowPosition')),
});
}

View File

@ -165,47 +165,39 @@ function findExistingTab({url, currentWindow, ignoreHash = true, ignoreSearch =
* @param {number} [_.openerTabId] defaults to the active tab
* @param {Boolean} [_.active=true] `true` to activate the tab
* @param {Boolean|null} [_.currentWindow=true] `null` to check all windows
* @param {Boolean} [_.newWindow=false] `true` to open a new window
* @param {chrome.windows.CreateData} [_.windowPosition] options for chrome.windows.create
* @param {chrome.windows.CreateData} [_.newWindow] creates a new window with these params if specified
* @returns {Promise<chrome.tabs.Tab>} Promise -> opened/activated tab
*/
function openURL({
async function openURL({
url,
index,
openerTabId,
active = true,
currentWindow = true,
newWindow = false,
windowPosition,
newWindow,
}) {
if (!url.includes('://')) {
url = chrome.runtime.getURL(url);
}
return findExistingTab({url, currentWindow}).then(tab => {
if (tab) {
return activateTab(tab, {
index,
openerTabId,
// when hash is different we can only set `url` if it has # otherwise the tab would reload
url: url !== (tab.pendingUrl || tab.url) && url.includes('#') ? url : undefined,
});
}
if (newWindow && browser.windows) {
return browser.windows.create(Object.assign({url}, windowPosition))
.then(wnd => wnd.tabs[0]);
}
return getActiveTab().then((activeTab = {url: ''}) =>
isTabReplaceable(activeTab, url) ?
activateTab(activeTab, {url, openerTabId}) : // not moving the tab
createTabWithOpener(activeTab, {url, index, active}));
});
function createTabWithOpener(openerTab, options) {
const id = openerTabId == null ? openerTab.id : openerTabId;
if (id != null && !openerTab.incognito && openerTabIdSupported) {
options.openerTabId = id;
}
return browser.tabs.create(options);
let tab = await findExistingTab({url, currentWindow});
if (tab) {
return activateTab(tab, {
index,
openerTabId,
// when hash is different we can only set `url` if it has # otherwise the tab would reload
url: url !== (tab.pendingUrl || tab.url) && url.includes('#') ? url : undefined,
});
}
if (newWindow && browser.windows) {
return (await browser.windows.create(Object.assign({url}, newWindow)).tabs)[0];
}
tab = await getActiveTab() || {url: ''};
if (isTabReplaceable(tab, url)) {
return activateTab(tab, {url, openerTabId});
}
const id = openerTabId == null ? tab.id : openerTabId;
const opener = id != null && !tab.incognito && openerTabIdSupported && {openerTabId: id};
return browser.tabs.create(Object.assign({url, index, active}, opener));
}
// replace empty tab (NTP or about:blank)

View File

@ -4,6 +4,7 @@
self.prefs = self.INJECTED === 1 ? self.prefs : (() => {
const defaults = {
'openEditInWindow': false, // new editor opens in a own browser window
'openEditInWindow.popup': false, // new editor opens in a simplified browser window without omnibox
'windowPosition': {}, // detached window position
'show-badge': true, // display text on popup menu icon
'disableAll': false, // boss key

View File

@ -392,10 +392,11 @@ Object.assign(handleEvent, {
const openWindow = left && shift && !ctrl;
const openBackgroundTab = (middle && !shift) || (left && ctrl && !shift);
const openForegroundTab = (middle && shift) || (left && ctrl && shift);
const url = $('[href]', event.target.closest('.entry')).href;
const entry = event.target.closest('.entry');
const url = $('[href]', entry).href;
if (openWindow || openBackgroundTab || openForegroundTab) {
if (chrome.windows && openWindow) {
chrome.windows.create(Object.assign(prefs.get('windowPosition'), {url}));
API.openEditor({id: entry.styleId});
} else {
getOwnTab().then(({index}) => {
openURL({

View File

@ -111,6 +111,13 @@
<span></span>
</span>
</label>
<label>
<span i18n-text="popupOpenEditInPopup"></span>
<span class="onoffswitch">
<input type="checkbox" id="openEditInWindow.popup" class="slider">
<span></span>
</span>
</label>
<label>
<span i18n-text="popupStylesFirst"></span>
<span class="onoffswitch">