From a0ce557783a18aa72122072c9c1d49e57fbca52b Mon Sep 17 00:00:00 2001 From: TheGuy Date: Fri, 22 Nov 2024 00:06:10 +0600 Subject: [PATCH] Add disable addon feature Fixes #725 Add functionality to disable and enable add-ons without uninstalling them. * **`src/common/AddonDetailsModal/AddonDetailsModal.js`** - Add "Disable" button for installed add-ons. - Add "Enable" button for disabled add-ons. - Modify `modalButtons` to include the new buttons. * **`src/routes/Addons/Addon/Addon.js`** - Add "Disable" button for installed add-ons. - Add "Enable" button for disabled add-ons. - Modify `toggleButtonOnClick` function to handle disabling and enabling add-ons. - Update PropTypes to include `disabled`. * **`src/services/Core/Core.js`** - Add method to disable an add-on. - Add method to enable an add-on. --- .../AddonDetailsModal/AddonDetailsModal.js | 54 +++++++++++++++++-- src/routes/Addons/Addon/Addon.js | 21 ++++++-- src/services/Core/Core.js | 26 ++++++++- 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/common/AddonDetailsModal/AddonDetailsModal.js b/src/common/AddonDetailsModal/AddonDetailsModal.js index 1ebbb2e60..e83a3edb8 100644 --- a/src/common/AddonDetailsModal/AddonDetailsModal.js +++ b/src/common/AddonDetailsModal/AddonDetailsModal.js @@ -1,5 +1,3 @@ -// Copyright (C) 2017-2023 Smart code 203358507 - const React = require('react'); const PropTypes = require('prop-types'); const ModalDialog = require('stremio/common/ModalDialog'); @@ -135,7 +133,57 @@ const AddonDetailsModal = ({ transportUrl, onCloseRequest }) => { } : null; - return configureButton && toggleButton ? [cancelButton, configureButton, toggleButton] : configureButton ? [cancelButton, configureButton] : toggleButton ? [cancelButton, toggleButton] : [cancelButton]; + const disableButton = addonDetails.localAddon !== null && !addonDetails.localAddon.disabled ? + { + className: styles['disable-button'], + label: 'Disable', + props: { + onClick: (event) => { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'DisableAddon', + args: addonDetails.localAddon + } + }); + if (typeof onCloseRequest === 'function') { + onCloseRequest({ + type: 'disable', + reactEvent: event, + nativeEvent: event.nativeEvent + }); + } + } + } + } + : + null; + const enableButton = addonDetails.localAddon !== null && addonDetails.localAddon.disabled ? + { + className: styles['enable-button'], + label: 'Enable', + props: { + onClick: (event) => { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'EnableAddon', + args: addonDetails.localAddon + } + }); + if (typeof onCloseRequest === 'function') { + onCloseRequest({ + type: 'enable', + reactEvent: event, + nativeEvent: event.nativeEvent + }); + } + } + } + } + : + null; + return [cancelButton, configureButton, toggleButton, disableButton, enableButton].filter(Boolean); }, [addonDetails, onCloseRequest]); const modalBackground = React.useMemo(() => { return addonDetails.remoteAddon?.content.type === 'Ready' ? addonDetails.remoteAddon.content.content.manifest.background : null; diff --git a/src/routes/Addons/Addon/Addon.js b/src/routes/Addons/Addon/Addon.js index ae27dca51..8e7cfebf1 100644 --- a/src/routes/Addons/Addon/Addon.js +++ b/src/routes/Addons/Addon/Addon.js @@ -1,5 +1,3 @@ -// Copyright (C) 2017-2023 Smart code 203358507 - const React = require('react'); const PropTypes = require('prop-types'); const classnames = require('classnames'); @@ -8,7 +6,7 @@ const { default: Icon } = require('@stremio/stremio-icons/react'); const { Button, Image } = require('stremio/common'); const styles = require('./styles'); -const Addon = ({ className, id, name, version, logo, description, types, behaviorHints, installed, onToggle, onConfigure, onShare, dataset }) => { +const Addon = ({ className, id, name, version, logo, description, types, behaviorHints, installed, disabled, onToggle, onConfigure, onShare, dataset }) => { const { t } = useTranslation(); const toggleButtonOnClick = React.useCallback((event) => { if (typeof onToggle === 'function') { @@ -111,6 +109,22 @@ const Addon = ({ className, id, name, version, logo, description, types, behavio >
{installed ? t('ADDON_UNINSTALL') : behaviorHints.configurationRequired ? t('ADDON_CONFIGURE') : t('ADDON_INSTALL')}
+ { + installed && !disabled ? + + : + null + } + { + installed && disabled ? + + : + null + }