admin/plugins: display warning for incompatible plugins
Massimo Melina committed
May 2, 2022 at 10:34 UTC
c165815fcb39283415ee7d66311eadd5805f7823
2 files changed
+17
-9
admin/src/PluginsPage.ts
+9
-3
@@ -1,9 +1,9 @@
1
-import { createElement as h } from "react"
1
+import { createElement as h, Fragment } from "react"
2
import { apiCall, useApiList } from './api'
3
import { DataGrid } from '@mui/x-data-grid'
4
-import { Alert, Box } from '@mui/material'
4
+import { Alert, Box, Tooltip } from '@mui/material'
5
import { IconBtn } from './misc'
6
-import { PlayCircle, Settings, StopCircle } from '@mui/icons-material'
6
+import { Error, PlayCircle, Settings, StopCircle } from '@mui/icons-material'
7
import { toast, formDialog } from './dialog'
8
import { BoolField, Field, MultiSelectField, NumberField, SelectField, StringField } from './Form'
9
import { ArrayField } from './ArrayField'
@@ -23,6 +23,12 @@ export default function PluginsPage() {
23
headerName: "name",
24
flex: .3,
25
minWidth: 150,
26
+ renderCell({ row, value }) {
27
+ return h(Fragment, {},
28
+ value,
29
+ typeof row.badApi === 'string' && h(Tooltip, { title: row.badApi, children: h(Error, { color: 'warning', sx: { ml: 1 } }) })
30
+ )
31
+ }
32
},
33
{
34
field: 'started',
server/src/plugins.ts
+8
-6
@@ -184,14 +184,16 @@ async function rescan() {
184
const module = pathLib.resolve(f)
185
const { unwatch } = watchLoad(f, async () => {
186
try {
187
- console.log(plugins[id] ? 'reloading plugin' : 'loading plugin', id)
187
+ console.log(plugins[id] ? "reloading plugin" : "loading plugin", id)
188
const { init, ...data } = await import(module)
189
delete data.default
190
deleteModule(require.resolve(module)) // avoid caching at next import
191
- if (data.apiRequired > API_VERSION)
192
- console.log('plugin', id, 'may not work correctly as it is designed for a newer version of HFS')
193
- if (data.apiRequired < COMPATIBLE_API_VERSION)
194
- console.log('plugin', id, 'may not work correctly as it is designed for an older version of HFS')
191
+ data.badApi = data.apiRequired > API_VERSION ? "may not work correctly as it is designed for a newer version of HFS"
192
+ : data.apiRequired < COMPATIBLE_API_VERSION ? "may not work correctly as it is designed for an older version of HFS"
193
+ : undefined
194
+ if (data.badApi)
195
+ console.log("plugin", id, data.badApi)
196
+
197
const res = await init?.call(null, {
198
srcDir: __dirname,
199
const: Const,
@@ -207,7 +209,7 @@ async function rescan() {
209
Object.assign(data, res)
210
new Plugin(id, data, unwatch)
211
} catch (e) {
210
- console.log('plugin error:', e)
212
+ console.log("plugin error:", e)
213
}
214
})
215
}