Skip to content

fix(#75): clarify port-open error popup and correct config paths#77

Merged
mixc6763-prog merged 3 commits into
mainfrom
fix/diagnostic-paths-and-port-error-ux
May 15, 2026
Merged

fix(#75): clarify port-open error popup and correct config paths#77
mixc6763-prog merged 3 commits into
mainfrom
fix/diagnostic-paths-and-port-error-ux

Conversation

@mixc6763-prog
Copy link
Copy Markdown
Contributor

@mixc6763-prog mixc6763-prog commented May 15, 2026

Summary

Three related fixes triggered by user reports on #75 — the "端口打开失败 / Ports Open Fail" popup is misleading users (and us) into chasing port-occupation problems, the diagnostic paths we ask reporters to inspect are out of date, and the generator path that produces .enhanced_config.yaml could silently emit a config without a usable HTTP-style port.

Commit 1 — docs(#75): use .config/clashfx for config and core log paths

The app moved from ~/.config/clash to ~/.config/clashfx long ago (see Paths.swift), but the READMEs and issue template still pointed users to the legacy directory. Reporters tail an empty file and we lose a debugging round-trip.

  • 5 READMEs (en, zh-CN, zh-TW, ja, ru): correct $HOME/.config/clash$HOME/.config/clashfx
  • bug_report.md: add two diagnostic fields used during issue triage —
    • ~/.config/clashfx/.mihomo_core.log (only requested when Enhanced Mode is on)
    • grep of mixed-port / port / socks-port / external-controller from .enhanced_config.yaml (only requested when the user hits "Ports Open Fail")
  • Drive-by: rename remaining ClashX template labels to ClashFX

Commit 2 — fix(#75): clarify port-open error popup with core log tail

ClashStatusTool.checkPortConfig shows the alert when mihomo_core's /configs API returns mixed-port = port = 0. That state is not a port-binding conflict — it usually means the generated .enhanced_config.yaml is missing port fields. The previous copy ("Ports Open Fail, Please try to restart ClashFX") sent users (and the issue #75 reporter) hunting for lsof collisions that don't exist.

Changes to ClashStatusTool.swift:

  • Rewritten alert body describes the actual state (mixed-port = port = 0 / missing port fields) instead of implying a port conflict
  • Appends the last 12 lines of ~/.config/clashfx/.mihomo_core.log to the alert when readable, so the real cause (TUN setup error, config parse error, etc.) is visible without digging through docs
  • "Edit Config" now opens .enhanced_config.yaml when it exists, so the zero ports are visible directly; falls back to the original config.yaml when Enhanced Mode is off
  • Two small private helpers (activeConfigPath, tailOfMihomoLog) keep the read-side concerns out of the alert flow

5 Localizable.strings updated (en/zh-Hans/zh-Hant/ja/ru): drop the misleading "Ports Open Fail, Please try to restart ClashFX" key, add the two new strings.

Commit 3 — fix(#75): always promote a usable mixed-port in Enhanced Mode config

The root cause of the popup itself. The previous fallback in clashWriteEnhancedConfig only injected mixed-port=7890 when all three of mixed-port, port, socks-port were zero. A source config with only socks-port (or only port in some edge cases) was passed through with mixed-port=0, and mihomo cannot synthesise a mixed-port default itself (RawConfig.MixedPort has no default tag). Result: .enhanced_config.yaml lacks a mixed-port, the GUI's usedHttpPort check returns 0, and the misleading alert fires.

Strategy mirrors ClashX.Meta's parseDefaultConfigThenStart (see main.go parseDefaultConfigThenStart):

  1. Keep existing mixed-port if > 0
  2. Otherwise promote the configured port or socks-port into mixed-port and drop the source field so mihomo doesn't try to bind the same number twice
  3. Fall back to mixed-port=7890 only when nothing is configured

Type-assertion coercion is also hardened against int64 / uint64 / float64 / string scalars that subscription providers occasionally emit in place of bare ints.

  • port_fallback.go: pure-Go helpers, no CGO so tests run on plain go test
  • port_fallback_test.go: 23 cases covering coercion (incl. string, int64, uint64) and every promotion / fallback / conflict-cleanup branch

Verification

  • xcodebuild -workspace ClashFX.xcworkspace -scheme ClashFX -configuration Debug (commit 1+2) → BUILD SUCCEEDED on clean derived data
  • swiftc -parse on ClashStatusTool.swift → ok
  • go test ./ in ClashFX/goClash/PASS (23/23)
  • Cross-arch sanity (commit 3): GOOS=darwin GOARCH=arm64 and GOOS=darwin GOARCH=amd64 go build -buildmode=c-archive both succeeded
  • Old key "Ports Open Fail..." no longer present in any Localizable.strings (grep confirmed)
  • New key pair present in all 5 locale files

Note: goClash.a / mihomo_core binaries are in .gitignore and will be rebuilt by the release pipeline; nothing in this PR carries a checked-in binary diff.

Closes #75.

ClashFX Team added 3 commits May 15, 2026 13:04
- READMEs (en/zh-CN/zh-TW/ja/ru): correct the default config
  directory from $HOME/.config/clash to $HOME/.config/clashfx
- bug_report.md: add fields for ~/.config/clashfx/.mihomo_core.log
  (Enhanced Mode) and enhanced config port settings used when
  diagnosing the "Ports Open Fail" popup; rename "ClashX" to
  "ClashFX" in template labels
checkPortConfig surfaces an alert when mihomo_core returns a config
with mixed-port = port = 0. The previous message ("Ports Open Fail,
Please try to restart ClashFX") implied a port-occupation problem,
but the real cause is usually a generated .enhanced_config.yaml
missing port fields, not an external port conflict.

- Rewrite the alert body to describe the actual state and append
  the last 12 lines of ~/.config/clashfx/.mihomo_core.log when
  the file is readable, so the user can see the real cause without
  hunting through documentation
- "Edit Config" now opens .enhanced_config.yaml when present so
  the zero ports are visible directly, with fallback to the
  original config.yaml when Enhanced Mode is off
- Update 5 Localizable.strings (en/zh-Hans/zh-Hant/ja/ru): drop
  the misleading "Ports Open Fail" key and add the two new keys
The previous fallback in clashWriteEnhancedConfig only injected
mixed-port=7890 when all of mixed-port/port/socks-port were zero.
A source config with only socks-port (or only port) ended up with
mixed-port=0 in .enhanced_config.yaml, triggering the misleading
"Ports Open Fail" popup at startup.

Behaviour now mirrors ClashX.Meta's parseDefaultConfigThenStart:
1. Keep existing mixed-port if > 0
2. Otherwise promote port or socks-port into mixed-port and drop
   the source field so mihomo doesn't bind the same number twice
3. Fall back to mixed-port=7890 only when nothing is configured

Type-assertion is also hardened against int64/uint64/float64/string
scalars that subscription providers occasionally produce in place
of bare ints.

- port_fallback.go: pure-Go helpers, testable without CGO
- port_fallback_test.go: 23 cases (coercion + all branches)

Verified: go test PASS (23/23); cross-arch c-archive builds
(arm64 + amd64) succeeded.

Ref: MetaCubeX/ClashX.Meta/ClashX/goClash/main.go
@mixc6763-prog mixc6763-prog merged commit 68c72ad into main May 15, 2026
1 check passed
@mixc6763-prog mixc6763-prog deleted the fix/diagnostic-paths-and-port-error-ux branch May 15, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

增强模式还是本身bug?

1 participant