fix: Handle UTF-8 BOM in config loading and build script

- main.js: Strip UTF-8 BOM when reading config.json
- build-client.bat: Write config.json without BOM using
  [System.Text.UTF8Encoding]::new($false)

PowerShell's -Encoding UTF8 writes BOM by default, which can
cause JSON parsing issues in Node.js.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-17 12:30:04 +08:00
parent ac2d9a0240
commit 34947f6262
2 changed files with 8 additions and 3 deletions

View File

@@ -43,7 +43,12 @@ function loadConfig() {
console.log(`Checking: ${configPath} - exists: ${exists}`);
try {
if (exists) {
const configData = fs.readFileSync(configPath, "utf-8");
// Use utf-8 and strip BOM if present (Windows Notepad adds BOM)
let configData = fs.readFileSync(configPath, "utf-8");
// Remove UTF-8 BOM if present
if (configData.charCodeAt(0) === 0xFEFF) {
configData = configData.slice(1);
}
appConfig = JSON.parse(configData);
console.log("Config loaded from:", configPath);
console.log("Config content:", JSON.stringify(appConfig, null, 2));