2025-02-18 17:52:09 +08:00
|
|
|
import ServerController from "../controller/ServerController";
|
|
|
|
import ServerDao from "../dao/ServerDao";
|
|
|
|
import ServerService from "../service/ServerService";
|
|
|
|
import LogService from "../service/LogService";
|
2025-02-21 18:30:13 +08:00
|
|
|
import VersionService from "../service/VersionService";
|
2025-02-18 17:52:09 +08:00
|
|
|
import { BrowserWindow, ipcMain } from "electron";
|
|
|
|
import LogController from "../controller/LogController";
|
2025-02-21 18:30:13 +08:00
|
|
|
import VersionController from "../controller/VersionController";
|
2025-02-18 17:52:09 +08:00
|
|
|
import FileService from "../service/FileService";
|
2025-02-21 18:30:13 +08:00
|
|
|
import VersionDao from "../dao/VersionDao";
|
|
|
|
import GitHubService from "../service/GitHubService";
|
2025-02-23 21:07:44 +08:00
|
|
|
import FrpcProcessService from "../service/FrpcProcessService";
|
|
|
|
import LaunchController from "../controller/LaunchController";
|
|
|
|
import ProxyDao from "../dao/ProxyDao";
|
|
|
|
import ProxyService from "../service/ProxyService";
|
|
|
|
import ProxyController from "../controller/ProxyController";
|
2025-02-18 17:52:09 +08:00
|
|
|
|
2025-02-21 18:30:13 +08:00
|
|
|
export const ipcRouters: IpcRouters = {
|
|
|
|
SERVER: {
|
|
|
|
saveConfig: {
|
|
|
|
path: "server/saveConfig",
|
|
|
|
controller: "serverController.saveConfig"
|
|
|
|
},
|
|
|
|
getServerConfig: {
|
|
|
|
path: "server/getServerConfig",
|
|
|
|
controller: "serverController.getServerConfig"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
LOG: {
|
|
|
|
getFrpLogContent: {
|
|
|
|
path: "log/getFrpLogContent",
|
|
|
|
controller: "logController.getFrpLogContent"
|
|
|
|
},
|
|
|
|
openFrpcLogFile: {
|
|
|
|
path: "log/openFrpcLogFile",
|
|
|
|
controller: "logController.openFrpcLogFile"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
VERSION: {
|
|
|
|
getVersions: {
|
|
|
|
path: "version/getVersions",
|
|
|
|
controller: "versionController.getVersions"
|
2025-02-23 02:11:17 +08:00
|
|
|
},
|
|
|
|
downloadVersion: {
|
|
|
|
path: "version/downloadVersion",
|
|
|
|
controller: "versionController.downloadFrpVersion"
|
|
|
|
},
|
|
|
|
getDownloadedVersions: {
|
|
|
|
path: "version/getDownloadedVersions",
|
|
|
|
controller: "versionController.getDownloadedVersions"
|
|
|
|
},
|
|
|
|
deleteDownloadedVersion: {
|
|
|
|
path: "version/deleteDownloadedVersion",
|
|
|
|
controller: "versionController.deleteDownloadedVersion"
|
2025-02-21 18:30:13 +08:00
|
|
|
}
|
2025-02-23 21:07:44 +08:00
|
|
|
},
|
|
|
|
LAUNCH: {
|
|
|
|
launch: {
|
|
|
|
path: "launch/launch",
|
|
|
|
controller: "launchController.launch"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
PROXY: {
|
|
|
|
createProxy: {
|
|
|
|
path: "proxy/createProxy",
|
|
|
|
controller: "proxyController.createProxy"
|
|
|
|
},
|
|
|
|
modifyProxy: {
|
|
|
|
path: "proxy/modifyProxy",
|
|
|
|
controller: "proxyController.modifyProxy"
|
|
|
|
},
|
|
|
|
deleteProxy: {
|
|
|
|
path: "proxy/deleteProxy",
|
|
|
|
controller: "proxyController.deleteProxy"
|
|
|
|
},
|
|
|
|
getAllProxies: {
|
|
|
|
path: "proxy/getAllProxies",
|
|
|
|
controller: "proxyController.getAllProxies"
|
|
|
|
},
|
|
|
|
modifyProxyStatus: {
|
|
|
|
path: "proxy/modifyProxyStatus",
|
|
|
|
controller: "proxyController.modifyProxyStatus"
|
|
|
|
},
|
|
|
|
getLocalPorts: {
|
|
|
|
path: "proxy/getLocalPorts",
|
|
|
|
controller: "proxyController.getLocalPorts"
|
|
|
|
}
|
2025-02-21 18:30:13 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const listeners: Listeners = {
|
|
|
|
watchFrpcLog: {
|
|
|
|
listenerMethod: "logService.watchFrpcLog",
|
|
|
|
channel: "log:watchFrpcLog"
|
|
|
|
}
|
2025-02-18 17:52:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class IpcRouterConfigurate {
|
|
|
|
ipcRouters: Array<IpcRouter>;
|
2025-02-21 18:30:13 +08:00
|
|
|
private readonly _beans: Map<string, any> = new Map<string, any>();
|
2025-02-18 17:52:09 +08:00
|
|
|
private readonly _win: BrowserWindow;
|
|
|
|
|
2025-02-21 18:30:13 +08:00
|
|
|
/**
|
|
|
|
* initBeans
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
private initializeBeans() {
|
2025-02-18 17:52:09 +08:00
|
|
|
const serverDao = new ServerDao();
|
2025-02-21 18:30:13 +08:00
|
|
|
const versionDao = new VersionDao();
|
2025-02-23 21:07:44 +08:00
|
|
|
const proxyDao = new ProxyDao();
|
2025-02-18 17:52:09 +08:00
|
|
|
const fileService = new FileService();
|
2025-02-23 21:07:44 +08:00
|
|
|
const serverService = new ServerService(serverDao, proxyDao);
|
2025-02-21 18:30:13 +08:00
|
|
|
const gitHubService = new GitHubService();
|
|
|
|
const versionService = new VersionService(
|
|
|
|
versionDao,
|
|
|
|
fileService,
|
|
|
|
gitHubService
|
|
|
|
);
|
2025-02-18 17:52:09 +08:00
|
|
|
const logService = new LogService(fileService);
|
2025-02-23 21:07:44 +08:00
|
|
|
const frpcProcessService = new FrpcProcessService(
|
|
|
|
serverService,
|
|
|
|
versionDao
|
|
|
|
);
|
|
|
|
const proxyService = new ProxyService(proxyDao);
|
|
|
|
const serverController = new ServerController(serverService, fileService);
|
2025-02-23 02:11:17 +08:00
|
|
|
const versionController = new VersionController(versionService, versionDao);
|
2025-02-18 17:52:09 +08:00
|
|
|
const logController = new LogController(logService);
|
2025-02-23 21:07:44 +08:00
|
|
|
const launchController = new LaunchController(frpcProcessService);
|
|
|
|
const proxyController = new ProxyController(proxyService, proxyDao);
|
2025-02-18 17:52:09 +08:00
|
|
|
|
2025-02-21 18:30:13 +08:00
|
|
|
this._beans.set("serverDao", serverDao);
|
|
|
|
this._beans.set("versionDao", versionDao);
|
2025-02-23 21:07:44 +08:00
|
|
|
this._beans.set("proxyDao", proxyDao);
|
2025-02-21 18:30:13 +08:00
|
|
|
this._beans.set("fileService", fileService);
|
|
|
|
this._beans.set("serverService", serverService);
|
|
|
|
this._beans.set("versionService", versionService);
|
|
|
|
this._beans.set("logService", logService);
|
2025-02-23 21:07:44 +08:00
|
|
|
this._beans.set("proxyService", proxyService);
|
|
|
|
this._beans.set("frpcProcessService", frpcProcessService);
|
2025-02-21 18:30:13 +08:00
|
|
|
this._beans.set("serverController", serverController);
|
|
|
|
this._beans.set("versionController", versionController);
|
|
|
|
this._beans.set("logController", logController);
|
2025-02-23 21:07:44 +08:00
|
|
|
this._beans.set("launchController", launchController);
|
|
|
|
this._beans.set("proxyController", proxyController);
|
2025-02-21 18:30:13 +08:00
|
|
|
}
|
2025-02-18 17:52:09 +08:00
|
|
|
|
2025-02-21 18:30:13 +08:00
|
|
|
/**
|
|
|
|
* initJob
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
private initializeListeners() {
|
|
|
|
Object.keys(listeners).forEach(listenerKey => {
|
|
|
|
console.log(listenerKey, "listenerKey", listeners[listenerKey]);
|
|
|
|
const { listenerMethod, channel } = listeners[listenerKey];
|
|
|
|
const [beanName, method] = listenerMethod.split(".");
|
|
|
|
const bean = this._beans.get(beanName);
|
|
|
|
const listenerParam: ListenerParam = {
|
|
|
|
win: this._win,
|
|
|
|
channel: channel,
|
|
|
|
args: []
|
|
|
|
};
|
|
|
|
bean[method].call(bean, listenerParam);
|
|
|
|
});
|
|
|
|
console.log("initialize listeners success");
|
|
|
|
// this._beans.get("logService").watchFrpcLog(this._win);
|
2025-02-18 17:52:09 +08:00
|
|
|
}
|
|
|
|
|
2025-02-21 18:30:13 +08:00
|
|
|
/**
|
|
|
|
* initRouters
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
private initializeRouters() {
|
|
|
|
Object.keys(ipcRouters).forEach(routerKey => {
|
|
|
|
const routerGroup = ipcRouters[routerKey];
|
|
|
|
|
|
|
|
Object.keys(routerGroup).forEach(method => {
|
|
|
|
const router = routerGroup[method];
|
|
|
|
ipcMain.on(router.path, (event, args) => {
|
|
|
|
const req: ControllerParam = {
|
|
|
|
win: this._win,
|
|
|
|
channel: `${router.path}:hook`,
|
|
|
|
event: event,
|
|
|
|
args: args
|
|
|
|
};
|
|
|
|
const [beanName, method] = router.controller.split(".");
|
|
|
|
const bean = this._beans.get(beanName);
|
|
|
|
bean[method].call(bean, req);
|
|
|
|
// bean[method].call(bean, req);
|
|
|
|
});
|
2025-02-18 17:52:09 +08:00
|
|
|
});
|
|
|
|
});
|
2025-02-21 18:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
* @param win mainWindows
|
|
|
|
*/
|
|
|
|
constructor(win: BrowserWindow) {
|
|
|
|
this._win = win;
|
|
|
|
this.initializeBeans();
|
|
|
|
this.initializeListeners();
|
|
|
|
this.initializeRouters();
|
2025-02-18 17:52:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default IpcRouterConfigurate;
|