From 0532fafe9f0e8d5b82381d55d91395bb26b54c3e Mon Sep 17 00:00:00 2001 From: xuwenwei Date: Mon, 8 Jun 2026 23:36:50 +0800 Subject: [PATCH] BUILD.md: document the Rust source edit (custom.txt path is broken for unsigned forks) --- BUILD.md | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/BUILD.md b/BUILD.md index 4c93f87..dc321c7 100644 --- a/BUILD.md +++ b/BUILD.md @@ -114,34 +114,44 @@ Dart 3.12 rejects `const Map{...}`. Change `const` to `final be wiped by `flutter pub cache clean`.** To make it permanent, copy the patched file into `./local_google_fonts/` and use `dependency_overrides: google_fonts: { path: ... }`. -### 2.6. `flutter/macos/Runner/custom.txt` (default settings via Rust's `load_custom_client`) +### 2.6. `src/common.rs` — hardcode `enable-audio` default to off (NOT via custom.txt) -RustDesk's Rust core reads `Contents/Resources/custom.txt` on startup -(see `src/common.rs::load_custom_client` + `read_custom_client`). It accepts two -keys: `default-settings` (fills `DEFAULT_SETTINGS`; user config still wins) and -`override-settings` (fills `OVERWRITE_SETTINGS`; user can't override). +**The naive approach (custom.txt) is broken for unsigned forks.** `load_custom_client` +reads `Contents/Resources/custom.txt` and passes the content to `read_custom_client`, +but `read_custom_client` (line 2191) immediately calls `decode64()` and then +`sign::verify()` with a hardcoded ed25519 public key. Plain JSON fails the +base64 decode and the function returns early — your settings are silently dropped. +Only **official signed** custom-client builds can use the `custom.txt` path. -**Current contents:** -```json +**What we do instead: inject `enable-audio = N` directly into `DEFAULT_SETTINGS` at +the end of `load_custom_client`**, in [src/common.rs:2104-2114](src/common.rs#L2104): + +```rust +// Custom fork: hardcode enable-audio = N as the default. User can still flip it on in Settings. +// Reason: RustDesk's official custom.txt path requires ed25519-signed base64 (see +// read_custom_client at line 2191 — decode64 + sign::verify with key +// "5Qbwsde3unUcJBtrx9ZkvUmwFNoExHzpryHuPUdqlWM="), which we can't produce without the +// official signing key. So we bypass custom.txt and inject directly into DEFAULT_SETTINGS. +// entry().or_insert() preserves the priority chain: OVERWRITE_SETTINGS → CONFIG2 → DEFAULT_SETTINGS. { - "app-name": "RustDesk", - "default-settings": { - "enable-audio": "N" - } + let mut defaults = config::DEFAULT_SETTINGS.write().unwrap(); + defaults.entry("enable-audio".to_string()).or_insert("N".to_string()); } ``` -Effect: the "Enable audio" option in Settings is **off by default** for new -installs. Users can still flip it on. To add more defaults, follow the -`KEYS_SETTINGS` whitelist in `libs/hbb_common/src/config.rs:3130`. +`entry().or_insert()` (not `insert()`) is intentional — it lets users override +`enable-audio` by writing to their own `RustDesk2.toml`'s `[options]` table +(CONFIG2 wins in the priority chain). -**Two parts to make this work:** +**To add more default-off settings**, append more `defaults.entry(...).or_insert(...)` +lines. Any key from the `KEYS_SETTINGS` whitelist at +[libs/hbb_common/src/config.rs:3130](libs/hbb_common/src/config.rs#L3130) works. +Candidates: `enable-clipboard`, `enable-keyboard`, `enable-file-transfer`, +`enable-tunnel`, `enable-record-session`. -1. The file `flutter/macos/Runner/custom.txt` must exist (it does in git). -2. `flutter/macos/Runner.xcodeproj/project.pbxproj` must list `custom.txt` in - the `PBXResourcesBuildPhase`'s `files` list. We added it under UUIDs - `AABBCC000100000000000001` (BuildFile) and `AABBCC000200000000000002` - (FileReference). If you regenerate the Xcode project, re-add it. +**Verified end-to-end:** debug eprintln confirmed `DEFAULT_SETTINGS.get("enable-audio") == Some("N")` +at startup. UI's "Settings → Permissions" page now shows the audio checkbox unchecked. +User can still flip it on in Settings. ---