52 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-04-03 16:47:16 +08:00
import * as PluginMsg from '../core/plugin-msg'
import Manifest from '../manifest.json'
if (chrome && chrome.devtools) {
// 对应的是Elements面板的边栏
chrome.devtools.panels.elements.createSidebarPane('Cocos', function (sidebar) {
sidebar.setObject({some_data: "some data to show!"});
});
2021-04-22 19:09:35 +08:00
// 和background建立连接
let connect: chrome.runtime.Port | null = null;
if (chrome && chrome.runtime) {
connect = chrome.runtime.connect({name: PluginMsg.Page.DevToolsPanel});
}
2021-04-03 16:47:16 +08:00
// 创建devtools-panel
chrome.devtools.panels.create("Cocos", "icons/48.png", Manifest.devtools_page, (panel: chrome.devtools.panels.ExtensionPanel) => {
console.log("[CC-Inspector] Dev Panel Created!");
2021-04-22 19:09:35 +08:00
if (!connect) {
return;
}
connect.onDisconnect.addListener(() => {
2021-04-05 19:31:34 +08:00
console.log(`%c[Connect-Dis]`, 'color:red;')
})
2021-04-22 19:09:35 +08:00
connect.onMessage.addListener((event, sender) => {
2021-04-05 18:38:44 +08:00
console.log(`[Message] ${JSON.stringify(event)}`);
2021-04-03 16:47:16 +08:00
});
panel.onShown.addListener((window) => {
2021-04-22 19:09:35 +08:00
// 面板显示查询是否是cocos游戏
2021-04-03 16:47:16 +08:00
console.log("panel show");
2021-04-22 19:09:35 +08:00
if (connect) {
connect.postMessage({msg: PluginMsg.Msg.UrlChange, data: {}})
}
2021-04-03 16:47:16 +08:00
});
panel.onHidden.addListener(() => {
2021-04-22 19:09:35 +08:00
// 面板隐藏
2021-04-03 16:47:16 +08:00
console.log("panel hide");
});
panel.onSearch.addListener(function (action, query) {
2021-04-22 19:09:35 +08:00
// ctrl+f 查找触发
if (connect) {
console.log("panel search!");
}
2021-04-03 16:47:16 +08:00
});
}
);
}