options页面组件

This commit is contained in:
2024-12-30 18:06:53 +08:00
parent 78152222f3
commit 9876c1cbcb
45 changed files with 3318 additions and 410 deletions

View File

@ -1,3 +1,4 @@
import EventEmitter from "eventemitter3";
import { connect } from "./client";
import { ApiFunction, Server } from "./server";
@ -24,6 +25,8 @@ export class Broker {
export class MessageQueue {
topicConMap: Map<string, { name: string; con: chrome.runtime.Port }[]> = new Map();
private EE: EventEmitter = new EventEmitter();
constructor(api: Server) {
api.on("messageQueue", this.handler());
}
@ -69,5 +72,16 @@ export class MessageQueue {
list?.forEach((item) => {
item.con.postMessage({ action: "message", topic, message });
});
this.EE.emit(topic, message);
}
// 只发布给当前环境
emit(topic: string, message: any) {
this.EE.emit(topic, message);
}
// 同环境下使用addListener
addListener(topic: string, handler: (message: any) => void) {
this.EE.on(topic, handler);
}
}