import React, { Children } from 'react' import { execute } from '../../../../../electron/core/plugin-manager/execution/extension-manager' type Props = { pluginName: string preferenceValues: any preferenceItems: any } import { formatPluginsName } from '@utils/converter' import { PluginService, preferences } from '@janhq/core' const PreferencePlugins = (props: Props) => { const { pluginName, preferenceValues, preferenceItems } = props /** * Notifies plugins of a preference update by executing the `PluginService.OnPreferencesUpdate` event. * If a timeout is already set, it is cleared before setting a new timeout to execute the event. */ let timeout: any | undefined = undefined function notifyPreferenceUpdate() { if (timeout) { clearTimeout(timeout) } timeout = setTimeout(() => execute(PluginService.OnPreferencesUpdate), 100) } return (
{formatPluginsName(pluginName)}
{preferenceItems .filter((x: any) => x.pluginName === pluginName) ?.map((e: any) => (
Setting: {e.preferenceName}
{e.preferenceDescription}
v.key === e.preferenceKey )[0]?.value } onChange={(event) => { preferences .set(e.pluginName, e.preferenceKey, event.target.value) .then(() => notifyPreferenceUpdate()) }} >
))}
) } export default PreferencePlugins