local-tool/: visionA-local desktop app
- M1: Wails shell + Go server + Next.js UI + Mock mode (macOS dmg ready)
- M2: i18n (zh-TW/en) + Settings 4-tab refactor
- M3: Embedded Python 3.12 runtime (python-build-standalone) + KneronPLUS wheels
- M4: Windows Inno Setup script (build on Windows runner)
- M5: Linux AppImage script + udev rule (build on Linux runner)
- M6: ffmpeg (GPL, pending legal review) + yt-dlp bundled
- Lifecycle: watchServer health check, fatal native dialog,
Wails IPC raise endpoint, stale process cleanup
.autoflow/: full PRD / Design Spec / Architecture / Testing docs
(4 rounds tri-party discussion + cross review)
.github/workflows/: macOS / Windows / Linux build CI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
package config
|
||
|
||
import (
|
||
"flag"
|
||
"fmt"
|
||
)
|
||
|
||
// PythonMode 表示 Python runtime 選擇策略。
|
||
// M1 階段只保留欄位與 CLI flag,實際切換邏輯由後續 milestone 實作。
|
||
type PythonMode string
|
||
|
||
const (
|
||
PythonModeAuto PythonMode = "auto"
|
||
PythonModeBundled PythonMode = "bundled"
|
||
PythonModeSystem PythonMode = "system"
|
||
)
|
||
|
||
type Config struct {
|
||
Port int
|
||
Host string
|
||
MockMode bool
|
||
MockCamera bool
|
||
MockDeviceCount int
|
||
LogLevel string
|
||
DevMode bool
|
||
DataDir string
|
||
ModelDir string
|
||
PythonMode PythonMode
|
||
PythonBin string // Python 可執行檔路徑(由 Wails 殼層傳入)
|
||
}
|
||
|
||
func Load() *Config {
|
||
cfg := &Config{}
|
||
var pythonMode string
|
||
|
||
flag.IntVar(&cfg.Port, "port", 3721, "Server port")
|
||
// 強制 localhost-only:即使使用者傳入其他 host,Load() 結束前會覆寫回 127.0.0.1
|
||
flag.StringVar(&cfg.Host, "host", "127.0.0.1", "Server host (forced to 127.0.0.1 for local-only use)")
|
||
flag.BoolVar(&cfg.MockMode, "mock", false, "Enable mock device driver")
|
||
flag.BoolVar(&cfg.MockCamera, "mock-camera", false, "Enable mock camera")
|
||
flag.IntVar(&cfg.MockDeviceCount, "mock-devices", 1, "Number of mock devices")
|
||
flag.StringVar(&cfg.LogLevel, "log-level", "info", "Log level (debug/info/warn/error)")
|
||
flag.BoolVar(&cfg.DevMode, "dev", false, "Dev mode: disable embedded static file serving")
|
||
flag.StringVar(&cfg.DataDir, "data-dir", "", "Override data directory (default: <binary>/data)")
|
||
flag.StringVar(&cfg.ModelDir, "model-dir", "", "Override custom model directory (default: <data-dir>/custom-models)")
|
||
flag.StringVar(&pythonMode, "python-mode", "auto", "Python runtime strategy: auto|bundled|system (placeholder for M1)")
|
||
flag.StringVar(&cfg.PythonBin, "python", "", "Path to python executable (optional; provided by Wails shell)")
|
||
flag.Parse()
|
||
|
||
// 強制 localhost-only
|
||
cfg.Host = "127.0.0.1"
|
||
|
||
switch PythonMode(pythonMode) {
|
||
case PythonModeAuto, PythonModeBundled, PythonModeSystem:
|
||
cfg.PythonMode = PythonMode(pythonMode)
|
||
default:
|
||
cfg.PythonMode = PythonModeAuto
|
||
}
|
||
|
||
return cfg
|
||
}
|
||
|
||
func (c *Config) Addr() string {
|
||
return fmt.Sprintf("%s:%d", c.Host, c.Port)
|
||
}
|