Skip to content

Commit 0a72e5f

Browse files
committed
feat: added message emitter to handle creator mode updates
1 parent c0a67cc commit 0a72e5f

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/activate/registerPearListener.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const getPearaiExtension = async () => {
1414
return pearAiExtension
1515
}
1616

17+
// TODO: SHOULD HAVE TYPE SYNCED WITH THE PEARAI SUBMODULE!
18+
type CreatorModeState = "OVERLAY_CLOSED" | "OVERLAY_OPEN" | "OVERLAY_CLOSED_CREATOR_ACTIVE"
19+
1720
export const registerPearListener = async () => {
1821
// Getting the pear ai extension instance
1922
const pearAiExtension = await getPearaiExtension()
@@ -61,7 +64,20 @@ export const registerPearListener = async () => {
6164
});
6265
// If there's a creator event in the cache after the extensions were refreshed, we need to get it!
6366
pearAiExtension.exports.pearAPI.creatorMode.triggerCachedCreatorEvent(true);
64-
console.log("triggerCachedCreatorEvent CALLED!")
67+
68+
pearAiExtension.exports.pearAPI.creatorMode.onDidChangeCreatorModeState(async (state: CreatorModeState) => {
69+
// Get the sidebar provider
70+
const sidebarProvider = ClineProvider.getVisibleInstance();
71+
72+
if (sidebarProvider) {
73+
// Send a message to the webview that will trigger a window event
74+
sidebarProvider.postMessageToWebview({
75+
type: "creatorModeUpdate",
76+
text: state,
77+
});
78+
}
79+
});
80+
6581
} else {
6682
console.error("⚠️⚠️ PearAI API not available in exports ⚠️⚠️")
6783
}

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface ExtensionMessage {
6868
| "acceptInput"
6969
| "setHistoryPreviewCollapsed"
7070
| "commandExecutionStatus"
71+
| "creatorModeUpdate"
7172
text?: string
7273
action?:
7374
| "chatButtonClicked"

0 commit comments

Comments
 (0)