✨ 增加日志
This commit is contained in:
parent
637c53defb
commit
29194f1010
@ -2,12 +2,14 @@ import {app, ipcMain} from "electron";
|
||||
import {getConfig, saveConfig} from "../storage/config";
|
||||
import {listVersion} from "../storage/version";
|
||||
|
||||
const log = require('electron-log');
|
||||
|
||||
export const initConfigApi = () => {
|
||||
ipcMain.on("config.saveConfig", async (event, args) => {
|
||||
saveConfig(args, (err, numberOfUpdated, upsert) => {
|
||||
if (!err) {
|
||||
const start = args.systemSelfStart || false;
|
||||
console.log('开机自启', start)
|
||||
log.info("开启自启状态", start)
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: start, //win
|
||||
openAsHidden: start, //macOs
|
||||
|
@ -7,6 +7,7 @@ import treeKill from "tree-kill";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const {exec, spawn} = require("child_process");
|
||||
const log = require('electron-log');
|
||||
export let frpcProcess = null;
|
||||
const runningCmd = {
|
||||
commandPath: null,
|
||||
@ -200,9 +201,8 @@ export const generateConfig = (
|
||||
* @param configPath
|
||||
*/
|
||||
const startFrpcProcess = (commandPath: string, configPath: string) => {
|
||||
console.log(app.getPath("userData") + "\\" + commandPath, 'commandP')
|
||||
log.info(`启动frpc 目录:${app.getPath("userData")} 命令:${commandPath}`,)
|
||||
const command = `${commandPath} -c ${configPath}`;
|
||||
console.info("启动", command)
|
||||
frpcProcess = spawn(command, {
|
||||
cwd: app.getPath("userData"),
|
||||
shell: true
|
||||
@ -210,17 +210,17 @@ const startFrpcProcess = (commandPath: string, configPath: string) => {
|
||||
runningCmd.commandPath = commandPath;
|
||||
runningCmd.configPath = configPath;
|
||||
frpcProcess.stdout.on("data", data => {
|
||||
console.debug(`命令输出: ${data}`);
|
||||
log.debug(`启动输出:${data}`)
|
||||
});
|
||||
frpcProcess.stdout.on("error", data => {
|
||||
console.log("启动错误", data)
|
||||
log.error(`启动错误:${data}`)
|
||||
stopFrpcProcess(() => {
|
||||
})
|
||||
});
|
||||
frpcStatusListener = setInterval(() => {
|
||||
const status = frpcProcessStatus()
|
||||
if (!status) {
|
||||
console.log("连接已断开")
|
||||
log.info("连接已断开")
|
||||
new Notification({
|
||||
title: "Frpc Desktop",
|
||||
body: "连接已断开,请前往日志查看原因"
|
||||
@ -240,7 +240,7 @@ export const reloadFrpcProcess = () => {
|
||||
if (config) {
|
||||
generateConfig(config, configPath => {
|
||||
const command = `${runningCmd.commandPath} reload -c ${configPath}`;
|
||||
console.info("重启", command);
|
||||
log.info(`重启:${command}`)
|
||||
exec(command, {
|
||||
cwd: app.getPath("userData"),
|
||||
shell: true
|
||||
|
@ -1,42 +1,45 @@
|
||||
import Datastore from "nedb";
|
||||
import path from "path";
|
||||
import { app } from "electron";
|
||||
import {app} from "electron";
|
||||
|
||||
const log = require('electron-log');
|
||||
|
||||
const configDB = new Datastore({
|
||||
autoload: true,
|
||||
filename: path.join(app.getPath("userData"), "config.db")
|
||||
autoload: true,
|
||||
filename: path.join(app.getPath("userData"), "config.db")
|
||||
});
|
||||
|
||||
export type Config = {
|
||||
currentVersion: any;
|
||||
serverAddr: string;
|
||||
serverPort: number;
|
||||
authMethod: string;
|
||||
authToken: string;
|
||||
logLevel: string;
|
||||
logMaxDays: number;
|
||||
tlsConfigEnable: boolean;
|
||||
tlsConfigCertFile: string;
|
||||
tlsConfigKeyFile: string;
|
||||
tlsConfigTrustedCaFile: string;
|
||||
tlsConfigServerName: string;
|
||||
proxyConfigEnable: boolean;
|
||||
proxyConfigProxyUrl: string;
|
||||
systemSelfStart: boolean;
|
||||
systemStartupConnect: boolean;
|
||||
user: string;
|
||||
metaToken: string;
|
||||
currentVersion: any;
|
||||
serverAddr: string;
|
||||
serverPort: number;
|
||||
authMethod: string;
|
||||
authToken: string;
|
||||
logLevel: string;
|
||||
logMaxDays: number;
|
||||
tlsConfigEnable: boolean;
|
||||
tlsConfigCertFile: string;
|
||||
tlsConfigKeyFile: string;
|
||||
tlsConfigTrustedCaFile: string;
|
||||
tlsConfigServerName: string;
|
||||
proxyConfigEnable: boolean;
|
||||
proxyConfigProxyUrl: string;
|
||||
systemSelfStart: boolean;
|
||||
systemStartupConnect: boolean;
|
||||
user: string;
|
||||
metaToken: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
export const saveConfig = (
|
||||
document: Config,
|
||||
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
||||
document: Config,
|
||||
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
||||
) => {
|
||||
document["_id"] = "1";
|
||||
configDB.update({ _id: "1" }, document, { upsert: true }, cb);
|
||||
document["_id"] = "1";
|
||||
log.debug("保存日志", document)
|
||||
configDB.update({_id: "1"}, document, {upsert: true}, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -44,7 +47,7 @@ export const saveConfig = (
|
||||
* @param cb
|
||||
*/
|
||||
export const getConfig = (
|
||||
cb: (err: Error | null, document: Config) => void
|
||||
cb: (err: Error | null, document: Config) => void
|
||||
) => {
|
||||
configDB.findOne({ _id: "1" }, cb);
|
||||
configDB.findOne({_id: "1"}, cb);
|
||||
};
|
||||
|
@ -61,6 +61,7 @@
|
||||
"adm-zip": "^0.5.14",
|
||||
"animate.css": "^4.1.1",
|
||||
"electron-dl": "^3.5.1",
|
||||
"electron-log": "^5.1.7",
|
||||
"tar": "^6.2.0",
|
||||
"unzipper": "^0.10.14"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user