plugins: APIs for those using fileShow event

Massimo Melina committed Sep 3, 2025 at 21:57 UTC ed4003ef1b0e29ce2d2923ddeb242c7e826e7586
4 files changed +27 -3
dev-plugins.md
+7 -1
@@ -446,6 +446,10 @@ In frontend you will have access to the `HFS` object of the global scope, which
446 Returns a negative if `a` must go before `b`, a positive if `b` must go before `a`, or zero they have same order.
447 It's exposed for you to use, or to overwrite if you need.
448 - `elementToEntry(el: HTMLElement): DirEntry | undefined` given a DOM element, returns the DirEntry associated to it, if any.
449 +- `isVideoComponent(Component): boolean` tell if the component is used by show for video files.
450 +- `markVideoComponent(Component): Component` if you replace the show-video component with yours, wrap it with this function.
451 +- `isAudioComponent(Component): boolean` tell if the component is used by show for audio files.
452 +- `markAudioComponent(Component): Component` if you replace the show-audio component with yours, wrap it with this function.
453
454 - The following properties are accessible only immediately at top-level; don't call it later in a callback.
455 - `getPluginConfig()` returns object of all config keys that are declared frontend-accessible by this plugin.
@@ -1054,4 +1058,6 @@ If you want to override a text regardless of the language, use the special langu
1058 - HFS.elementToEntry
1059 - backend event: checkVfsPermission
1060 - 12.9 (v0.57.14)
1057 - - frontend event fileShow gets Component parameter
\ No newline at end of file
1061 + - frontend event fileShow gets Component parameter
1062 +- 12.91 (v3.0.0)
1063 + - HFS.isVideoComponent, HFS.markVideoComponent, HFS.isAudioComponent, HFS.markAudioComponent
\ No newline at end of file
frontend/src/misc.ts
+18
@@ -99,6 +99,7 @@ Object.assign(getHFS(), {
99 h, React, state, t, _, dialogLib, apiCall, useApi, reloadList, logout, Icon, hIcon, iconBtn, useBatch, fileShow,
100 toast, domOn, getNotifications, debounceAsync, useSnapState, DirEntry, Btn,
101 fileShowComponents: { Video, Audio },
102 + isVideoComponent, markVideoComponent, isAudioComponent, markAudioComponent,
103 isShowSupported: getShowComponent,
104 misc: { ...cross, ...shared, ...thisModule },
105 emit: hfsEvent,
@@ -123,6 +124,23 @@ Object.assign(getHFS(), {
124 },
125 })
126
127 +markVideoComponent(Video)
128 +markAudioComponent(Audio)
129 +function isVideoComponent(Component: any) {
130 + return Boolean(Component?.hfs_show_video)
131 +}
132 +function markVideoComponent(Component: any) {
133 + Component.hfs_show_video = true
134 + return Component
135 +}
136 +function isAudioComponent(Component: any) {
137 + return Boolean(Component?.hfs_show_audio)
138 +}
139 +function markAudioComponent(Component: any) {
140 + Component.hfs_show_audio = true
141 + return Component
142 +}
143 +
144 export function operationSuccessful() {
145 return toast(t`Operation successful`, 'success')
146 }
\ No newline at end of file
src/const.ts
+1 -1
@@ -9,7 +9,7 @@ import { formatTimestamp } from './cross'
9 import { argv } from './argv'
10 export * from './cross-const'
11
12 -export const API_VERSION = 12.9
12 +export const API_VERSION = 12.91
13 export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
14
15 // you can add arguments with this file, currently used for the update process on mac/linux
src/plugins.ts
+1 -1
@@ -272,7 +272,7 @@ export class Plugin implements CommonPluginInterface {
272 const idx = keys.indexOf(id)
273 const moveDown = onlyTruthy(mapPlugins(((pl, plId, plIdx) => pl.afterPlugin === id && plIdx < idx && plId)))
274 const {beforePlugin, afterPlugin} = data // or this plugin that wants to be considered before another
275 - if (afterPlugin && keys.indexOf(afterPlugin) > idx)
275 + if (afterPlugin && keys.indexOf(afterPlugin) > idx)
276 moveDown.push(id)
277 if (beforePlugin && keys.indexOf(beforePlugin) < idx)
278 moveDown.push(beforePlugin)