refactor: logger fetch logic

This commit is contained in:
huzibaca
2024-11-18 05:58:06 +08:00
parent 824325a2eb
commit 9ebd96611a
9 changed files with 50 additions and 126 deletions

View File

@@ -6,29 +6,6 @@ export async function copyClashEnv() {
return invoke<void>("copy_clash_env");
}
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.reduce<ILogItem[]>((acc, log) => {
const result = log.match(regex);
if (result) {
const [_, _time, type, payload] = result;
const time = dayjs(_time).format("MM-DD HH:mm:ss");
acc.push({ time, type, payload });
return acc;
}
const result2 = log.match(newRegex);
if (result2) {
const [_, time, type, payload] = result2;
acc.push({ time, type, payload });
}
return acc;
}, []);
}
export async function getProfiles() {
return invoke<IProfilesConfig>("get_profiles");
}