diff --git a/Common/Colors.qml b/Common/Colors.qml index acc71373..a9a3e3c5 100644 --- a/Common/Colors.qml +++ b/Common/Colors.qml @@ -148,20 +148,29 @@ Singleton { onStreamFinished: { const out = matugenCollector.text - if (!out.length) { + const startIndex = out.indexOf('{') + const endIndex = out.lastIndexOf('}') + let jsonStringOnly = "" + if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) { + jsonStringOnly = out.substring(startIndex, endIndex + 1) + } + if (!jsonStringOnly.length) { ToastService.wallpaperErrorStatus = "error" - ToastService.showError("Wallpaper Processing Failed") + ToastService.showError("Wallpaper Processing Failed: Empty JSON extracted from matugen output.") return } try { - root.matugenJson = out - root.matugenColors = JSON.parse(out) + root.matugenJson = jsonStringOnly + root.matugenColors = JSON.parse(jsonStringOnly) root.colorsUpdated() generateAppConfigs() ToastService.clearWallpaperError() } catch (e) { ToastService.wallpaperErrorStatus = "error" - ToastService.showError("Wallpaper Processing Failed") + const stderr = matugenErr.text + const msg = "Wallpaper processing failed (JSON parse error after extraction)" + + (stderr ? `: ${stderr}` : ` with output: ${jsonStringOnly}`) + ToastService.showError(msg) } } } @@ -169,6 +178,16 @@ Singleton { stderr: StdioCollector { id: matugenErr } + + onExited: code => { + if (code !== 0) { + ToastService.wallpaperErrorStatus = "error" + const stderr = matugenErr.text + const msg = "Matugen command failed with exit code " + code + + (stderr ? `: ${stderr}` : ". No stderr output.") + ToastService.showError(msg) + } + } } function generateAppConfigs() {