feat: log info

This commit is contained in:
GyDi
2022-09-05 20:30:39 +08:00
committed by GitHub
parent fcee41f00d
commit 9e7c7ac163
6 changed files with 110 additions and 34 deletions

View File

@@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
import { useSetRecoilState } from "recoil";
import { listen } from "@tauri-apps/api/event";
import { getInformation } from "@/services/api";
import { getClashLogs } from "@/services/cmds";
import { atomLogData } from "@/services/states";
const MAX_LOG_NUM = 1000;
@@ -13,6 +14,8 @@ export default function useLogSetup() {
const setLogData = useSetRecoilState(atomLogData);
useEffect(() => {
getClashLogs().then(setLogData);
let ws: WebSocket = null!;
const handler = (event: MessageEvent<any>) => {

View File

@@ -1,6 +1,29 @@
import { invoke } from "@tauri-apps/api/tauri";
import Notice from "@/components/base/base-notice";
export async function getClashLogs() {
const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/;
const newRegex = /(.+?)\s+(.+?)\s+(.+)/;
const logs = await invoke<string[]>("get_clash_logs");
return logs
.map((log) => {
const result = log.match(regex);
if (result) {
const [_, time, type, payload] = result;
return { time, type, payload };
}
const result2 = log.match(newRegex);
if (result2) {
const [_, time, type, payload] = result2;
return { time, type, payload };
}
return null;
})
.filter(Boolean) as ApiType.LogItem[];
}
export async function getProfiles() {
return invoke<CmdType.ProfilesConfig>("get_profiles");
}