refactor(web): install plugin composable extensibility

This commit is contained in:
Zack Spear
2023-09-12 17:19:53 -07:00
committed by Zack Spear
parent 8b5ba1aa97
commit c5cc372d7f
2 changed files with 18 additions and 17 deletions

View File

@@ -1,30 +1,27 @@
export interface InstallPluginPayload {
modalTitle: string;
pluginUrl: string;
update?: boolean;
}
const useInstallPlugin = () => {
const install = (payload = { staging: false, update: false }) => {
const install = (payload: InstallPluginPayload) => {
try {
const file = `https://sfo2.digitaloceanspaces.com/unraid-dl/unraid-api/dynamix.unraid.net${payload?.staging ? '.staging.plg' : '.plg'}`;
if (!payload.update) {
// after initial install, the dropdown store looks for this to automatically open the launchpad dropdown
sessionStorage.setItem('clickedInstallPlugin', '1');
}
const modalTitle = payload.update ? 'Updating Connect (beta)' : 'Installing Connect (beta)';
// @ts-ignore `openPlugin` will be included in 6.10.4+ DefaultPageLayout
if (typeof openPlugin === 'function') {
// @ts-ignore
openPlugin(
`plugin ${payload.update ? 'update' : 'install'} ${file}`,
modalTitle,
`plugin ${payload.update ? 'update' : 'install'} ${payload.pluginUrl}`,
payload.modalTitle,
'',
'refresh',
);
} else {
// `openBox()` is defined in the webgui's DefaultPageLayout.php and used when openPlugin is not available
// @ts-ignore
openBox(
`/plugins/dynamix.plugin.manager/scripts/plugin&arg1=install&arg2=${file}`,
modalTitle,
`/plugins/dynamix.plugin.manager/scripts/plugin&arg1=install&arg2=${payload.pluginUrl}`,
payload.modalTitle,
600,
900,
true,