|
12 | 12 | import requests |
13 | 13 | from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot |
14 | 14 |
|
| 15 | +from .config_manager import ConfigManager |
15 | 16 | from .constants import ( |
16 | 17 | MINECRAFT_DIR, |
17 | 18 | VERSIONS_CACHE_PATH, |
@@ -249,6 +250,57 @@ def set_progress(value: int, maximum: int = 100) -> None: |
249 | 250 | cleaned_options["gameDirectory"] = game_dir |
250 | 251 | print(f"Launching with game directory: {game_dir}") |
251 | 252 |
|
| 253 | + # --- Telemetry & Privacy Logic --- |
| 254 | + config_manager = ConfigManager() |
| 255 | + if config_manager.get("disable_telemetry", False): |
| 256 | + print("Disabling telemetry features...") |
| 257 | + |
| 258 | + # 1. Modify options.txt |
| 259 | + options_txt_path = os.path.join(game_dir, "options.txt") |
| 260 | + try: |
| 261 | + current_options = {} |
| 262 | + if os.path.exists(options_txt_path): |
| 263 | + with open(options_txt_path, "r") as f: |
| 264 | + for line in f: |
| 265 | + if ":" in line: |
| 266 | + key, val = line.strip().split(":", 1) |
| 267 | + current_options[key] = val |
| 268 | + |
| 269 | + # Force disable keys |
| 270 | + current_options["snooperEnabled"] = "false" |
| 271 | + current_options["telemetry"] = "false" |
| 272 | + current_options["onboardAccessibility"] = "false" # Often triggers data collection |
| 273 | + |
| 274 | + with open(options_txt_path, "w") as f: |
| 275 | + for key, val in current_options.items(): |
| 276 | + f.write(f"{key}:{val}\n") |
| 277 | + print(f"Updated options.txt at {options_txt_path}") |
| 278 | + except Exception as e: |
| 279 | + print(f"Failed to update options.txt: {e}") |
| 280 | + |
| 281 | + # 2. Add JVM Arguments |
| 282 | + if "jvmArguments" not in cleaned_options: |
| 283 | + cleaned_options["jvmArguments"] = [] |
| 284 | + |
| 285 | + # Ensure it's a list (minecraft-launcher-lib handles list or string, but we want list) |
| 286 | + if isinstance(cleaned_options["jvmArguments"], str): |
| 287 | + cleaned_options["jvmArguments"] = cleaned_options["jvmArguments"].split() |
| 288 | + |
| 289 | + telemetry_args = [ |
| 290 | + "-Dminecraft.api.env=custom", |
| 291 | + "-Dminecraft.telemetry.target=0.0.0.0", # Placeholder/Signal |
| 292 | + "-Dsnooper.enabled=false", |
| 293 | + "-Dlog4j2.formatMsgNoLookups=true", |
| 294 | + "-Duser.language=en", # Reduce fingerprinting |
| 295 | + "-Duser.country=US", |
| 296 | + ] |
| 297 | + |
| 298 | + # Note: We cannot easily map DNS to 0.0.0.0 via JVM args without an agent or hosts file. |
| 299 | + # These args are best-effort. |
| 300 | + |
| 301 | + cleaned_options["jvmArguments"].extend(telemetry_args) |
| 302 | + print("Added telemetry-disabling JVM arguments.") |
| 303 | + |
252 | 304 | command = minecraft_launcher_lib.command.get_minecraft_command( |
253 | 305 | version=self.version_to_launch, |
254 | 306 | minecraft_directory=MINECRAFT_DIR, |
|
0 commit comments