mirror of
				https://github.com/tidys/cc-inspector-chrome
				synced 2025-10-31 20:25:25 +00:00 
			
		
		
		
	
		
			
	
	
		
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
		
		
			
		
	
	
			36 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
|   | import { Msg, Page, PluginEvent } from "../../core/types"; | |||
|  | import { PortMan } from "./portMan"; | |||
|  | import { portMgr } from "./portMgr"; | |||
|  | 
 | |||
|  | export class PortDevtools extends PortMan { | |||
|  |   init(): void { | |||
|  |     // 当devtools链接后,主动同步frames数据
 | |||
|  |     portMgr._updateFrames(); | |||
|  |     this.onDisconnect = () => { | |||
|  |       portMgr.removePort(this); | |||
|  |     } | |||
|  |     this.onMessage = (data: PluginEvent) => { | |||
|  |       if (data.msg === Msg.UseFrame) { | |||
|  |         portMgr.useFrame(data.data); | |||
|  |       } else { | |||
|  |         // 从devtools过来的消息统一派发到Content中
 | |||
|  |         if (PluginEvent.check(data, Page.Devtools, Page.Background)) { | |||
|  |           if (data.msg === Msg.TreeInfo) { | |||
|  |             if (portMgr.isCurrentFrme(data.data)) { | |||
|  |               console.log(`frameID[${data.data}]不一致`); | |||
|  |             } | |||
|  |           } | |||
|  |           PluginEvent.reset(data, Page.Background, Page.Content); | |||
|  |           const port = portMgr.getCurrentUseContent(); | |||
|  |           if (!port) { | |||
|  |             console.warn(`not find andy port`); | |||
|  |             return; | |||
|  |           } | |||
|  |           port.postMessage(data); | |||
|  |         } | |||
|  |       } | |||
|  | 
 | |||
|  |     } | |||
|  |   } | |||
|  | 
 | |||
|  | } |