Skip to content

Commit e9c46b4

Browse files
authored
feat(frontend): allow open raw game log file in file explorer (UNIkeEN#1206)
1 parent 9c2a521 commit e9c46b4

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
},
852852
"GameLogPage": {
853853
"placeholder": "Filter by Text",
854-
"exportLogs": "Export Logs",
854+
"revealRawLog": "Reveal Raw Log File",
855855
"clearLogs": "Clear All Logs",
856856
"scrollToBottom": "Scroll to Bottom"
857857
},

src/locales/zh-Hans.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
},
852852
"GameLogPage": {
853853
"placeholder": "输入关键词筛选",
854-
"exportLogs": "导出日志",
854+
"revealRawLog": "显示原始日志文件",
855855
"clearLogs": "清除所有日志",
856856
"scrollToBottom": "滚动到底部"
857857
},

src/pages/standalone/game-log.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
Text,
99
Tooltip,
1010
} from "@chakra-ui/react";
11+
import { appCacheDir, join } from "@tauri-apps/api/path";
1112
import { getCurrentWebview } from "@tauri-apps/api/webview";
13+
import { revealItemInDir } from "@tauri-apps/plugin-opener";
1214
import { useEffect, useRef, useState } from "react";
1315
import { useTranslation } from "react-i18next";
1416
import { LuChevronsDown, LuFileInput, LuTrash } from "react-icons/lu";
@@ -35,13 +37,17 @@ const GameLogPage: React.FC = () => {
3537
const [isScrolledToBottom, setIsScrolledToBottom] = useState(true);
3638

3739
const logContainerRef = useRef<HTMLDivElement>(null);
40+
const launchingIdRef = useRef<number | null>(null);
3841

3942
const clearLogs = () => setLogs([]);
4043

4144
// invoke retrieve on first load
4245
useEffect(() => {
4346
(async () => {
44-
let launchingId = parseIdFromWindowLabel(getCurrentWebview().label);
47+
launchingIdRef.current = parseIdFromWindowLabel(
48+
getCurrentWebview().label
49+
);
50+
const launchingId = launchingIdRef.current;
4551
if (launchingId) {
4652
const res = await LaunchService.retrieveGameLog(launchingId);
4753
if (res.status === "success" && Array.isArray(res.data)) {
@@ -59,6 +65,24 @@ const GameLogPage: React.FC = () => {
5965
return () => unlisten();
6066
}, []);
6167

68+
const revealRawLogFile = async () => {
69+
try {
70+
const launchingId = launchingIdRef.current;
71+
if (launchingId == null) return;
72+
73+
const baseDir = await appCacheDir();
74+
const logFilePath = await join(
75+
baseDir,
76+
"GameLogs",
77+
`game_log_${launchingId}.log`
78+
);
79+
80+
await revealItemInDir(logFilePath);
81+
} catch (err) {
82+
logger.error("Failed to open raw log file:", err);
83+
}
84+
};
85+
6286
let lastLevel: string = "INFO";
6387

6488
const getLogLevel = (log: string): string => {
@@ -167,14 +191,14 @@ const GameLogPage: React.FC = () => {
167191
{level} ({logCounts[level] || 0})
168192
</Button>
169193
))}
170-
<Tooltip label={t("GameLogPage.exportLogs")} placement="bottom">
194+
<Tooltip label={t("GameLogPage.revealRawLog")} placement="bottom">
171195
<IconButton
172196
icon={<LuFileInput />}
173-
aria-label={t("GameLogPage.exportLogs")}
197+
aria-label={t("GameLogPage.revealRawLog")}
174198
variant="ghost"
175199
size="sm"
176200
colorScheme="gray"
177-
isDisabled
201+
onClick={revealRawLogFile}
178202
/>
179203
</Tooltip>
180204
<Tooltip label={t("GameLogPage.clearLogs")} placement="bottom">

0 commit comments

Comments
 (0)