#!/usr/bin/env python3 import json with open('/home/mdares/.node-red/flows.json', 'r') as f: flows = json.load(f) # Handler code for resume-prompt mode resume_handler = ''' // ======================================================== // MODE: RESUME-PROMPT // ======================================================== if (mode === "resume-prompt") { // Forward the resume prompt to Home UI // Also set activeWorkOrder so Start button becomes enabled const order = msg.payload.order || null; if (order) { // Set activeWorkOrder in global so Start button is enabled global.set("activeWorkOrder", order); node.warn(`[RESUME-PROMPT] Set activeWorkOrder to ${order.id} - Start button should now be enabled`); } // Send prompt message to Home template const homeMsg = { topic: msg.topic || "resumePrompt", payload: msg.payload }; return [null, homeMsg, null, null]; } ''' # Find Back to UI node and add the handler for node in flows: if node.get('id') == 'f2bab26e27e2023d' and node.get('name') == 'Back to UI': func = node.get('func', '') # Find the best place to insert: before the DEFAULT section if '// DEFAULT' in func: # Insert before DEFAULT section default_idx = func.find('// ========================================================\n// DEFAULT') if default_idx != -1: func = func[:default_idx] + resume_handler + '\n' + func[default_idx:] node['func'] = func print("✓ Added resume-prompt handler to Back to UI function") else: print("✗ Could not find DEFAULT section") else: # Fallback: add before the final return statement final_return_idx = func.rfind('return [null, null, null, null];') if final_return_idx != -1: func = func[:final_return_idx] + resume_handler + '\n' + func[final_return_idx:] node['func'] = func print("✓ Added resume-prompt handler to Back to UI function (before final return)") break # Write back with open('/home/mdares/.node-red/flows.json', 'w') as f: json.dump(flows, f, indent=4) print("✓ flows.json updated successfully")