Skip to content

Commit 2ba622c

Browse files
authored
refactor(ui): trim unused control UI helpers (#101632)
1 parent 4d5cd05 commit 2ba622c

6 files changed

Lines changed: 12 additions & 58 deletions

File tree

ui/src/app/native-bridge.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
navigateChatInputHistory,
55
type ChatInputHistoryState,
66
} from "../pages/chat/input-history.ts";
7-
import { createNativeChatDrafts, isWebView2, sendToNative } from "./native-bridge.ts";
7+
import { createNativeChatDrafts } from "./native-bridge.ts";
88

99
type FakeBridge = {
1010
postMessage: ReturnType<typeof vi.fn>;
@@ -46,14 +46,6 @@ afterEach(() => {
4646
});
4747

4848
describe("native chat drafts", () => {
49-
it("detects WebView2 and sends native messages", () => {
50-
expect(isWebView2()).toBe(false);
51-
const bridge = makeBridge();
52-
expect(isWebView2()).toBe(true);
53-
sendToNative({ type: "ready" });
54-
expect(bridge.posted).toEqual([{ type: "ready" }]);
55-
});
56-
5749
it("registers the listener before the ready handshake", () => {
5850
const callOrder: string[] = [];
5951
vi.stubGlobal("chrome", {

ui/src/app/native-bridge.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ type WebView2Bridge = {
55
removeEventListener(type: "message", listener: (event: MessageEvent) => void): void;
66
};
77

8-
type NativeBridgeMessage =
9-
| { type: "draft-text"; payload: { text: string } }
10-
| { type: "ready"; payload?: Record<string, unknown> };
11-
128
export type NativeChatDrafts = {
139
subscribe: (listener: (draft: string) => void) => () => void;
1410
dispose: () => void;
@@ -19,12 +15,9 @@ function getWebview(): WebView2Bridge | undefined {
1915
return webview;
2016
}
2117

22-
export function isWebView2(): boolean {
23-
return getWebview() !== undefined;
24-
}
25-
26-
export function sendToNative(msg: NativeBridgeMessage): void {
27-
getWebview()?.postMessage(msg);
18+
// Keep WebView2 messaging distinct from the DOM Window.postMessage contract.
19+
function sendToNative(message: unknown): void {
20+
getWebview()?.postMessage(message);
2821
}
2922

3023
function readNativeDraft(raw: unknown): string | null {

ui/src/app/settings.node.test.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
loadGatewaySessionSelection,
77
loadLocalUserIdentity,
88
loadSettings,
9-
saveLocalUserIdentity,
109
saveSettings,
1110
type UiSettings,
1211
} from "./settings.ts";
@@ -837,14 +836,16 @@ describe("loadSettings default gateway URL derivation", () => {
837836
});
838837
});
839838

840-
it("persists local user identity separately from gateway settings", () => {
839+
it("loads local user identity separately from gateway settings", () => {
841840
setTestLocation({
842841
protocol: "https:",
843842
host: "gateway.example:8443",
844843
pathname: "/",
845844
});
846-
847-
saveLocalUserIdentity({ name: "Buns", avatar: "🦞" });
845+
localStorage.setItem(
846+
"openclaw.control.user.v1",
847+
JSON.stringify({ name: "Buns", avatar: "🦞" }),
848+
);
848849

849850
expect(loadLocalUserIdentity()).toEqual({
850851
name: "Buns",
@@ -870,15 +871,4 @@ describe("loadSettings default gateway URL derivation", () => {
870871
avatar: null,
871872
});
872873
});
873-
874-
it("removes the persisted local user identity when cleared", () => {
875-
saveLocalUserIdentity({ name: "Buns", avatar: "data:image/png;base64,AAA" });
876-
saveLocalUserIdentity({ name: null, avatar: null });
877-
878-
expect(loadLocalUserIdentity()).toEqual({
879-
name: null,
880-
avatar: null,
881-
});
882-
expect(localStorage.getItem("openclaw.control.user.v1")).toBeNull();
883-
});
884874
});

ui/src/app/settings.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ import { normalizeChatSplitLayout, type ChatSplitLayout } from "../pages/chat/sp
4545
import { parseImportedCustomTheme, type ImportedCustomTheme } from "./custom-theme.ts";
4646
import { normalizeGatewayTokenScope } from "./gateway-scope.ts";
4747
import { parseThemeSelection, type ThemeMode, type ThemeName } from "./theme.ts";
48-
import {
49-
hasLocalUserIdentity,
50-
normalizeLocalUserIdentity,
51-
type LocalUserIdentity,
52-
} from "./user-identity.ts";
48+
import { normalizeLocalUserIdentity, type LocalUserIdentity } from "./user-identity.ts";
5349

5450
export const BORDER_RADIUS_STOPS = [0, 25, 50, 75, 100] as const;
5551
export type BorderRadiusStop = (typeof BORDER_RADIUS_STOPS)[number];
@@ -129,8 +125,6 @@ export type UiSettings = {
129125
locale?: string;
130126
};
131127

132-
export type { LocalUserIdentity } from "./user-identity.ts";
133-
134128
type LastActiveSessionHost = {
135129
settings: UiSettings;
136130
applySettings(next: UiSettings): void;
@@ -668,21 +662,6 @@ export function loadLocalUserIdentity(): LocalUserIdentity {
668662
}
669663
}
670664

671-
export function saveLocalUserIdentity(next: LocalUserIdentity) {
672-
const storage = getSafeLocalStorage();
673-
const normalized = normalizeLocalUserIdentity(next);
674-
try {
675-
if (!hasLocalUserIdentity(normalized)) {
676-
storage?.removeItem(LOCAL_USER_IDENTITY_KEY);
677-
return;
678-
}
679-
storage?.setItem(LOCAL_USER_IDENTITY_KEY, JSON.stringify(normalized));
680-
} catch {
681-
// best-effort — quota exceeded or security restrictions should not
682-
// prevent in-memory identity updates from being applied
683-
}
684-
}
685-
686665
function persistSettings(next: UiSettings, options: { selectGateway?: boolean } = {}) {
687666
persistSessionToken(next.gatewayUrl, next.token);
688667
const storage = getSafeLocalStorage();

ui/src/lib/sessions/drag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Private MIME keeps stray text and file drags from becoming session actions.
12
export const SESSION_DRAG_MIME = "application/x-openclaw-session-key";
23

34
export function writeSessionDragData(dataTransfer: DataTransfer, sessionKey: string): void {

ui/src/pages/sessions/view.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { formatSessionTokens } from "../../lib/presenter.ts";
2424
import { formatGoalDetail, formatGoalSummary } from "../../lib/session-goal.ts";
2525
import { sessionModelMatchesDefaults } from "../../lib/session-model-defaults.ts";
2626
import { isSessionRunActive } from "../../lib/session-run-state.ts";
27+
import { SESSION_DRAG_MIME } from "../../lib/sessions/drag.ts";
2728
import {
2829
groupSessionRows,
2930
SESSION_GROUP_MODES,
@@ -484,8 +485,6 @@ function sessionDetailItems(params: {
484485
}
485486

486487
const NEW_GROUP_OPTION = "__new-group__";
487-
// Private MIME so stray text/file drags never become sessions.patch calls.
488-
const SESSION_DRAG_MIME = "application/x-openclaw-session-key";
489488

490489
function sessionsTableColumnCount(props: SessionsProps): number {
491490
return props.groupBy === "category" ? 9 : 8;

0 commit comments

Comments
 (0)