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", "message": "Action menu",
"description": "Tooltip for menu button in popup." "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": { "popupOpenEditInWindow": {
"message": "Open editor in a new window", "message": "Open editor in a new window",
"description": "Label for the checkbox controlling 'edit' action behavior in the popup." "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); u.search = new URLSearchParams(params);
return openURL({ return openURL({
url: `${u}`, url: `${u}`,
newWindow: prefs.get('openEditInWindow'), currentWindow: null,
windowPosition: prefs.get('windowPosition'), newWindow: prefs.get('openEditInWindow') && Object.assign({},
currentWindow: null prefs.get('openEditInWindow.popup') && {type: 'popup'},
prefs.get('windowPosition')),
}); });
} }

View File

@ -165,23 +165,21 @@ function findExistingTab({url, currentWindow, ignoreHash = true, ignoreSearch =
* @param {number} [_.openerTabId] defaults to the active tab * @param {number} [_.openerTabId] defaults to the active tab
* @param {Boolean} [_.active=true] `true` to activate the tab * @param {Boolean} [_.active=true] `true` to activate the tab
* @param {Boolean|null} [_.currentWindow=true] `null` to check all windows * @param {Boolean|null} [_.currentWindow=true] `null` to check all windows
* @param {Boolean} [_.newWindow=false] `true` to open a new window * @param {chrome.windows.CreateData} [_.newWindow] creates a new window with these params if specified
* @param {chrome.windows.CreateData} [_.windowPosition] options for chrome.windows.create
* @returns {Promise<chrome.tabs.Tab>} Promise -> opened/activated tab * @returns {Promise<chrome.tabs.Tab>} Promise -> opened/activated tab
*/ */
function openURL({ async function openURL({
url, url,
index, index,
openerTabId, openerTabId,
active = true, active = true,
currentWindow = true, currentWindow = true,
newWindow = false, newWindow,
windowPosition,
}) { }) {
if (!url.includes('://')) { if (!url.includes('://')) {
url = chrome.runtime.getURL(url); url = chrome.runtime.getURL(url);
} }
return findExistingTab({url, currentWindow}).then(tab => { let tab = await findExistingTab({url, currentWindow});
if (tab) { if (tab) {
return activateTab(tab, { return activateTab(tab, {
index, index,
@ -191,21 +189,15 @@ function openURL({
}); });
} }
if (newWindow && browser.windows) { if (newWindow && browser.windows) {
return browser.windows.create(Object.assign({url}, windowPosition)) return (await browser.windows.create(Object.assign({url}, newWindow)).tabs)[0];
.then(wnd => wnd.tabs[0]);
} }
return getActiveTab().then((activeTab = {url: ''}) => tab = await getActiveTab() || {url: ''};
isTabReplaceable(activeTab, url) ? if (isTabReplaceable(tab, url)) {
activateTab(activeTab, {url, openerTabId}) : // not moving the tab return activateTab(tab, {url, openerTabId});
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);
} }
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) // replace empty tab (NTP or about:blank)

View File

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

View File

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

View File

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