no message

This commit is contained in:
许彦峰
2019-03-18 18:03:07 +08:00
parent ffc404b67a
commit c293754259
8 changed files with 97 additions and 31 deletions

View File

@@ -2,11 +2,12 @@ let PluginMsg = require("../core/plugin-msg");
// 链接池子
let ConnPool = {
Devtools: null,
DevtoolsPanel: null,
Content: null,
};
function shortConnectionLink(request, sender, sendResponse) {
console.log(`%c[短连接|id:${sender.id}|url:${sender.url}]\n${JSON.stringify(request)}`, 'background:#aaa;color:#BD4E19')
// console.log(`%c[短连接|id:${sender.id}|url:${sender.url}]\n${JSON.stringify(request)}`, 'background:#aaa;color:#BD4E19')
sendResponse && sendResponse(request);
if (request.msg === PluginMsg.Msg.Support ||
request.msg === PluginMsg.Msg.ListInfo ||
@@ -19,6 +20,11 @@ function shortConnectionLink(request, sender, sendResponse) {
function longConnectionLink(data, sender) {
console.log(`%c[长连接:${sender.name}]\n${JSON.stringify(data)}`, 'background:#aaa;color:#bada55')
sender.postMessage(data);
if (data.msg === PluginMsg.Msg.UrlChange) {
if (sender.name === PluginMsg.Page.DevToolsPanel) {
ConnPool.Content && ConnPool.Content.postMessage({msg: PluginMsg.Msg.UrlChange, data: {}})
}
}
// chrome.tabs.executeScript(message.tabId, {code: message.content});
// port.postMessage(message);
}
@@ -32,12 +38,20 @@ chrome.runtime.onConnect.addListener(function (port) {
port.onMessage.removeListener(longConnectionLink);
if (port.name === PluginMsg.Page.Devtools) {
ConnPool.Devtools = null;
} else if (port.name === PluginMsg.Page.Content) {
ConnPool.Content = null;
} else if (port.name === PluginMsg.Page.DevToolsPanel) {
ConnPool.DevtoolsPanel = null;
}
});
// 缓存
if (port.name === PluginMsg.Page.Devtools) {
ConnPool.Devtools = port;
} else if (port.name === PluginMsg.Page.Content) {
ConnPool.Content = port;
} else if (port.name === PluginMsg.Page.DevToolsPanel) {
ConnPool.DevtoolsPanel = port;
}
});
@@ -45,6 +59,12 @@ chrome.runtime.onConnect.addListener(function (port) {
// [短连接] 监听来自content.js发来的事件
chrome.runtime.onMessage.addListener(shortConnectionLink);
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status === "complete") {
// 加载新的url
ConnPool.Content.postMessage({msg: PluginMsg.Msg.UrlChange, data: {url: tab.favIconUrl}});
}
})
function createPluginMenus() {
// 右键菜单