diff --git a/penpot-plugin/src/TaskHandler.ts b/penpot-plugin/src/TaskHandler.ts index 950c19c..b09a6c0 100644 --- a/penpot-plugin/src/TaskHandler.ts +++ b/penpot-plugin/src/TaskHandler.ts @@ -73,5 +73,5 @@ export abstract class TaskHandler { * * @param task - The task to be handled */ - abstract handle(task: Task): void; + abstract handle(task: Task): Promise; } diff --git a/penpot-plugin/src/plugin.ts b/penpot-plugin/src/plugin.ts index 3fd0ca2..086f6f4 100644 --- a/penpot-plugin/src/plugin.ts +++ b/penpot-plugin/src/plugin.ts @@ -28,7 +28,9 @@ penpot.ui.onMessage((message // New request-based message handling if (typeof message === "object" && message.task && message.id) { - handlePluginTaskRequest(message); + handlePluginTaskRequest(message).catch((error) => { + console.error("Error in handlePluginTaskRequest:", error); + }); } }); @@ -37,7 +39,7 @@ penpot.ui.onMessage((message * * @param request - The task request containing ID, task type and parameters */ -function handlePluginTaskRequest(request: { id: string; task: string; params: any }): void { +async function handlePluginTaskRequest(request: { id: string; task: string; params: any }): Promise { console.log("Executing plugin task:", request.task, request.params); const task = new Task(request.id, request.task, request.params); @@ -48,7 +50,7 @@ function handlePluginTaskRequest(request: { id: string; task: string; params: an try { // Cast the params to the expected type and handle the task console.log("Processing task with handler:", handler); - handler.handle(task); + await handler.handle(task); // check whether a response was sent and send a generic success if not if (!task.isResponseSent) { diff --git a/penpot-plugin/src/task-handlers/ExecuteCodeTaskHandler.ts b/penpot-plugin/src/task-handlers/ExecuteCodeTaskHandler.ts index f7c9eeb..543d203 100644 --- a/penpot-plugin/src/task-handlers/ExecuteCodeTaskHandler.ts +++ b/penpot-plugin/src/task-handlers/ExecuteCodeTaskHandler.ts @@ -182,7 +182,7 @@ export class ExecuteCodeTaskHandler extends TaskHandler { }; } - handle(task: Task): void { + async handle(task: Task): Promise { if (!task.params.code) { task.sendError("executeCode task requires 'code' parameter"); return; diff --git a/penpot-plugin/src/task-handlers/PrintTextTaskHandler.ts b/penpot-plugin/src/task-handlers/PrintTextTaskHandler.ts index b6d32d5..3db37e2 100644 --- a/penpot-plugin/src/task-handlers/PrintTextTaskHandler.ts +++ b/penpot-plugin/src/task-handlers/PrintTextTaskHandler.ts @@ -7,7 +7,7 @@ import { PrintTextTaskParams } from "../../../common/src"; export class PrintTextTaskHandler extends TaskHandler { readonly taskType = "printText"; - handle(task: Task): void { + async handle(task: Task): Promise { if (!task.params.text) { throw new Error("printText task requires 'text' parameter"); }