@samitouri / QOSami-HFS / commits / 849db522

plugins: support async for fileMenu event

Massimo Melina committed Mar 22, 2025 at 20:36 UTC 849db522fba6e99830bb5ee1e6d9a8f047c8c699
2 files changed +4 -3
dev-plugins.md
+2 -1
@@ -451,7 +451,7 @@ This is a list of available frontend-events, with respective object parameter an
451 - add or manipulate entries of the menu. If you return something, that will be added to the menu.
452 You can also delete or replace the content of the `menu` array.
453 - parameter `{ entry: DirEntry, menu: FileMenuEntry[], props: FileMenuProp[] }`
454 - - output `undefined | FileMenuEntry | FileMenuEntry[]`
454 + - output `Promisable<undefined | FileMenuEntry | FileMenuEntry[]>`
455 ```typescript
456 interface FileMenuEntry {
457 id?: string,
@@ -807,6 +807,7 @@ If you want to override a text regardless of the language, use the special langu
807 - api.setInterval, setTimeout
808 - HFS.Btn
809 - HFS.watchState added third parameter
810 + - frontend events: async for fileMenu and html-producers
811 - 11.6 (v0.56.0)
812 - api.setError
813 - frontend events: afterBreadcrumbs, afterFolderStats, afterFilter
frontend/src/fileMenu.ts
+2 -2
@@ -29,7 +29,7 @@ interface FileMenuEntry {
29 onClick?: (ev:MouseEvent<Element>) => any
30 }
31
32 -export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (Falsy | FileMenuEntry | 'open' | 'delete' | 'show')[]) {
32 +export async function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (Falsy | FileMenuEntry | 'open' | 'delete' | 'show')[]) {
33 const { uri, isFolder, s } = entry
34 const canRead = !entry.p?.includes('r')
35 const canList = !entry.p?.match(/L/i)
@@ -88,7 +88,7 @@ export function openFileMenu(entry: DirEntry, ev: MouseEvent, addToMenu: (Falsy
88 },
89 isFolder && !entry.cantOpen && { id: 'folderSize', label: t`Size`, value: h(FolderSize) },
90 ].filter(Boolean)
91 - const res = hfsEvent('fileMenu', { entry, menu, props })
91 + const res = await Promise.all(hfsEvent('fileMenu', { entry, menu, props }))
92 menu.push(...res.flat()) // flat because each plugin may return an array of entries
93 _.remove(menu, (x, i) => _.find(menu, y => x.id ? x.id === y.id : (!y.id && x.label === y.label), i + 1)) // avoid duplicates, keeping later ones
94 const ico = getEntryIcon(entry)