Files
api/composables/installPlugin.ts
2023-08-08 13:50:42 -07:00

49 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const useInstallPlugin = () => {
const install = (payload = { staging: false, update: false }) => {
console.debug('[useInstallPlugin.install]', { payload });
try {
const file = `https://sfo2.digitaloceanspaces.com/unraid-dl/unraid-api/dynamix.unraid.net${payload?.staging ? '.staging.plg' : '.plg'}`;
console.debug('[useInstallPlugin.install]', file);
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') {
console.debug('[useInstallPlugin.install] using openPlugin', file);
// @ts-ignore
openPlugin(
`plugin ${payload.update ? 'update' : 'install'} ${file}`,
modalTitle,
'',
'refresh',
);
} else {
console.debug('[useInstallPlugin.install] using openBox', file);
// `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,
600,
900,
true,
);
}
} catch (error) {
console.error(error);
}
};
return {
install,
};
};
export default useInstallPlugin;