From 4ff229408a1b692be15b34bcfdf65f7be7a07b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Wed, 8 May 2024 12:36:53 +0200 Subject: [PATCH] enabled AI setting restore --- apps/remix-ide/src/app/tabs/settings-tab.tsx | 8 ++++++-- libs/remix-ui/settings/src/lib/remix-ui-settings.tsx | 4 ++-- libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx | 11 ++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/settings-tab.tsx b/apps/remix-ide/src/app/tabs/settings-tab.tsx index b32477aa17..49571922eb 100644 --- a/apps/remix-ide/src/app/tabs/settings-tab.tsx +++ b/apps/remix-ide/src/app/tabs/settings-tab.tsx @@ -15,7 +15,7 @@ const _paq = (window._paq = window._paq || []) const profile = { name: 'settings', displayName: 'Settings', - methods: ['get', 'updateCopilotChoice'], + methods: ['get', 'updateCopilotChoice', 'getCopilotSetting'], events: [], icon: 'assets/img/settings.webp', description: 'Remix-IDE settings', @@ -52,7 +52,7 @@ module.exports = class SettingsTab extends ViewPlugin { this.element = document.createElement('div') this.element.setAttribute('id', 'settingsTab') this.useMatomoAnalytics = null - this.useCopilot = false + this.useCopilot = this.get('settings/copilot/suggest/activate') } setDispatch(dispatch: React.Dispatch) { @@ -102,6 +102,10 @@ module.exports = class SettingsTab extends ViewPlugin { }) } + getCopilotSetting(){ + return this.useCopilot + } + updateMatomoAnalyticsChoice(isChecked) { this.config.set('settings/matomo-analytics', isChecked) this.useMatomoAnalytics = isChecked diff --git a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx index a4afd0b152..0a6b663a61 100644 --- a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx +++ b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx @@ -56,7 +56,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { const [ipfsProtocol, setipfsProtocol] = useState('') const [ipfsProjectId, setipfsProjectId] = useState('') const [ipfsProjectSecret, setipfsProjectSecret] = useState('') - const copilotDownload = useRef(null) const intl = useIntl() const initValue = () => { @@ -143,8 +142,9 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { } const startCopilot = async () => { - copilotActivate(props.config, true, dispatch) + copilotActivate(props.config, props.useCopilot, dispatch) props.plugin.call('terminal', 'log', { type: 'typewriterlog', value: `Solidity copilot activated!` }) + //props.plugin.call('settings', 'updateCopilotChoice', props.useCopilot) } startCopilot() diff --git a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx index 1a7d1d32da..8381c03e4a 100644 --- a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx +++ b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx @@ -64,7 +64,6 @@ export const TabsUI = (props: TabsUIProps) => { const tabsRef = useRef({}) const tabsElement = useRef(null) const [ai_switch, setAI_switch] = useState(false) - const tabs = useRef(props.tabs) tabs.current = props.tabs // we do this to pass the tabs list to the onReady callbacks @@ -77,6 +76,16 @@ export const TabsUI = (props: TabsUIProps) => { } }, [tabsState.selectedIndex]) + const getAI = async() => { + try { + return await props.plugin.call('settings', 'getCopilotSetting') + } catch (e){ + return false + } + } + + getAI().then(value => setAI_switch(value)).catch(error => console.log(error)) + const getFileDecorationClasses = (tab: any) => { const fileDecoration = tabsState.fileDecorations.find((fileDecoration: fileDecoration) => { if (`${fileDecoration.workspace.name}/${fileDecoration.path}` === tab.name) return true