mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] devtools: fix display and message passing for firefox
This commit fixes 2 issues specific to the firefox version of the extension: First issue concerns the computation the position of the border between the subwindows of the components tab which could go terribly wrong due to the fact that the innerwidth of the window is implicitly set to 10 when the owl devtools window is hidden. Second issue comes from changes in the runtime.onMessage method of browser which now requires to directly return the response instead of using the sendResponse method. Also perform a little cleanup on usage of browserInstance and in the manifest.
This commit is contained in:
committed by
Géry Debongnie
parent
fee3eecd7f
commit
fb013ccc72
@@ -29,7 +29,7 @@
|
|||||||
"scripts": ["background.js"]
|
"scripts": ["background.js"]
|
||||||
},
|
},
|
||||||
"devtools_page": "devtools_app/devtools.html",
|
"devtools_page": "devtools_app/devtools.html",
|
||||||
"content_security_policy": "script-src 'self' 'unsafe-eval' blob:; object-src 'self'",
|
"content_security_policy": "script-src 'self'; object-src 'self'",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["<all_urls>"],
|
"matches": ["<all_urls>"],
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { IS_FIREFOX, getActiveTabURL } from "./utils";
|
import { IS_FIREFOX, getActiveTabURL, browserInstance } from "./utils";
|
||||||
|
|
||||||
let owlStatus = 0;
|
let owlStatus = 0;
|
||||||
|
|
||||||
const browserInstance = IS_FIREFOX ? browser : chrome;
|
|
||||||
|
|
||||||
// Used to keep track of the tabs where the owl devtools have been opened
|
// Used to keep track of the tabs where the owl devtools have been opened
|
||||||
const activePanels = new Map();
|
const activePanels = new Map();
|
||||||
|
|
||||||
@@ -71,6 +69,9 @@ function checkOwlStatus(tabId) {
|
|||||||
browserInstance.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
|
browserInstance.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
|
||||||
// Send back the owl status to the sender
|
// Send back the owl status to the sender
|
||||||
if (message.type === "getOwlStatus") {
|
if (message.type === "getOwlStatus") {
|
||||||
|
if (IS_FIREFOX) {
|
||||||
|
return { result: owlStatus };
|
||||||
|
}
|
||||||
sendResponse({ result: owlStatus });
|
sendResponse({ result: owlStatus });
|
||||||
return true;
|
return true;
|
||||||
} else if (message.type === "owlStatus") {
|
} else if (message.type === "owlStatus") {
|
||||||
@@ -112,11 +113,10 @@ browserInstance.runtime.onMessage.addListener(async (message, sender, sendRespon
|
|||||||
}, 750);
|
}, 750);
|
||||||
activePanels.set(message.id, { port: port, expirationTimeout: expirationTimeout });
|
activePanels.set(message.id, { port: port, expirationTimeout: expirationTimeout });
|
||||||
// This is solely for firefox which doesnt allow access to the chrome.tabs api inside devtools
|
// This is solely for firefox which doesnt allow access to the chrome.tabs api inside devtools
|
||||||
|
// We therefore only use the firefox syntax to send the response here
|
||||||
} else if (message.type === "getActiveTabURL") {
|
} else if (message.type === "getActiveTabURL") {
|
||||||
getActiveTabURL().then((tab) => {
|
const tab = await getActiveTabURL();
|
||||||
sendResponse({ result: tab });
|
return { result: tab };
|
||||||
});
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
const destinationPanel = activePanels.get(sender.tab.id);
|
const destinationPanel = activePanels.get(sender.tab.id);
|
||||||
if (destinationPanel) {
|
if (destinationPanel) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import globalHook from "./page_scripts/owl_devtools_global_hook";
|
import globalHook from "./page_scripts/owl_devtools_global_hook";
|
||||||
import { IS_FIREFOX } from "./utils";
|
import { IS_FIREFOX, browserInstance } from "./utils";
|
||||||
|
|
||||||
// Relays the owlDevtools__... type top window messages to the background script so that it can relay it to the devtools app
|
// Relays the owlDevtools__... type top window messages to the background script so that it can relay it to the devtools app
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
@@ -7,7 +7,7 @@ window.addEventListener(
|
|||||||
function (event) {
|
function (event) {
|
||||||
if (event.data.type && event.data.source === "owl-devtools") {
|
if (event.data.type && event.data.source === "owl-devtools") {
|
||||||
try {
|
try {
|
||||||
chrome.runtime.sendMessage(
|
browserInstance.runtime.sendMessage(
|
||||||
event.data.data
|
event.data.data
|
||||||
? { type: event.data.type, data: event.data.data, origin: event.data.origin }
|
? { type: event.data.type, data: event.data.data, origin: event.data.origin }
|
||||||
: { type: event.data.type, origin: event.data.origin }
|
: { type: event.data.type, origin: event.data.origin }
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { IS_FIREFOX } from "../utils";
|
import { IS_FIREFOX, browserInstance } from "../utils";
|
||||||
|
|
||||||
let created = false;
|
let created = false;
|
||||||
let browserInstance = IS_FIREFOX ? browser : chrome;
|
|
||||||
|
|
||||||
// Try to load the owl panel each 1000 ms in case it (re)appears on the page later on
|
// Try to load the owl panel each 1000 ms in case it (re)appears on the page later on
|
||||||
const checkInterval = setInterval(createPanelsIfOwl, 1000);
|
const checkInterval = setInterval(createPanelsIfOwl, 1000);
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ export class ComponentsTab extends Component {
|
|||||||
|
|
||||||
onWindowResize = () => {
|
onWindowResize = () => {
|
||||||
const minWidth = (147 / window.innerWidth) * 100;
|
const minWidth = (147 / window.innerWidth) * 100;
|
||||||
this.store.splitPosition = Math.max(this.store.splitPosition, minWidth);
|
if (minWidth <= 100) {
|
||||||
|
this.store.splitPosition = Math.max(this.store.splitPosition, minWidth);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1,11 +1,9 @@
|
|||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
|
|
||||||
import { isElementInCenterViewport, minimizeKey, IS_FIREFOX } from "../../../../utils";
|
import { isElementInCenterViewport, minimizeKey, browserInstance } from "../../../../utils";
|
||||||
import { useStore } from "../../../store/store";
|
import { useStore } from "../../../store/store";
|
||||||
import { HighlightText } from "./highlight_text/highlight_text";
|
import { HighlightText } from "./highlight_text/highlight_text";
|
||||||
|
|
||||||
const browserInstance = IS_FIREFOX ? browser : chrome;
|
|
||||||
|
|
||||||
const { Component, useRef, useState, useEffect, onMounted } = owl;
|
const { Component, useRef, useState, useEffect, onMounted } = owl;
|
||||||
|
|
||||||
export class TreeElement extends Component {
|
export class TreeElement extends Component {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
const { reactive, useState, toRaw } = owl;
|
const { reactive, useState, toRaw } = owl;
|
||||||
import { fuzzySearch, IS_FIREFOX, getActiveTabURL } from "../../utils";
|
import { fuzzySearch, IS_FIREFOX, getActiveTabURL, browserInstance } from "../../utils";
|
||||||
import globalHook from "../../page_scripts/owl_devtools_global_hook";
|
import globalHook from "../../page_scripts/owl_devtools_global_hook";
|
||||||
|
|
||||||
const browserInstance = IS_FIREFOX ? browser : chrome;
|
|
||||||
|
|
||||||
// Main store which contains all states that needs to be maintained throughout all components in the devtools app
|
// Main store which contains all states that needs to be maintained throughout all components in the devtools app
|
||||||
export const store = reactive({
|
export const store = reactive({
|
||||||
devtoolsId: 0,
|
devtoolsId: 0,
|
||||||
@@ -943,10 +941,9 @@ function arraysEqual(arr1, arr2) {
|
|||||||
|
|
||||||
async function getTabURL() {
|
async function getTabURL() {
|
||||||
if (IS_FIREFOX) {
|
if (IS_FIREFOX) {
|
||||||
// This happens in firefox when the method is called inside devtools so we ask the background to execute it instead
|
// It is not possible to run getActiveTabURL inside the devtools when using firefox so we ask the background to execute it instead
|
||||||
browserInstance.runtime.sendMessage({ type: "getActiveTabURL" }).then((response) => {
|
const response = await browserInstance.runtime.sendMessage({ type: "getActiveTabURL" });
|
||||||
return response.result;
|
return response.result;
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
return await getActiveTabURL();
|
return await getActiveTabURL();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export const IS_FIREFOX = navigator.userAgent.indexOf("Firefox") !== -1;
|
export const IS_FIREFOX = navigator.userAgent.indexOf("Firefox") !== -1;
|
||||||
|
|
||||||
const browserInstance = IS_FIREFOX ? browser : chrome;
|
export const browserInstance = IS_FIREFOX ? browser : chrome;
|
||||||
|
|
||||||
export async function getOwlStatus() {
|
export async function getOwlStatus() {
|
||||||
const response = await browserInstance.runtime.sendMessage({ type: "getOwlStatus" });
|
const response = await browserInstance.runtime.sendMessage({ type: "getOwlStatus" });
|
||||||
|
|||||||
Reference in New Issue
Block a user