diff --git a/install.py b/install.py index c13c92b..c7d1578 100644 --- a/install.py +++ b/install.py @@ -50,7 +50,7 @@ def run_plugin_patch(plugin_dir: str) -> bool: return False -def apply_plugins(): +def apply_plugins(yes_all: bool = False): print("[2/3] Applying plugins...") if not os.path.exists(PLUGINS_DIR): @@ -70,7 +70,11 @@ def apply_plugins(): plugin_path = os.path.join(PLUGINS_DIR, plugin_name) print(f"\n Plugin: {plugin_name}") - answer = input(f" Install '{plugin_name}'? [Y/n]: ").strip().lower() + if yes_all: + answer = "y" + print(f" Install '{plugin_name}'? [Y/n]: Y (--yes)") + else: + answer = input(f" Install '{plugin_name}'? [Y/n]: ").strip().lower() if answer in ("", "y", "yes"): print(f" Installing {plugin_name}...") @@ -209,6 +213,11 @@ def parse_args(): metavar="ENV", help=f"PlatformIO build environment (default: default)\n{env_help}", ) + parser.add_argument( + "-y", "--yes", + action="store_true", + help="Auto-answer Y to all plugin install prompts", + ) return parser.parse_args() @@ -227,13 +236,13 @@ def main(): print(f" Environment : {args.environment}") print(f" {ENVIRONMENTS[args.environment]}") print() - answer = input(" Do you wish to proceed? [Y/n]: ").strip().lower() + answer = input(" Do you wish to proceed? [Y/n]: ").strip().lower() if not args.yes else "y" if answer not in ("", "y", "yes"): print(" Aborted.") sys.exit(0) print() clone_repo() - apply_plugins() + apply_plugins(yes_all=args.yes) build_and_flash(args.environment) print("\nDone.") diff --git a/plugins/darkmode/patch.py b/plugins/darkmode/patch.py index 6536245..ab475cd 100644 --- a/plugins/darkmode/patch.py +++ b/plugins/darkmode/patch.py @@ -421,6 +421,68 @@ def patch_xtc_reader(repo_dir): print(" XtcReaderActivity.cpp patched.") +def patch_web_server(repo_dir): + path = find_first("CrossPointWebServer.cpp", repo_dir) + content = read_file(path) + + if '"Dark Mode"' in content or '"Smaller Fonts"' in content: + print(" CrossPointWebServer.cpp already patched, skipping.") + return + + name_overrides = ( + '\n' + ' if (s.key) {\n' + ' if (strcmp(s.key, "darkModeState") == 0) {\n' + ' doc["name"] = "Dark Mode";\n' + ' doc["category"] = "Plugins";\n' + ' } else if (strcmp(s.key, "smallerFontsMode") == 0) {\n' + ' doc["name"] = "Smaller Fonts";\n' + ' doc["category"] = "Plugins";\n' + ' }\n' + ' }\n' + ) + + content = content.replace( + ' doc["category"] = I18N.get(s.category);\n' + '\n' + ' switch (s.type) {', + ' doc["category"] = I18N.get(s.category);\n' + + name_overrides + + '\n' + ' switch (s.type) {' + ) + + enum_overrides = ( + ' if (s.key) {\n' + ' if (strcmp(s.key, "darkModeState") == 0) {\n' + ' JsonArray opts = doc["options"].to();\n' + ' opts.add("Disabled");\n' + ' opts.add("Enabled");\n' + ' } else if (strcmp(s.key, "smallerFontsMode") == 0) {\n' + ' JsonArray opts = doc["options"].to();\n' + ' opts.add("Disabled");\n' + ' opts.add("Smaller");\n' + ' opts.add("Smallest");\n' + ' }\n' + ' }\n' + ) + + content = content.replace( + ' for (const auto& opt : s.enumValues) {\n' + ' options.add(I18N.get(opt));\n' + ' }\n' + ' break;\n', + ' for (const auto& opt : s.enumValues) {\n' + ' options.add(I18N.get(opt));\n' + ' }\n' + + enum_overrides + + ' break;\n' + ) + + write_file(path, content) + print(" CrossPointWebServer.cpp patched.") + + def patch(repo_dir: str): plugin_dir = os.path.dirname(os.path.abspath(__file__)) @@ -448,6 +510,9 @@ def patch(repo_dir: str): print(" Patching XtcReaderActivity.cpp...") patch_xtc_reader(repo_dir) + print(" Patching CrossPointWebServer.cpp (web UI)...") + patch_web_server(repo_dir) + if __name__ == "__main__": if len(sys.argv) < 2: diff --git a/plugins/smallerfonts/patch.py b/plugins/smallerfonts/patch.py index d25da01..b021c4c 100644 --- a/plugins/smallerfonts/patch.py +++ b/plugins/smallerfonts/patch.py @@ -431,6 +431,68 @@ def patch_settings_cpp(repo_dir): print(" SettingsActivity.cpp patched.") +def patch_web_server(repo_dir): + path = find_first("CrossPointWebServer.cpp", repo_dir) + content = read_file(path) + + if '"Dark Mode"' in content or '"Smaller Fonts"' in content: + print(" CrossPointWebServer.cpp already patched, skipping.") + return + + name_overrides = ( + '\n' + ' if (s.key) {\n' + ' if (strcmp(s.key, "darkModeState") == 0) {\n' + ' doc["name"] = "Dark Mode";\n' + ' doc["category"] = "Plugins";\n' + ' } else if (strcmp(s.key, "smallerFontsMode") == 0) {\n' + ' doc["name"] = "Smaller Fonts";\n' + ' doc["category"] = "Plugins";\n' + ' }\n' + ' }\n' + ) + + content = content.replace( + ' doc["category"] = I18N.get(s.category);\n' + '\n' + ' switch (s.type) {', + ' doc["category"] = I18N.get(s.category);\n' + + name_overrides + + '\n' + ' switch (s.type) {' + ) + + enum_overrides = ( + ' if (s.key) {\n' + ' if (strcmp(s.key, "darkModeState") == 0) {\n' + ' JsonArray opts = doc["options"].to();\n' + ' opts.add("Disabled");\n' + ' opts.add("Enabled");\n' + ' } else if (strcmp(s.key, "smallerFontsMode") == 0) {\n' + ' JsonArray opts = doc["options"].to();\n' + ' opts.add("Disabled");\n' + ' opts.add("Smaller");\n' + ' opts.add("Smallest");\n' + ' }\n' + ' }\n' + ) + + content = content.replace( + ' for (const auto& opt : s.enumValues) {\n' + ' options.add(I18N.get(opt));\n' + ' }\n' + ' break;\n', + ' for (const auto& opt : s.enumValues) {\n' + ' options.add(I18N.get(opt));\n' + ' }\n' + + enum_overrides + + ' break;\n' + ) + + write_file(path, content) + print(" CrossPointWebServer.cpp patched.") + + def patch(repo_dir: str): plugin_dir = os.path.dirname(os.path.abspath(__file__)) @@ -469,6 +531,9 @@ def patch(repo_dir: str): print(" Patching SettingsActivity.cpp...") patch_settings_cpp(repo_dir) + print(" Patching CrossPointWebServer.cpp (web UI)...") + patch_web_server(repo_dir) + if __name__ == "__main__": if len(sys.argv) < 2: diff --git a/screenshot2.jpg b/screenshot2.jpg index 09ca0b4..407ed41 100644 Binary files a/screenshot2.jpg and b/screenshot2.jpg differ