Skip to content

Commit 970e030

Browse files
authored
fix(desktop): open Folder Access from a focused utility window (#8855)
* fix(desktop): open Folder Access from a focused utility window * test(desktop): cover Folder Access from a utility window in the Electron e2e
1 parent c3c3d56 commit 970e030

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎apps/desktop/e2e/local-files.spec.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,55 @@ createRoot(document.getElementById('settings')).render(
267267
await expect(prompt.getByRole('button', { name: "Don't allow", exact: true })).toBeVisible()
268268
return { prompt, result }
269269
}
270+
await test.step('File → Folder Access opens over a focused utility window', async () => {
271+
if (!app) throw new Error('Desktop app is not running')
272+
const serverShown = app.waitForEvent('window', { timeout: 10_000 })
273+
await app.evaluate(({ Menu }) => {
274+
const item = Menu.getApplicationMenu()
275+
?.items.flatMap((entry) => entry.submenu?.items ?? [])
276+
.find((entry) => entry.label === 'Server…')
277+
if (!item) throw new Error('Server menu item missing')
278+
item.click()
279+
})
280+
await expect(await serverShown).toHaveTitle('Sim - Server')
281+
await expect
282+
.poll(() =>
283+
app?.evaluate(({ BrowserWindow }) =>
284+
BrowserWindow.getAllWindows().some(
285+
(win) => win.webContents.getURL().endsWith('server.html') && win.isVisible()
286+
)
287+
)
288+
)
289+
.toBe(true)
290+
const accessMenu = await app.evaluate(({ BrowserWindow, Menu }) => {
291+
const utility = BrowserWindow.getAllWindows().find((win) =>
292+
win.webContents.getURL().endsWith('server.html')
293+
)
294+
if (!utility) throw new Error('Server window missing')
295+
const item = Menu.getApplicationMenu()
296+
?.items.flatMap((entry) => entry.submenu?.items ?? [])
297+
.find((entry) => entry.label === 'Folder Access…')
298+
if (!item) throw new Error('Folder Access menu item missing')
299+
const popup = Menu.prototype.popup
300+
let shown: { anchoredToUtility: boolean; items: string[] } | undefined
301+
Menu.prototype.popup = function (this: Electron.Menu, options) {
302+
shown = {
303+
anchoredToUtility: options?.window === utility,
304+
items: this.items.map((entry) => entry.label),
305+
}
306+
}
307+
try {
308+
item.click(undefined, utility)
309+
} finally {
310+
Menu.prototype.popup = popup
311+
}
312+
utility.close()
313+
return shown
314+
})
315+
expect(accessMenu?.anchoredToUtility).toBe(true)
316+
expect(accessMenu?.items).toContain('Add Folder…')
317+
})
318+
270319
await test.step('Stop cancels only its own request while chats share a folder prompt', async () => {
271320
const sharedFolder = join(root, 'Shared')
272321
mkdirSync(sharedFolder)

‎apps/desktop/src/main/menu.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function buildMenuTemplate(deps: MenuDeps): MenuItemConstructorOptions[]
216216
{
217217
label: 'Folder Access…',
218218
click: (_item, focusedWindow) => {
219-
const win = focusedMainOrFallback(focusedWindow)
219+
const win = focusedWindowOrMain(focusedWindow)
220220
if (win) deps.openFolderAccess(win)
221221
},
222222
},

0 commit comments

Comments
 (0)