2025-02-18 17:52:09 +08:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
2025-02-21 18:30:13 +08:00
|
|
|
import { app } from "electron";
|
2025-02-18 17:52:09 +08:00
|
|
|
import FileService from "./FileService";
|
|
|
|
import { success } from "../utils/response";
|
|
|
|
|
|
|
|
class LogService {
|
|
|
|
private readonly _fileService: FileService;
|
|
|
|
private readonly _logPath: string = path.join(
|
|
|
|
app.getPath("userData"),
|
|
|
|
"frpc.log"
|
|
|
|
);
|
|
|
|
|
|
|
|
constructor(fileService: FileService) {
|
|
|
|
this._fileService = fileService;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFrpLogContent(): Promise<string> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
fs.readFile(this._logPath, "utf-8", (error, data) => {
|
|
|
|
if (!error) {
|
|
|
|
resolve(data);
|
|
|
|
} else {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-21 18:30:13 +08:00
|
|
|
watchFrpcLog(listenerParam: ListenerParam) {
|
2025-02-18 17:52:09 +08:00
|
|
|
fs.watch(this._logPath, (eventType, filename) => {
|
|
|
|
if (eventType === "change") {
|
2025-02-21 18:30:13 +08:00
|
|
|
console.log("change", eventType, listenerParam.channel);
|
|
|
|
listenerParam.win.webContents.send(
|
|
|
|
listenerParam.channel,
|
2025-02-18 17:52:09 +08:00
|
|
|
success(true)
|
2025-02-21 18:30:13 +08:00
|
|
|
);
|
2025-02-18 17:52:09 +08:00
|
|
|
} else {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// return new Promise<boolean>((resolve, reject) => {
|
|
|
|
//
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
|
|
|
openFrpcLogFile(): Promise<boolean> {
|
|
|
|
return new Promise<boolean>((resolve, reject) => {
|
|
|
|
this._fileService
|
2025-02-21 18:30:13 +08:00
|
|
|
.openLocalFile(this._logPath)
|
2025-02-18 17:52:09 +08:00
|
|
|
.then(result => {
|
|
|
|
resolve(result);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LogService;
|