admin/plugins/online: warn before installing dependencies

Massimo Melina committed Oct 27, 2023 at 19:20 UTC 7143f32f5206f099b0c49d9321d9587c9e480e47
3 files changed +9 -4
admin/src/OnlinePlugins.ts
+3 -1
@@ -10,6 +10,7 @@ import { useDebounce } from 'usehooks-ts'
10 import { renderName, startPlugin } from './InstalledPlugins'
11 import { state, useSnapState } from './state'
12 import { alertDialog, confirmDialog, toast } from './dialog'
13 +import _ from 'lodash'
14
15 export default function OnlinePlugins() {
16 const [search, setSearch] = useState('')
@@ -73,7 +74,8 @@ export default function OnlinePlugins() {
74 disabled: row.installed && "Already installed",
75 tooltipProps: { placement:'bottom-end' }, // workaround problem with horizontal scrolling by moving the tooltip leftward
76 confirm: "WARNING - Proceed only if you trust this author and this plugin",
76 - onClick() {
77 + async onClick() {
78 + if (row.missing && !await confirmDialog("This will also install: " + _.map(row.missing, 'repo').join(', '))) return
79 const branch = row.branch || row.default_branch
80 installPlugin(id, branch).catch((e: any) => {
81 if (e.code !== HTTP_FAILED_DEPENDENCY)
admin/src/VfsMenuBar.ts
+4 -3
@@ -1,14 +1,14 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { createElement as h } from 'react'
4 -import { Box } from '@mui/material'
4 +import { Alert, Box } from '@mui/material'
5 import { Add, Microsoft } from '@mui/icons-material'
6 import { reloadVfs } from './VfsPage'
7 import addFiles, { addVirtual } from './addFiles'
8 import MenuButton from './MenuButton'
9 -import { basename, Btn, reloadBtn } from './misc'
9 +import { Btn, reloadBtn } from './misc'
10 import { apiCall, useApi } from './api'
11 -import { alertDialog, confirmDialog } from './dialog'
11 +import { confirmDialog } from './dialog'
12
13 export default function VfsMenuBar({ status }: any) {
14 const { data: integrated, reload } = useApi(status?.platform === 'win32' && 'windows_integrated')
@@ -56,6 +56,7 @@ async function windowsIntegration() {
56 width: 'min(30em, 80vw)',
57 marginTop: '1em',
58 } }),
59 + h(Alert, { severity: 'info' }, "It will also automatically copy the URL, ready to paste!"),
60 )
61 return await confirmDialog(msg)
62 && apiCall('windows_integration')
src/api.plugins.ts
+2
@@ -103,6 +103,8 @@ const apis: ApiHandlers = {
103 for await (const pl of await searchPlugins(text)) {
104 const repo = pl.repo || pl.id // .repo property can be more trustworthy in case github user renamed and left the previous link in 'repo'
105 if (_.includes(folder2repo, repo)) continue // don't include installed plugins
106 + const missing = await getMissingDependencies(pl)
107 + if (missing.length) pl.missing = missing
108 list.add(pl)
109 // watch for events about this plugin, until this request is closed
110 undo.push(onOff(events, {