Files
Axel Meyer 7f17a40b7c
Some checks failed
Release / build (push) Failing after 21s
Rewrite in Go: static binaries, zero runtime dependencies
Replace Node.js + Python codebase with three Go binaries:
- claude-statusline: CLI status bar for Claude Code
- claude-fetcher: standalone cron job for API usage
- claude-widget: system tray icon (fyne-io/systray + fogleman/gg)

All CGO-free for trivial cross-compilation. Add nfpm .deb packaging
with autostart and cron. CI pipeline produces Linux + Windows binaries,
.deb, .tar.gz, and .zip release assets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 15:27:10 +00:00

94 lines
2.2 KiB
Go

package config
import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"strings"
)
// WidgetConfig holds the widget configuration.
type WidgetConfig struct {
RefreshInterval int `json:"refresh_interval"`
OrgID string `json:"org_id"`
}
var defaults = WidgetConfig{
RefreshInterval: 300,
OrgID: "",
}
// ConfigDir returns the platform-specific config directory.
func ConfigDir() string {
if v := os.Getenv("CLAUDE_STATUSLINE_CONFIG"); v != "" {
return v
}
if runtime.GOOS == "windows" {
return filepath.Join(os.Getenv("LOCALAPPDATA"), "claude-statusline")
}
if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" {
return filepath.Join(xdg, "claude-statusline")
}
home, _ := os.UserHomeDir()
return filepath.Join(home, ".config", "claude-statusline")
}
// ConfigPath returns the path to widget-config.json.
func ConfigPath() string {
return filepath.Join(ConfigDir(), "widget-config.json")
}
// SessionKeyPath returns the path to the session-key file.
func SessionKeyPath() string {
return filepath.Join(ConfigDir(), "session-key")
}
// Load reads widget-config.json and merges with defaults.
func Load() WidgetConfig {
cfg := defaults
data, err := os.ReadFile(ConfigPath())
if err != nil {
return cfg
}
_ = json.Unmarshal(data, &cfg)
if cfg.RefreshInterval < 60 {
cfg.RefreshInterval = 60
}
return cfg
}
// Save writes widget-config.json.
func Save(cfg WidgetConfig) error {
dir := ConfigDir()
if err := os.MkdirAll(dir, 0o755); err != nil {
return err
}
data, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
return os.WriteFile(ConfigPath(), data, 0o644)
}
// GetSessionKey returns the session key from env or file.
func GetSessionKey() string {
if v := os.Getenv("CLAUDE_SESSION_KEY"); v != "" {
return strings.TrimSpace(v)
}
data, err := os.ReadFile(SessionKeyPath())
if err != nil {
return ""
}
return strings.TrimSpace(string(data))
}
// SetSessionKey writes the session key to file.
func SetSessionKey(key string) error {
dir := ConfigDir()
if err := os.MkdirAll(dir, 0o755); err != nil {
return err
}
return os.WriteFile(SessionKeyPath(), []byte(strings.TrimSpace(key)+"\n"), 0o600)
}