Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions desktop/src/main/appLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const desktopThemePreferenceWriteDelayMs = 150;
const windowsTrayIconSettleDelayMs = 16;

export class AppLifecycle {
private locale: "zh" | "en" | undefined;
private cleanupIPC: (() => void) | null = null;
private cleanupThemeIcons: (() => void) | null = null;
private desktopThemePreferenceWriteTimer: ReturnType<typeof setTimeout> | null = null;
Expand Down Expand Up @@ -94,6 +95,9 @@ export class AppLifecycle {
() => this.restartSidecar(),
() => this.show(),
(theme) => this.setThemeSource(theme),
(locale) => {
this.locale = locale;
},
);

this.configureThemeIcons();
Expand Down Expand Up @@ -538,14 +542,24 @@ export class AppLifecycle {
}

private async confirmQuit(): Promise<boolean> {
const useChinese = this.locale ? this.locale === "zh" : /^zh(?:[-_]|$)/i.test(app.getLocale());
const copy = useChinese
? {
title: "退出 CSGClaw?",
message: "退出后,本地 CSGClaw 服务和所有正在运行的智能体都会停止。",
buttons: ["退出 CSGClaw", "继续运行"],
}
: {
title: "Quit CSGClaw?",
message: "Quitting stops the local CSGClaw service and any running agents.",
buttons: ["Quit CSGClaw", "Keep Running"],
};
const options: Electron.MessageBoxOptions = {
...copy,
type: "warning",
buttons: ["Quit CSGClaw", "Keep Running"],
defaultId: 1,
cancelId: 1,
noLink: true,
title: "Quit CSGClaw?",
message: "Quitting stops the local CSGClaw service and any running agents.",
};
const window = this.windowManager?.window;
const result = window ? await dialog.showMessageBox(window, options) : await dialog.showMessageBox(options);
Expand Down
14 changes: 13 additions & 1 deletion desktop/src/main/ipcHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { registerIPCHandlers } from "./ipcHandlers";
function createHarness(response = 0) {
const handlers = new Map<string, (...args: unknown[]) => unknown>();
const opened: string[] = [];
const locales: string[] = [];
const confirmations: unknown[] = [];
const origin = "http://127.0.0.1:18080";
const frame = { url: origin + "/" };
Expand Down Expand Up @@ -60,6 +61,7 @@ function createHarness(response = 0) {
async () => {},
() => {},
() => {},
(locale) => locales.push(locale),
);
const event = { sender: contents, senderFrame: frame };
const invokeChannel = async (
Expand All @@ -69,9 +71,19 @@ function createHarness(response = 0) {
) => handlers.get(channel)!(sender, input);
const invoke = async (input: unknown, sender: unknown = event) =>
invokeChannel(DesktopIPC.openOAuth, input, sender);
return { invoke, invokeChannel, opened, confirmations };
return { invoke, invokeChannel, opened, confirmations, locales };
}

test("locale IPC accepts supported locales only from the trusted main frame", async () => {
const { invokeChannel, locales } = createHarness();

await invokeChannel(DesktopIPC.setLocale, "zh");
await invokeChannel(DesktopIPC.setLocale, "en");
await assert.rejects(invokeChannel(DesktopIPC.setLocale, "fr"), /Unsupported desktop locale/);
await assert.rejects(invokeChannel(DesktopIPC.setLocale, "zh", {}), /sender was rejected/);
assert.deepEqual(locales, ["zh", "en"]);
});

test("focus recovery IPC accepts only the trusted main frame", async () => {
const { invokeChannel } = createHarness();

Expand Down
9 changes: 9 additions & 0 deletions desktop/src/main/ipcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function registerIPCHandlers(
restartSidecar: () => Promise<void>,
showWindow: () => void,
setThemeSource: (theme: DesktopThemeSource) => void,
setLocale: (locale: "zh" | "en") => void,
): () => void {
const notifications = new TurnNotifications((roomID) => {
showWindow();
Expand Down Expand Up @@ -106,6 +107,13 @@ export function registerIPCHandlers(
assertSender(event);
setThemeSource(parseDesktopThemeSource(input));
});
ipcMain.handle(DesktopIPC.setLocale, (event, input: unknown) => {
assertSender(event);
if (input !== "zh" && input !== "en") {
throw new Error("Unsupported desktop locale.");
}
setLocale(input);
});
ipcMain.handle(DesktopIPC.setUpdateChannel, async (event, input: unknown) => {
assertSender(event);
await updater.setChannel(parseUpdateChannel(input));
Expand All @@ -123,6 +131,7 @@ export function registerIPCHandlers(
ipcMain.removeHandler(DesktopIPC.restartSidecar);
ipcMain.removeHandler(DesktopIPC.showWindow);
ipcMain.removeHandler(DesktopIPC.setThemeSource);
ipcMain.removeHandler(DesktopIPC.setLocale);
ipcMain.removeHandler(DesktopIPC.setUpdateChannel);
};
}
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DesktopIPC = {
showTurnNotification: "csgclaw:desktop:show-turn-notification",
turnNotificationClick: "csgclaw:desktop:turn-notification-click",
setThemeSource: "csgclaw:desktop:set-theme-source",
setLocale: "csgclaw:desktop:set-locale",
setWindowChromeAppearance: "csgclaw:desktop:set-window-chrome-appearance",
setUpdateChannel: "csgclaw:desktop:set-update-channel",
updateStatus: "csgclaw:desktop:update-status",
Expand Down Expand Up @@ -75,6 +76,7 @@ const bridge: DesktopBridge = Object.freeze({
return () =>
ipcRenderer.removeListener(DesktopIPC.turnNotificationClick, handler);
},
setLocale: (locale: "zh" | "en") => ipcRenderer.invoke(DesktopIPC.setLocale, locale),
setThemeSource: (theme: DesktopThemeSource) =>
ipcRenderer.invoke(DesktopIPC.setThemeSource, theme),
setWindowChromeAppearance: (appearance: DesktopWindowChromeAppearance) =>
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/shared/desktopBridge.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const DesktopIPC = {
showTurnNotification: "csgclaw:desktop:show-turn-notification",
turnNotificationClick: "csgclaw:desktop:turn-notification-click",
setThemeSource: "csgclaw:desktop:set-theme-source",
setLocale: "csgclaw:desktop:set-locale",
setWindowChromeAppearance: "csgclaw:desktop:set-window-chrome-appearance",
setUpdateChannel: "csgclaw:desktop:set-update-channel",
updateStatus: "csgclaw:desktop:update-status",
Expand Down Expand Up @@ -92,6 +93,7 @@ export type DesktopBridge = {
showTurnNotification(input: DesktopTurnNotification): Promise<void>;
onTurnNotificationClick(listener: (roomID: string) => void): () => void;
setThemeSource(theme: DesktopThemeSource): Promise<void>;
setLocale(locale: "zh" | "en"): Promise<void>;
setWindowChromeAppearance?(
appearance: DesktopWindowChromeAppearance,
): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { createTranslator } from "@/shared/i18n";
import { MessageContent } from "./MessageContent";

function questionMessage(status: "pending" | "answered") {
Expand Down Expand Up @@ -45,6 +46,19 @@ function questionMessage(status: "pending" | "answered") {
};
}

it("localizes recorded stop notices when the language changes and preserves ordinary messages", () => {
const content = "Conversation interrupted";
const message = { metadata: { csgclaw: { delivery_kind: "turn_stopped" } } };
const { rerender } = render(<MessageContent content={content} message={message} t={createTranslator("en")} />);
expect(screen.getByText(content)).toBeVisible();

rerender(<MessageContent content={content} message={message} t={createTranslator("zh")} />);
expect(screen.getByText("会话已中断")).toBeVisible();

rerender(<MessageContent content={content} t={createTranslator("zh")} />);
expect(screen.getByText(content)).toBeVisible();
});

describe("MessageContent question transcripts", () => {
it("highlights both tagged and plain mentions resolved by the server", () => {
const content =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ function MessageBody({
() => (activity || slashCommandText ? null : parseStructuredMessage(content)),
[activity, content, slashCommandText],
);
const displayContent = String(content ?? "");
const delivery = message?.metadata?.csgclaw;
const interrupted =
delivery &&
typeof delivery === "object" &&
"delivery_kind" in delivery &&
delivery.delivery_kind === "turn_stopped";
const displayContent = interrupted && t ? t("conversationInterrupted") : String(content ?? "");
const rendered = useMemo(
() =>
renderMarkdownWithCitations(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { messages } from "@/shared/i18n/messages";
import { getDesktopBridge } from "@/shared/platform/desktopBridge";
import { writeWorkspacePreference } from "@/shared/storage/workspacePreferences";
import {
HUB_NEW_BADGE_SEEN_STORAGE_KEY,
Expand Down Expand Up @@ -103,9 +104,12 @@ export function useWorkspaceShellController({

useEffect(() => {
const messageLocale = locale === "zh" ? "zh" : "en";
document.documentElement.lang = locale === "zh" ? "zh-CN" : "en";
document.documentElement.lang = messageLocale === "zh" ? "zh-CN" : "en";
document.title = messages[messageLocale].pageTitle;
writeWorkspacePreference(LOCALE_STORAGE_KEY, locale);
void getDesktopBridge()
?.setLocale?.(messageLocale)
.catch(() => {});
}, [locale]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
--desktop-titlebar-height: 48px;
--desktop-workspace-inset: 8px;
--workspace-divider-color: color-mix(in srgb, var(--line) 65%, transparent);
--workspace-sidebar-edge-color: transparent;
--workspace-resizer-rest-color: transparent;
--workspace-resizer-block-inset: calc(var(--radius-xl) + 2px);
--app-ui-viewport-height: calc(100dvh - var(--desktop-titlebar-height) - var(--desktop-workspace-inset));
display: grid;
grid-template-rows: var(--desktop-titlebar-height) minmax(0, 1fr);
Expand Down Expand Up @@ -80,9 +82,8 @@
overflow: hidden;
}
.frame .content :global(main.chat-panel) {
border: 1px solid var(--workspace-divider-color);
border-radius: var(--radius-xl);
border-color: var(--workspace-divider-color);
border-left-color: transparent;
}
.frame .content [data-chat-side-panel] {
border-left-color: var(--workspace-divider-color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
flex-direction: column;
overflow: hidden;
background: var(--sidebar);
border-right: 1px solid var(--line);
border-right: 1px solid var(--workspace-sidebar-edge-color, var(--line));
color: var(--text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
.sidebarResizer::before {
content: "";
position: absolute;
inset: 0 auto 0 11px;
inset-block: var(--workspace-resizer-block-inset, 0px);
left: 11px;
width: 2px;
border-radius: 999px;
background: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,18 @@
:global(:root[data-theme="dark"]) .mainColumn,
:global(:root[data-theme="dark"]) .contextHeader,
:global(:root[data-theme="dark"]) .contextSearch {
border-color: var(--workspace-divider-color, var(--line));
background: var(--surface);
}

:global(:root[data-theme="dark"]) .contextSearch {
border-color: var(--workspace-divider-color, var(--line));
}

.noContextSidebar > .primarySidebar,
.mainColumn {
border-right-color: var(--workspace-sidebar-edge-color, var(--workspace-divider-color, var(--line)));
}

:global(:root[data-theme="dark"]) .primaryNav,
:global(:root[data-theme="dark"]) .primaryFooter {
border-color: var(--line);
Expand Down Expand Up @@ -694,6 +702,7 @@
.primarySidebarCollapsed {
width: var(--workspace-primary-sidebar-collapsed-width);
min-width: var(--workspace-primary-sidebar-collapsed-width);
border-right-color: var(--workspace-sidebar-edge-color, var(--workspace-divider-color, var(--line)));
}

.primarySidebarCollapsed + .mainColumn {
Expand Down
2 changes: 2 additions & 0 deletions web/packages/app/src/shared/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,7 @@ export const messages = {
conversationWorkingUsingTool: "正在调用工具",
conversationWorkingWaiting: "正在等待",
conversationWorkingOpenActivity: "查看 {name} 的活动记录:{detail}",
conversationInterrupted: "会话已中断",
conversationWorkingStop: "停止",
conversationWorkingStopAria: "停止 {name} 的当前请求",
conversationWorkingStopSending: "正在发送停止请求…",
Expand Down Expand Up @@ -5928,6 +5929,7 @@ export const messages = {
conversationWorkingUsingTool: "Using tool",
conversationWorkingWaiting: "Waiting",
conversationWorkingOpenActivity: "View {name}'s activity: {detail}",
conversationInterrupted: "Conversation interrupted",
conversationWorkingStop: "Stop",
conversationWorkingStopAria: "Stop {name}'s current turn",
conversationWorkingStopSending: "Sending stop request…",
Expand Down
2 changes: 2 additions & 0 deletions web/packages/app/src/shared/platform/desktopBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export type DesktopBridge = {
setUpdateChannel(channel: DesktopUpdateChannel): Promise<DesktopUpdateStatus>;
setThemeSource(theme: DesktopThemeSource): Promise<void>;
// Optional so newer Web UIs remain compatible with older desktop shells.
setLocale?(locale: "zh" | "en"): Promise<void>;
// Optional so newer Web UIs remain compatible with older desktop shells.
setWindowChromeAppearance?(appearance: DesktopWindowChromeAppearance): Promise<void>;
onUpdateStatus(listener: (status: DesktopUpdateStatus) => void): () => void;
};
Expand Down
Loading