@@ -22,38 +22,39 @@ export const getpearAIExports = async () => {
2222
2323 return pearAiExtension . exports ;
2424}
25-
25+
2626// TODO: SHOULD HAVE TYPE SYNCED WITH THE PEARAI SUBMODULE!
2727type CreatorModeState = "OVERLAY_CLOSED" | "OVERLAY_OPEN" | "OVERLAY_CLOSED_CREATOR_ACTIVE"
2828
29- export const registerPearListener = async ( ) => {
29+ export const registerPearListener = async ( provider : ClineProvider ) => {
3030 // Getting the pear ai extension instance
3131 const exports = await getpearAIExports ( )
3232
3333 exports . pearAPI . creatorMode . onDidRequestExecutePlan ( async ( msg : any ) => {
3434 console . dir ( `onDidRequestNewTask triggered with: ${ JSON . stringify ( msg ) } ` )
35- // Get the sidebar provider
36- let sidebarProvider = ClineProvider . getVisibleInstance ( )
3735
38- // TODO: LOOK INTO THIS - THIS IS A JANKY FIX AND IT FEELS LIKE THIS IS TEMPERAMENTAL
39- while ( ! sidebarProvider ) {
40- await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
41- sidebarProvider = ClineProvider . getVisibleInstance ( )
36+ let canContinue = false ;
37+
38+ while ( ! canContinue ) {
39+ await new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ;
40+ canContinue = provider . viewLaunched && provider . isViewLaunched ;
4241 }
4342
43+
44+ // Get the sidebar provider
4445 // Focus the sidebar first
4546 await vscode . commands . executeCommand ( "pearai-roo-cline.SidebarProvider.focus" )
4647
4748 // Wait for the view to be ready using a helper function
48- await ensureViewIsReady ( sidebarProvider )
49+ await ensureViewIsReady ( provider )
4950 // Wait a brief moment for UI to update
50- await new Promise ( ( resolve ) => setTimeout ( resolve , 300 ) )
51+ await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) )
5152
5253 // * This does actually work but the UI update does not happen. This method calls this.postStateToWebview() so not sure what is going on - James
53- await sidebarProvider . handleModeSwitch ( "Creator" )
54+ await provider . handleModeSwitch ( "Creator" )
5455
5556 // Clicl the chat btn
56- await sidebarProvider . postMessageToWebview ( { type : "action" , action : "chatButtonClicked" } )
57+ await provider . postMessageToWebview ( { type : "action" , action : "chatButtonClicked" } )
5758
5859 const creatorModeConfig = {
5960 creatorMode : true ,
@@ -63,7 +64,7 @@ export const registerPearListener = async () => {
6364
6465
6566 // Initialize with task
66- await sidebarProvider . initClineWithTask ( msg . plan , undefined , undefined , undefined , creatorModeConfig ) ;
67+ await provider . initClineWithTask ( msg . plan , undefined , undefined , undefined , creatorModeConfig ) ;
6768 } ) ;
6869 // If there's a creator event in the cache after the extensions were refreshed, we need to get it!
6970 exports . pearAPI . creatorMode . triggerCachedCreatorEvent ( true ) ;
0 commit comments