From ed3b9e283203955457ab6aa2fed468ac65a5cd75 Mon Sep 17 00:00:00 2001 From: rambros Date: Mon, 23 Mar 2026 02:05:55 +0530 Subject: [PATCH] add self contained mode --- src/core/configuration.py | 14 +++++++++----- src/ui/main_app.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/core/configuration.py b/src/core/configuration.py index db52fd5..078a376 100644 --- a/src/core/configuration.py +++ b/src/core/configuration.py @@ -17,7 +17,7 @@ class AppConfig(BaseModel): anonymize_users: bool = Field(default=False) log_level: str = Field(default="INFO") -def load_config(config_path: Union[str, Path] = "config.yaml", create_if_missing: bool = True) -> AppConfig: +def load_config(config_path: Union[str, Path] = "reaper_config.yaml", create_if_missing: bool = True) -> AppConfig: path = Path(config_path) if not path.exists(): if not create_if_missing: @@ -36,19 +36,23 @@ def load_config(config_path: Union[str, Path] = "config.yaml", create_if_missing return AppConfig(**data) -def save_config(config: AppConfig, config_path: Union[str, Path] = "config.yaml"): +def save_config(config: AppConfig, config_path: Union[str, Path] = "reaper_config.yaml"): path = Path(config_path) data = config.model_dump(exclude_none=True) with open(path, "w", encoding="utf-8") as f: yaml.safe_dump(data, f, default_flow_style=False, sort_keys=False) def get_available_configs() -> list[str]: - """Returns a list of available configuration names from `ReaperFiles-*` folders.""" + """Returns a list of available configuration names. + If reaper_config.yaml exists in CWD, returns ['.'] to signify standalone mode.""" + if Path("reaper_config.yaml").exists(): + return ["."] + configs = [] for item in Path(".").iterdir(): if item.is_dir() and item.name.startswith("ReaperFiles-"): config_name = item.name[len("ReaperFiles-"):] - if (item / "config.yaml").exists(): + if (item / "reaper_config.yaml").exists(): configs.append(config_name) return sorted(configs) @@ -56,6 +60,6 @@ def create_new_config(name: str) -> Path: """Creates a new configuration folder and default config file.""" folder_path = Path(f"ReaperFiles-{name}") folder_path.mkdir(exist_ok=True) - config_path = folder_path / "config.yaml" + config_path = folder_path / "reaper_config.yaml" load_config(config_path) # creates default return folder_path diff --git a/src/ui/main_app.py b/src/ui/main_app.py index 8e05059..e445313 100644 --- a/src/ui/main_app.py +++ b/src/ui/main_app.py @@ -183,15 +183,38 @@ class ConfigSelectionScreen(Screen): configs = get_available_configs() lv = self.query_one("#config_list", ListView) lv.clear() + + is_standalone = ("." in configs) + try: + self.query_one("#btn_new_config", Button).display = not is_standalone + except Exception: pass + for c in configs: - lv.append(ListItem(Label(c), name=c)) + label = c + if c == ".": + dir_name = Path(".").resolve().name + if dir_name.startswith("ReaperFiles-"): + label = dir_name[len("ReaperFiles-"):] + else: + label = dir_name + lv.append(ListItem(Label(label), name=c)) return configs def on_list_view_selected(self, event: ListView.Selected) -> None: cfg_name = event.item.name - cfg_path = Path(f"ReaperFiles-{cfg_name}") / "config.yaml" + if cfg_name == ".": + cfg_path = Path("reaper_config.yaml") + dir_name = Path(".").resolve().name + if dir_name.startswith("ReaperFiles-"): + display_name = dir_name[len("ReaperFiles-"):] + else: + display_name = dir_name + else: + cfg_path = Path(f"ReaperFiles-{cfg_name}") / "reaper_config.yaml" + display_name = cfg_name + from src.ui.mode_screen import ModeScreen - self.app.push_screen(ModeScreen(cfg_name, cfg_path)) + self.app.push_screen(ModeScreen(display_name, cfg_path)) def action_new_config(self) -> None: def cb(name: str | None): @@ -199,7 +222,7 @@ class ConfigSelectionScreen(Screen): create_new_config(name) self.refresh_configs() # Immediately open the ConfigScreen for the new config - cfg_path = Path(f"ReaperFiles-{name}") / "config.yaml" + cfg_path = Path(f"ReaperFiles-{name}") / "reaper_config.yaml" def on_config_saved(saved: bool = False): if saved: self.refresh_configs() @@ -399,7 +422,7 @@ class ConfigScreen(Screen): yield Rule(id="footer_rule") with Horizontal(id="cfg_actions"): - yield Button("Save Configuration", variant="success", id="btn_save", tooltip="Save all changes to config.yaml") + yield Button("Save Configuration", variant="success", id="btn_save", tooltip="Save all changes to reaper_config.yaml") yield Button("Back", id="btn_back") yield Footer() yield RamDisplay()