Skip to content

Commit 0af3c8b

Browse files
committed
fix(ui): break config view import cycle and satisfy lint/deadcode/i18n gates
Move the notifications section props to a leaf contract (no view.ts type import), unexport the status-event constant, use bracket access for the injected dunder global, default-case the status switch, and refresh the native i18n inventory line offset.
1 parent 2d60496 commit 0af3c8b

5 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎apps/.i18n/native-source.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29171,7 +29171,7 @@
2917129171
},
2917229172
{
2917329173
"kind": "conditional-branch",
29174-
"line": 878,
29174+
"line": 881,
2917529175
"path": "apps/macos/Sources/OpenClaw/DashboardWindowController.swift",
2917629176
"source": "[\\(host)]",
2917729177
"surface": "apple",

‎ui/src/app/native-notifications.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import { afterEach, describe, expect, it, vi } from "vitest";
44
import {
55
createNativeNotificationsCapability,
6-
NATIVE_NOTIFICATIONS_STATUS_EVENT,
76
type NativeNotificationsCapability,
87
} from "./native-notifications.ts";
98

9+
// Wire contract shared with the Mac app bridge; asserted literally on purpose.
10+
const NATIVE_NOTIFICATIONS_STATUS_EVENT = "openclaw:native-notifications-status";
11+
1012
type NativeNotificationsMessage = {
1113
type: "status" | "request-permission" | "send-test";
1214
};
@@ -51,7 +53,7 @@ describe("native notifications", () => {
5153

5254
it("seeds status from the native snapshot", () => {
5355
installBridge();
54-
(window as NativeNotificationsTestWindow).__OPENCLAW_NATIVE_NOTIFICATIONS__ = {
56+
(window as NativeNotificationsTestWindow)["__OPENCLAW_NATIVE_NOTIFICATIONS__"] = {
5557
permission: "granted",
5658
};
5759

‎ui/src/app/native-notifications.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type NativeNotificationsWindow = Window & {
2222
};
2323
};
2424

25-
export const NATIVE_NOTIFICATIONS_STATUS_EVENT = "openclaw:native-notifications-status";
25+
// Wire contract with the Mac app's dashboard bridge (DashboardWindowController+Notifications.swift).
26+
const NATIVE_NOTIFICATIONS_STATUS_EVENT = "openclaw:native-notifications-status";
2627

2728
export type NativeNotificationsCapability = {
2829
readonly snapshot: NativeNotificationsSnapshot;
@@ -63,7 +64,7 @@ export function createNativeNotificationsCapability(): NativeNotificationsCapabi
6364
}
6465

6566
const nativeWindow = window as NativeNotificationsWindow;
66-
let snapshot = snapshotFrom(nativeWindow.__OPENCLAW_NATIVE_NOTIFICATIONS__) ?? {
67+
let snapshot = snapshotFrom(nativeWindow["__OPENCLAW_NATIVE_NOTIFICATIONS__"]) ?? {
6768
permission: "unknown" as const,
6869
};
6970
const listeners = new Set<(snapshot: NativeNotificationsSnapshot) => void>();

‎ui/src/pages/config/notifications-section.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,28 @@ import {
88
} from "../../components/settings-ui.ts";
99
import { t } from "../../i18n/index.ts";
1010
import { COMMUNICATION_SETTINGS_TARGET_IDS } from "./settings-targets.ts";
11-
import type { ConfigProps } from "./view.ts";
11+
12+
export type WebPushUiState = {
13+
supported: boolean;
14+
permission: NotificationPermission | "unsupported";
15+
subscribed: boolean;
16+
loading: boolean;
17+
error?: string | null;
18+
};
19+
20+
// Leaf props contract: view.ts imports this module, so importing ConfigProps
21+
// back from view.ts would create an import cycle. ConfigProps is structurally
22+
// assignable to this subset.
23+
type NotificationsSectionProps = {
24+
connected: boolean;
25+
nativeNotifications?: { permission: NativeNotificationsPermission | "unknown" };
26+
onNativeNotificationsRequestPermission?: () => void;
27+
onNativeNotificationsSendTest?: () => void;
28+
webPush?: WebPushUiState;
29+
onWebPushSubscribe?: () => void;
30+
onWebPushUnsubscribe?: () => void;
31+
onWebPushTest?: () => void;
32+
};
1233

1334
function nativeNotificationsStatus(permission: NativeNotificationsPermission | "unknown"): {
1435
kind: "ok" | "danger" | "accent" | "muted";
@@ -21,12 +42,12 @@ function nativeNotificationsStatus(permission: NativeNotificationsPermission | "
2142
return { kind: "danger", label: t("configView.notifications.denied") };
2243
case "notDetermined":
2344
return { kind: "accent", label: t("configView.notifications.notRequested") };
24-
case "unknown":
45+
default:
2546
return { kind: "muted", label: t("configView.notifications.checking") };
2647
}
2748
}
2849

29-
export function renderNotificationsSection(props: ConfigProps) {
50+
export function renderNotificationsSection(props: NotificationsSectionProps) {
3051
const native = props.nativeNotifications;
3152
if (native) {
3253
const status = nativeNotificationsStatus(native.permission);

‎ui/src/pages/config/view.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
import { t } from "../../i18n/index.ts";
5050
import type { ConfigAutoSaveStatus } from "../../lib/config/index.ts";
5151
import type { RealtimeTalkInputDevice } from "../chat/realtime-talk-input.ts";
52-
import { renderNotificationsSection } from "./notifications-section.ts";
52+
import { renderNotificationsSection, type WebPushUiState } from "./notifications-section.ts";
5353
import { renderSettingsSelectRow } from "./settings-select-row.ts";
5454
import { APPEARANCE_SETTINGS_TARGET_IDS } from "./settings-targets.ts";
5555

@@ -61,14 +61,6 @@ const TEXT_SCALE_LABELS: Record<TextScaleStop, string> = {
6161
140: "configView.textSizes.xxl",
6262
};
6363

64-
type WebPushUiState = {
65-
supported: boolean;
66-
permission: NotificationPermission | "unsupported";
67-
subscribed: boolean;
68-
loading: boolean;
69-
error?: string | null;
70-
};
71-
7264
type SettingsMicrophoneState = {
7365
devices: RealtimeTalkInputDevice[];
7466
selectedDeviceId: string;

0 commit comments

Comments
 (0)