option to open editor in a simple window (no omnibox) (#1067)
This commit is contained in:
parent
d405bc64ae
commit
e6d73be049
|
@ -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."
|
||||||
|
|
|
@ -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')),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,47 +165,39 @@ 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,
|
||||||
openerTabId,
|
openerTabId,
|
||||||
// when hash is different we can only set `url` if it has # otherwise the tab would reload
|
// 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,
|
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);
|
|
||||||
}
|
}
|
||||||
|
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)
|
// replace empty tab (NTP or about:blank)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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({
|
||||||
|
|
|
@ -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">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user