MCPcopy
hub / github.com/codeaashu/claude-code / checkAndInstall

Function checkAndInstall

src/commands/thinkback/thinkback.tsx:164–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

162 const [progressMessage, setProgressMessage] = useState('');
163 useEffect(() => {
164 async function checkAndInstall(): Promise<void> {
165 try {
166 // Check if marketplace is installed
167 const knownMarketplaces = await loadKnownMarketplacesConfig();
168 const marketplaceName = getMarketplaceName();
169 const marketplaceRepo = getMarketplaceRepo();
170 const pluginId = getPluginId();
171 const marketplaceInstalled = marketplaceName in knownMarketplaces;
172
173 // Check if plugin is already installed first
174 const pluginAlreadyInstalled = isPluginInstalled(pluginId);
175 if (!marketplaceInstalled) {
176 // Install the marketplace
177 setState({
178 phase: 'installing-marketplace'
179 });
180 logForDebugging(`Installing marketplace ${marketplaceRepo}`);
181 await addMarketplaceSource({
182 source: 'github',
183 repo: marketplaceRepo
184 }, message => {
185 setProgressMessage(message);
186 });
187 clearAllCaches();
188 logForDebugging(`Marketplace ${marketplaceName} installed`);
189 } else if (!pluginAlreadyInstalled) {
190 // Marketplace installed but plugin not installed - refresh to get latest plugins
191 // Only refresh when needed to avoid potentially destructive git operations
192 setState({
193 phase: 'installing-marketplace'
194 });
195 setProgressMessage('Updating marketplace…');
196 logForDebugging(`Refreshing marketplace ${marketplaceName}`);
197 await refreshMarketplace(marketplaceName, message_0 => {
198 setProgressMessage(message_0);
199 });
200 clearMarketplacesCache();
201 clearAllCaches();
202 logForDebugging(`Marketplace ${marketplaceName} refreshed`);
203 }
204 if (!pluginAlreadyInstalled) {
205 // Install the plugin
206 setState({
207 phase: 'installing-plugin'
208 });
209 logForDebugging(`Installing plugin ${pluginId}`);
210 const result = await installSelectedPlugins([pluginId]);
211 if (result.failed.length > 0) {
212 const errorMsg = result.failed.map(f => `${f.name}: ${f.error}`).join(', ');
213 throw new Error(`Failed to install plugin: ${errorMsg}`);
214 }
215 clearAllCaches();
216 logForDebugging(`Plugin ${pluginId} installed`);
217 } else {
218 // Plugin is installed, check if it's enabled
219 const {
220 disabled
221 } = await loadAllPlugins();

Callers 1

ThinkbackInstallerFunction · 0.85

Calls 15

getMarketplaceNameFunction · 0.85
getMarketplaceRepoFunction · 0.85
isPluginInstalledFunction · 0.85
logForDebuggingFunction · 0.85
addMarketplaceSourceFunction · 0.85
clearAllCachesFunction · 0.85
refreshMarketplaceFunction · 0.85
clearMarketplacesCacheFunction · 0.85
loadAllPluginsFunction · 0.85
enablePluginOpFunction · 0.85
toErrorFunction · 0.85

Tested by

no test coverage detected