Introduces dependency injection via Inversify and reflect-metadata, adds a service handler registry for packet handling, and updates core initialization to auto-register and bind service handlers. Also updates Vite configs and auto-include logic to support protocol service files.
25 lines
722 B
TypeScript
25 lines
722 B
TypeScript
import "reflect-metadata";
|
|
import { Container, injectable } from "inversify";
|
|
import { NapCatCore } from "../..";
|
|
|
|
export const container = new Container();
|
|
|
|
export const ReceiverServiceRegistry = new Map<string, new (...args: any[]) => ServiceBase>();
|
|
|
|
export abstract class ServiceBase {
|
|
get core(): NapCatCore {
|
|
return container.get(NapCatCore);
|
|
}
|
|
|
|
abstract handler(seq: number, hex_data: string): Promise<void> | void;
|
|
}
|
|
|
|
export function ReceiveService(serviceName: string) {
|
|
return function <T extends new (...args: any[]) => ServiceBase>(constructor: T) {
|
|
injectable()(constructor);
|
|
ReceiverServiceRegistry.set(serviceName, constructor);
|
|
return constructor;
|
|
};
|
|
}
|
|
|