plugins: HFS.fileShowComponents
Massimo Melina committed
Dec 15, 2024 at 12:31 UTC
d9b0a28d06e98f1362472e6ec7c955fbbf9aa03f
4 files changed
+12
-9
dev-plugins.md
+4
-2
@@ -294,7 +294,8 @@ The HFS objects contains many properties:
294
in case you need to add to the list, do it by instantiating this class. E.g. `new HFS.DirEntry(name)`
295
- `fileShow(entry: DirEntry, options?: { startPlaying: true )` open file-show on the specified entry.
296
- `copyTextToClipboard(text: string)` self-explanatory.
297
-- `urlParams: object` you'll find each parameter in the URL mapped in this object as string.
297
+- `urlParams: object` you'll find each parameter in the URL mapped in this object as string.
298
+- `fileShowComponents: { Video, Audio }` expose standard components used by file-show. Can be useful if you need extend them, inside `fileShow` event.
299
300
The following properties are accessible only immediately at top-level; don't call it later in a callback.
301
- `getPluginConfig()` returns object of all config keys that are declared frontend-accessible by this plugin.
@@ -695,7 +696,7 @@ If you want to override a text regardless of the language, use the special langu
696
697
## API version history
698
698
- - 10.2 (v0.55.0)
699
+ - 10.3 (v0.55.0)
700
- HFS.copyTextToClipboard
701
- HFS.urlParams
702
- exports.beforePlugin + afterPlugin
@@ -704,6 +705,7 @@ If you want to override a text regardless of the language, use the special langu
705
- init can now return directly the unload function
706
- api.i18n
707
- frontend event: newListEntries
708
+ - HFS.fileShowComponents
709
- 9.6 (v0.54.0)
710
- frontend event: showPlay
711
- api.addBlock
frontend/src/misc.ts
+2
-1
@@ -15,7 +15,7 @@ import { reloadList } from './useFetchList'
15
import { logout } from './login'
16
import { subscribeKey } from 'valtio/utils'
17
import { uploadState } from './uploadQueue'
18
-import { fileShow } from './show'
18
+import { fileShow, Video, Audio } from './show'
19
import { debounceAsync } from '../../src/debounceAsync'
20
export * from '@hfs/shared'
21
import i18n from './i18n'
@@ -76,6 +76,7 @@ export function formatTimestamp(x: number | string | Date, options?: Intl.DateTi
76
Object.assign(getHFS(), {
77
h, React, state, t, _, dialogLib, apiCall, useApi, reloadList, logout, Icon, hIcon, iconBtn, useBatch, fileShow,
78
toast, domOn, getNotifications, debounceAsync, useSnapState, DirEntry,
79
+ fileShowComponents: { Video, Audio },
80
misc: { ...cross, ...shared },
81
emit: hfsEvent,
82
watchState(k: string, cb: (v: any) => void) {
frontend/src/show.ts
+5
-5
@@ -234,13 +234,13 @@ export function fileShow(entry: DirEntry, { startPlaying=false, startShuffle=fal
234
235
function curFailed(err?: Error) {
236
console.debug(err)
237
- if (err?.name === 'NotAllowedError') { // browser won't allow automatic audio playing without user interaction
237
+ if (err?.name === 'NotAllowedError') { // browser won't allow automatic audio playing without user interaction...
238
if (!playMsgOnce) return
239
playMsgOnce = false
240
const el = getShowElement()
241
if (!(el instanceof HTMLMediaElement)) return
242
const mel = el as HTMLMediaElement
243
- const dlg = newDialog({ // so we offer
243
+ const dlg = newDialog({ // ...so we offer a simple dialog with a button
244
onClose: () => playMsgOnce = true,
245
Content: () => h(Btn, {
246
autoFocus: true,
@@ -254,7 +254,7 @@ export function fileShow(entry: DirEntry, { startPlaying=false, startShuffle=fal
254
})
255
return
256
}
257
- const mediaError = (document.querySelector('.showing-container .showing') as any)?.error?.code // only presenti in video/audio elements
257
+ const mediaError = (document.querySelector('.showing-container .showing') as any)?.error?.code // only present in video/audio elements
258
if (mediaError === 2) return // happens when chrome fails to fetch cover for videos. We don't skip the file for this reason. Tested on chrome129/windows
259
if (cur !== lastGood.current)
260
return go()
@@ -376,11 +376,11 @@ export function getShowComponent(entry: DirEntry) {
376
: ''
377
}
378
379
-function Audio({ onLoad, ...rest }: any) {
379
+export function Audio({ onLoad, ...rest }: any) {
380
return h('audio', { onLoadedData: onLoad, controls: true, ...rest })
381
}
382
383
-function Video({ onLoad, ...rest }: any) {
383
+export function Video({ onLoad, ...rest }: any) {
384
return h('video', { onLoadedData: onLoad, controls: true, ...rest })
385
}
386
src/const.ts
+1
-1
@@ -8,7 +8,7 @@ import { basename, dirname, join } from 'path'
8
import { formatTimestamp } from './cross'
9
export * from './cross-const'
10
11
-export const API_VERSION = 10.2
11
+export const API_VERSION = 10.3
12
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
13
14
export const argv = minimist(process.argv.slice(2))