From 8a800a4bee530284b43ebce188159003dd22c652 Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Mon, 30 Jun 2025 01:49:06 +0200 Subject: [PATCH] Replace MaskEditor menu option with custom handler Removes the default 'Open in MaskEditor' option from the menu and adds a new custom option with improved error handling and logging. This ensures the MaskEditor is opened through a controlled callback, providing better user feedback in case of errors. --- js/CanvasView.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/js/CanvasView.js b/js/CanvasView.js index 6ae6909..beaac6f 100644 --- a/js/CanvasView.js +++ b/js/CanvasView.js @@ -1237,7 +1237,33 @@ app.registerExtension({ originalGetExtraMenuOptions?.apply(this, arguments); const self = this; + + // Usuń standardową opcję "Open in MaskEditor" jeśli istnieje + const maskEditorIndex = options.findIndex(option => + option && option.content === "Open in MaskEditor" + ); + if (maskEditorIndex !== -1) { + options.splice(maskEditorIndex, 1); + } + const newOptions = [ + { + content: "Open in MaskEditor", + callback: async () => { + try { + log.info("Opening LayerForge canvas in MaskEditor"); + if (self.canvasWidget && self.canvasWidget.startMaskEditor) { + await self.canvasWidget.startMaskEditor(); + } else { + log.error("Canvas widget not available"); + alert("Canvas not ready. Please try again."); + } + } catch (e) { + log.error("Error opening MaskEditor:", e); + alert(`Failed to open MaskEditor: ${e.message}`); + } + }, + }, { content: "Open Image", callback: async () => {