Files
lmvpn_client/internal/paths/paths.go
T
kevin b0aa386ee2 修复 daemon 启动问题,分离 GUI 和 daemon 二进制
- 分离二进制: cmd/lmvpn (GUI+Fyne) 和 cmd/lmvpnd (daemon, 无 Fyne)
  消除 daemon 启动时的 Fyne locale 初始化错误
- 新增 daemon-launch 子命令: 用 syscall.SysProcAttr{Setsid: true}
  替代 nohup, 解决 osascript 无 TTY 时的 'Inappropriate ioctl' 错误
- daemon 日志写到用户家目录: paths.SetUserHome() 覆盖 root 默认路径
- IPC socket chown 给用户: 解决 root:wheel 0660 导致 GUI 无法连接
- 修复 JWT→密码认证回退: 捕获 ServerError{auth_err} 而非仅 AuthError
- 修复 token URL 编码: 用 url.QueryEscape 替代裸拼接
- 日志去重: LMVPN_DAEMON=1 时 daemon 不再 stderr 镜像到文件
- Makefile 构建双二进制并打包到 .app bundle
2026-07-06 17:46:36 +08:00

63 lines
2.0 KiB
Go

// Package paths resolves platform-specific application directories.
//
// Layout follows each platform's conventions. On macOS:
//
// ~/Library/Application Support/com.lmvpn.client/ user data, db, config
// ~/Library/Caches/com.lmvpn.client/ caches
// ~/Library/Logs/com.lmvpn.client/ logs
package paths
import "os"
// BundleID is the application bundle identifier used as the per-app
// subdirectory name under the platform library folders.
const BundleID = "com.lmvpn.client"
// AppName is the human-readable application name.
const AppName = "LMVPN"
// Dirs describes the resolved application directories.
type Dirs struct {
Data string // persistent user data (db, config)
Cache string // recreatable caches
Log string // log files
}
// Paths is the resolved directory set for the current platform.
var Paths Dirs
// SetUserHome overrides the home directory used to compute Paths.
// This is used by the daemon (which runs as root) to write logs and
// data to the invoking user's Library folders instead of /var/root.
func SetUserHome(home string) {
if home != "" {
recomputePaths(home)
}
}
// EnsureDirs creates the application directories if they do not exist.
func EnsureDirs() error {
for _, d := range []string{Paths.Data, Paths.Cache, Paths.Log} {
if err := os.MkdirAll(d, 0o755); err != nil {
return err
}
}
return nil
}
// DBPath returns the path to the SQLite database file.
func DBPath() string { return Paths.Data + "/lmvpn.db" }
// ConfigPath returns the path to the application config file.
func ConfigPath() string { return Paths.Data + "/config.yml" }
// LogFile returns the path to the GUI log file.
func LogFile() string { return Paths.Log + "/lmvpn.log" }
// DaemonLogFile returns the path to the daemon log file.
func DaemonLogFile() string { return Paths.Log + "/lmvpn-daemon.log" }
// IPCSocketPath returns the path to the unix domain socket used for
// GUI <-> daemon communication.
func IPCSocketPath() string { return "/tmp/lmvpn.sock" }