From 7c35bde51e97a1bff1d8870fff931ad6a71b01af Mon Sep 17 00:00:00 2001 From: Yujie Sun Date: Wed, 7 Jan 2026 19:43:03 +0800 Subject: [PATCH 1/2] feat(frontend): support dynamic window title i18n through Tauri API --- src-tauri/capabilities/default.json | 1 + src/locales/en.json | 6 ++++++ src/locales/zh-Hans.json | 6 ++++++ src/pages/standalone/game-error.tsx | 20 ++++++++++++++++---- src/pages/standalone/game-log.tsx | 13 ++++++++++--- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 99f32d3f4..87cbc334f 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -11,6 +11,7 @@ "core:webview:allow-create-webview-window", "core:window:allow-show", "core:window:allow-start-dragging", + "core:window:allow-set-title", "deep-link:default", "dialog:default", "log:default", diff --git a/src/locales/en.json b/src/locales/en.json index b7380707e..522be15a6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -2527,6 +2527,12 @@ }, "helper": "Enter the token generated by the device to import from" }, + "Tauri": { + "windowTitle": { + "gameLog": "Game Logs", + "gameError": "Oops! The Game Crashed." + } + }, "Utils": { "datetime": { "formatRelativeTime": { diff --git a/src/locales/zh-Hans.json b/src/locales/zh-Hans.json index a1e2dabfa..05b76e869 100644 --- a/src/locales/zh-Hans.json +++ b/src/locales/zh-Hans.json @@ -2527,6 +2527,12 @@ }, "helper": "请输入需同步设备生成的令牌" }, + "Tauri": { + "windowTitle": { + "gameLog": "游戏日志", + "gameError": "哎呀!游戏崩溃了" + } + }, "Utils": { "datetime": { "formatRelativeTime": { diff --git a/src/pages/standalone/game-error.tsx b/src/pages/standalone/game-error.tsx index d760d5b96..d64c31053 100644 --- a/src/pages/standalone/game-error.tsx +++ b/src/pages/standalone/game-error.tsx @@ -15,7 +15,7 @@ import { Tooltip, VStack, } from "@chakra-ui/react"; -import { getCurrentWebview } from "@tauri-apps/api/webview"; +import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"; import { save } from "@tauri-apps/plugin-dialog"; import { openPath, revealItemInDir } from "@tauri-apps/plugin-opener"; import { useCallback, useEffect, useState } from "react"; @@ -72,8 +72,18 @@ const GameErrorPage: React.FC = () => { setBasicInfoParams(infoList); }, [config.basicInfo, platformName]); + // set window title with i18n useEffect(() => { - let launchingId = parseIdFromWindowLabel(getCurrentWebview().label); + (async () => { + await getCurrentWebviewWindow().setTitle( + t("Tauri.windowTitle.gameError") + ); + })(); + }, [t]); + + // retrieve states and logs (for crash analysis) + useEffect(() => { + let launchingId = parseIdFromWindowLabel(getCurrentWebviewWindow().label); LaunchService.retrieveGameLaunchingState(launchingId).then((response) => { if (response.status === "success") { @@ -122,7 +132,9 @@ const GameErrorPage: React.FC = () => { }; const handleOpenLogWindow = async () => { - let launchingId = parseIdFromWindowLabel(getCurrentWebview()?.label || ""); + let launchingId = parseIdFromWindowLabel( + getCurrentWebviewWindow()?.label || "" + ); if (launchingId) { await LaunchService.openGameLogWindow(launchingId); } @@ -137,7 +149,7 @@ const GameErrorPage: React.FC = () => { const savePath = await save({ defaultPath: `minecraft-exported-crash-info-${timestamp}.zip`, }); - let launchingId = parseIdFromWindowLabel(getCurrentWebview().label); + let launchingId = parseIdFromWindowLabel(getCurrentWebviewWindow().label); if (!savePath || !launchingId) return; setIsLoading(true); const res = await LaunchService.exportGameCrashInfo(launchingId, savePath); diff --git a/src/pages/standalone/game-log.tsx b/src/pages/standalone/game-log.tsx index f4d44f17a..0195eb373 100644 --- a/src/pages/standalone/game-log.tsx +++ b/src/pages/standalone/game-log.tsx @@ -9,7 +9,7 @@ import { Tooltip, } from "@chakra-ui/react"; import { appLogDir, join } from "@tauri-apps/api/path"; -import { getCurrentWebview } from "@tauri-apps/api/webview"; +import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"; import { revealItemInDir } from "@tauri-apps/plugin-opener"; import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; @@ -41,11 +41,18 @@ const GameLogPage: React.FC = () => { const clearLogs = () => setLogs([]); + // set window title with i18n + useEffect(() => { + (async () => { + await getCurrentWebviewWindow().setTitle(t("Tauri.windowTitle.gameLog")); + })(); + }, [t]); + // invoke retrieve on first load useEffect(() => { (async () => { launchingIdRef.current = parseIdFromWindowLabel( - getCurrentWebview().label + getCurrentWebviewWindow().label ); const launchingId = launchingIdRef.current; if (launchingId) { @@ -55,7 +62,7 @@ const GameLogPage: React.FC = () => { } } })(); - }, []); + }, [t]); // keep listening to game process output useEffect(() => { From 57dd34f53eafea6f5f4ce2aa9d361599d9de8530 Mon Sep 17 00:00:00 2001 From: Yujie Sun <94227543+UNIkeEN@users.noreply.github.com> Date: Wed, 7 Jan 2026 21:29:58 +0800 Subject: [PATCH 2/2] fix Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/pages/standalone/game-log.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/standalone/game-log.tsx b/src/pages/standalone/game-log.tsx index 0195eb373..07696e49d 100644 --- a/src/pages/standalone/game-log.tsx +++ b/src/pages/standalone/game-log.tsx @@ -62,7 +62,7 @@ const GameLogPage: React.FC = () => { } } })(); - }, [t]); + }, []); // keep listening to game process output useEffect(() => {