115115 "bcasl_enabled" : True ,
116116 "plugin_timeout" : 0.0 ,
117117 },
118+
119+ # Engines UI state (persisted widget states per engine)
120+ "engines" : {
121+ "pyinstaller" : {
122+ "ui" : {
123+ "widgets" : {}
124+ }
125+ },
126+ "nuitka" : {
127+ "ui" : {
128+ "widgets" : {}
129+ }
130+ }
131+ },
118132}
119133
120134
@@ -335,6 +349,15 @@ def create_default_ark_config(workspace_dir: str) -> bool:
335349 - "pip"
336350 auto_detect: true
337351 fallback_to_pip: true
352+
353+ # ENGINES (UI state persistence)
354+ engines:
355+ pyinstaller:
356+ ui:
357+ widgets: {}
358+ nuitka:
359+ ui:
360+ widgets: {}
338361"""
339362
340363 with open (config_file , 'w' , encoding = 'utf-8' ) as f :
@@ -345,3 +368,92 @@ def create_default_ark_config(workspace_dir: str) -> bool:
345368 except Exception as e :
346369 print (f"Warning: Failed to create ARK_Main_Config.yml: { e } " )
347370 return False
371+
372+
373+ # --- Simple Engine UI state helpers (for non-dev friendly persistence) ---
374+
375+ def _read_yaml (path : Path ) -> dict :
376+ try :
377+ if path .exists ():
378+ with open (path , 'r' , encoding = 'utf-8' ) as f :
379+ data = yaml .safe_load (f ) or {}
380+ return data if isinstance (data , dict ) else {}
381+ except Exception :
382+ pass
383+ return {}
384+
385+
386+ def _write_yaml_atomic (path : Path , data : dict ) -> bool :
387+ try :
388+ path .parent .mkdir (parents = True , exist_ok = True )
389+ tmp = path .with_suffix (path .suffix + ".tmp" )
390+ with open (tmp , 'w' , encoding = 'utf-8' ) as f :
391+ yaml .safe_dump (data , f , allow_unicode = True , sort_keys = False )
392+ os .replace (tmp , path )
393+ return True
394+ except Exception :
395+ return False
396+
397+
398+ essential_props = ("checked" , "text" , "enabled" , "visible" , "currentIndex" )
399+
400+
401+ def load_engine_ui_state (workspace_dir : str , engine_id : str ) -> dict :
402+ """Load saved UI state for an engine from ARK_Main_Config.yml.
403+ Returns a mapping {widgetName: {prop: value}} or {}.
404+ """
405+ try :
406+ cfg = _read_yaml (Path (workspace_dir ) / "ARK_Main_Config.yml" ) if workspace_dir else {}
407+ engines = cfg .get ("engines" , {}) if isinstance (cfg , dict ) else {}
408+ e = engines .get (str (engine_id ), {}) if isinstance (engines , dict ) else {}
409+ ui = e .get ("ui" , {}) if isinstance (e , dict ) else {}
410+ widgets = ui .get ("widgets" , {}) if isinstance (ui , dict ) else {}
411+ return widgets if isinstance (widgets , dict ) else {}
412+ except Exception :
413+ return {}
414+
415+
416+ def save_engine_ui_state (workspace_dir : str , engine_id : str , updates : dict ) -> bool :
417+ """Save UI state for an engine into ARK_Main_Config.yml.
418+ - workspace_dir: project workspace path
419+ - engine_id: id string (e.g. 'pyinstaller')
420+ - updates: {widgetName: {prop: value}}
421+ Returns True on success, False otherwise.
422+ """
423+ if not workspace_dir :
424+ return False
425+ try :
426+ cfg_path = Path (workspace_dir ) / "ARK_Main_Config.yml"
427+ cfg = _read_yaml (cfg_path )
428+ if not isinstance (cfg , dict ):
429+ cfg = {}
430+ engines = cfg .get ("engines" )
431+ if not isinstance (engines , dict ):
432+ engines = {}
433+ cfg ["engines" ] = engines
434+ e = engines .get (str (engine_id ))
435+ if not isinstance (e , dict ):
436+ e = {}
437+ engines [str (engine_id )] = e
438+ ui = e .get ("ui" )
439+ if not isinstance (ui , dict ):
440+ ui = {}
441+ e ["ui" ] = ui
442+ widgets = ui .get ("widgets" )
443+ if not isinstance (widgets , dict ):
444+ widgets = {}
445+ ui ["widgets" ] = widgets
446+ # Merge per widget
447+ for wname , props in (updates or {}).items ():
448+ if not isinstance (wname , str ) or not isinstance (props , dict ):
449+ continue
450+ cur = widgets .get (wname )
451+ if not isinstance (cur , dict ):
452+ cur = {}
453+ widgets [wname ] = cur
454+ for k , v in props .items ():
455+ if k in essential_props :
456+ cur [k ] = v
457+ return _write_yaml_atomic (cfg_path , cfg )
458+ except Exception :
459+ return False
0 commit comments