From 75b49d90f7795901543a333ae5299f7c69d54d1e Mon Sep 17 00:00:00 2001 From: trickypr <23250792+trickypr@users.noreply.github.com> Date: Sun, 24 Dec 2023 22:05:13 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20extension=20panel=20multip?= =?UTF-8?q?rocess=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/omnibox/PageAction.svelte | 45 ++++++++++++------- .../shared/search/providers/URLProvider.ts | 14 +++++- src/prefs.js | 3 ++ 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/content/browser/components/omnibox/PageAction.svelte b/src/content/browser/components/omnibox/PageAction.svelte index 081d21c..3d6d2e9 100644 --- a/src/content/browser/components/omnibox/PageAction.svelte +++ b/src/content/browser/components/omnibox/PageAction.svelte @@ -37,6 +37,25 @@ } }) + function setupBrowser(browser) { + browser.messageManager.addMessageListener( + 'Extension:BrowserResized', + messageReceiver, + ) + + browser.messageManager.loadFrameScript( + 'chrome://extensions/content/ext-browser-content.js', + false, + true, + ) + + browser.messageManager.sendAsyncMessage('Extension:InitBrowser', { + allowScriptsToClose: true, + maxWidth: 800, + maxHeight: 600, + }) + } + async function buildPanelBrowser() { if (browser) { browser.remove() @@ -49,7 +68,7 @@ remoteType: getBrowserRemoteType(uri), attributes: { disableglobalhistory: 'true', - messagemanagergroup: 'todo', + messagemanagergroup: 'webext-browsers', 'webextension-view-type': 'popup', }, }) @@ -58,23 +77,11 @@ panel.appendChild(lBrowser) browser = lBrowser - lBrowser.messageManager.addMessageListener( - 'Extension:BrowserResized', - messageReceiver, - ) - - lBrowser.messageManager.loadFrameScript( - 'chrome://extensions/content/ext-browser-content.js', - false, - true, - ) - - lBrowser.messageManager.sendAsyncMessage('Extension:InitBrowser', { - allowScriptsToClose: true, - maxWidth: 800, - maxHeight: 600, - }) lBrowser.style.borderRadius = 'inherit' + setupBrowser(lBrowser) + lBrowser.addEventListener('DidChangeBrowserRemoteness', () => + setupBrowser(lBrowser), + ) await spinLock(() => lBrowser.mInitialized) setURI(lBrowser, uri) @@ -138,5 +145,9 @@ height: 1em; color: var(--text); + + /* This is firefox's dark mode filter + TODO: When we have themes, toggle this correctly */ + filter: grayscale(100%) brightness(20%) invert(); } diff --git a/src/content/shared/search/providers/URLProvider.ts b/src/content/shared/search/providers/URLProvider.ts index 90fd02b..660d5e1 100644 --- a/src/content/shared/search/providers/URLProvider.ts +++ b/src/content/shared/search/providers/URLProvider.ts @@ -6,6 +6,7 @@ import tld from './data/tld.txt' const HTTPS_REGEX = /^(?https?:\/\/)?(?(\w+\.)+(?\w+))(?\/.*)?$/m +const EXTENSION_REGEX = /^moz-extension:\/\/.+$/m const CHROME_REGEX = /^chrome:\/\/.+$/m const ABOUT_REGEX = /^about:.+$/m const tlds = tld @@ -19,7 +20,12 @@ const tlds = tld * @returns If the query is a url or not */ export function isUrlLike(query: string): boolean { - if (ABOUT_REGEX.test(query) || CHROME_REGEX.test(query)) return true + if ( + ABOUT_REGEX.test(query) || + CHROME_REGEX.test(query) || + EXTENSION_REGEX.test(query) + ) + return true const match = HTTPS_REGEX.exec(query) if (match === null) return false @@ -35,7 +41,11 @@ export class URLProvider extends Provider { public async getResults(query: string): Promise { // Check against chrome urls - if (CHROME_REGEX.test(query) || ABOUT_REGEX.test(query)) + if ( + CHROME_REGEX.test(query) || + ABOUT_REGEX.test(query) || + EXTENSION_REGEX.test(query) + ) return [ { title: query, diff --git a/src/prefs.js b/src/prefs.js index a84b280..2485117 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -109,6 +109,9 @@ pref('browser.download.alwaysOpenPanel', true); // 2 - Remove the download from both session list and history. pref('browser.download.clearHistoryOnDelete', 0); +// We do this because we want page actions etc. to have color schemes +pref('svg.context-properties.content.enabled', true); + // ============================================================================= // Multithreading