Skip to content

Commit c4574ba

Browse files
authored
Merge branch 'main' into grok-skills-inspect
2 parents 363c947 + a850895 commit c4574ba

68 files changed

Lines changed: 3018 additions & 1281 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/electron/ElectronMenu.test.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ describe("ElectronMenu", () => {
9898
const electronMenu = yield* ElectronMenu.ElectronMenu;
9999
const selectedItemId = yield* electronMenu.showContextMenu({
100100
window: makeWindow(2),
101-
items: [{ id: "copy", label: "Copy" }],
101+
items: [
102+
{ id: "copy", label: "Copy" },
103+
{ id: "delete", label: "Delete", destructive: true, separatorBefore: true },
104+
],
102105
position: Option.some({ x: 10.8, y: 20.2 }),
103106
});
104107

@@ -110,6 +113,38 @@ describe("ElectronMenu", () => {
110113
enabled: true,
111114
click: buildFromTemplateMock.mock.calls[0]?.[0][0].click,
112115
});
116+
assert.deepEqual(
117+
buildFromTemplateMock.mock.calls[0]?.[0].map(
118+
(item: Electron.MenuItemConstructorOptions) => item.type ?? item.label,
119+
),
120+
["Copy", "separator", "Delete"],
121+
);
122+
}).pipe(Effect.provide(TestLayer)),
123+
);
124+
125+
it.effect("keeps a preceding non-destructive action in the destructive section", () =>
126+
Effect.gen(function* () {
127+
buildFromTemplateMock.mockImplementation(() => ({
128+
popup: (options: Electron.PopupOptions) => options.callback?.(),
129+
}));
130+
131+
const electronMenu = yield* ElectronMenu.ElectronMenu;
132+
yield* electronMenu.showContextMenu({
133+
window: makeWindow(),
134+
items: [
135+
{ id: "copy", label: "Copy" },
136+
{ id: "archive", label: "Archive", separatorBefore: true },
137+
{ id: "delete", label: "Delete", destructive: true },
138+
],
139+
position: Option.none(),
140+
});
141+
142+
assert.deepEqual(
143+
buildFromTemplateMock.mock.calls[0]?.[0].map(
144+
(item: Electron.MenuItemConstructorOptions) => item.type ?? item.label,
145+
),
146+
["Copy", "separator", "Archive", "Delete"],
147+
);
113148
}).pipe(Effect.provide(TestLayer)),
114149
);
115150

‎apps/desktop/src/electron/ElectronMenu.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM
7878
label: sourceItem.label,
7979
destructive: sourceItem.destructive === true,
8080
disabled: sourceItem.disabled === true,
81+
...(sourceItem.separatorBefore === true ? { separatorBefore: true } : {}),
8182
};
8283

8384
if (sourceItem.children) {
@@ -141,10 +142,24 @@ export const make = Effect.gen(function* () {
141142
): Electron.MenuItemConstructorOptions[] => {
142143
const template: Electron.MenuItemConstructorOptions[] = [];
143144
let hasInsertedDestructiveSeparator = false;
145+
let sectionStartedByExplicitSeparator = false;
146+
const appendSeparator = () => {
147+
if (template.length === 0 || template.at(-1)?.type === "separator") return;
148+
template.push({ type: "separator" });
149+
};
144150

145151
for (const item of entries) {
146-
if (item.destructive && !hasInsertedDestructiveSeparator && template.length > 0) {
147-
template.push({ type: "separator" });
152+
if (item.separatorBefore) {
153+
appendSeparator();
154+
sectionStartedByExplicitSeparator = true;
155+
}
156+
if (
157+
item.destructive &&
158+
!hasInsertedDestructiveSeparator &&
159+
!sectionStartedByExplicitSeparator &&
160+
template.length > 0
161+
) {
162+
appendSeparator();
148163
hasInsertedDestructiveSeparator = true;
149164
}
150165

0 commit comments

Comments
 (0)