|
5 | 5 | "image" |
6 | 6 | "os" |
7 | 7 | "os/signal" |
| 8 | + "path/filepath" |
8 | 9 | "strings" |
9 | 10 | "syscall" |
10 | 11 | "time" |
@@ -35,7 +36,9 @@ const ( |
35 | 36 |
|
36 | 37 | // App represents the main application |
37 | 38 | type App struct { |
38 | | - config *config.Config |
| 39 | + config *config.Config |
| 40 | + // ConfigPath holds the path the daemon was started with (if any) |
| 41 | + ConfigPath string |
39 | 42 | logger *zap.Logger |
40 | 43 | hotkeyManager *hotkeys.Manager |
41 | 44 | hintGenerator *hints.Generator |
@@ -974,10 +977,27 @@ func (a *App) handleIPCCommand(cmd ipc.Command) ipc.Response { |
974 | 977 | return ipc.Response{Success: true, Message: "mode set to idle"} |
975 | 978 |
|
976 | 979 | case "status": |
977 | | - statusData := map[string]interface{}{ |
| 980 | + cfgPath := a.ConfigPath |
| 981 | + if cfgPath == "" { |
| 982 | + // Fallback to the standard config path if daemon wasn't started |
| 983 | + // with an explicit --config |
| 984 | + cfgPath = config.GetConfigPath() |
| 985 | + } |
| 986 | + |
| 987 | + // Expand ~ to home dir and resolve relative paths to absolute |
| 988 | + if strings.HasPrefix(cfgPath, "~") { |
| 989 | + if home, err := os.UserHomeDir(); err == nil { |
| 990 | + cfgPath = filepath.Join(home, cfgPath[1:]) |
| 991 | + } |
| 992 | + } |
| 993 | + if abs, err := filepath.Abs(cfgPath); err == nil { |
| 994 | + cfgPath = abs |
| 995 | + } |
| 996 | + |
| 997 | + statusData := map[string]any{ |
978 | 998 | "enabled": a.enabled, |
979 | 999 | "mode": a.getModeString(), |
980 | | - "config": config.GetConfigPath(), |
| 1000 | + "config": cfgPath, |
981 | 1001 | } |
982 | 1002 | return ipc.Response{Success: true, Data: statusData} |
983 | 1003 |
|
@@ -1051,6 +1071,9 @@ func LaunchDaemon(configPath string) { |
1051 | 1071 | fmt.Fprintf(os.Stderr, "Error creating app: %v\n", err) |
1052 | 1072 | os.Exit(1) |
1053 | 1073 | } |
| 1074 | + // Record the config path the daemon was started with so status can report |
| 1075 | + // the same path (if provided via --config) |
| 1076 | + app.ConfigPath = configPath |
1054 | 1077 | globalApp = app |
1055 | 1078 |
|
1056 | 1079 | // Start app in goroutine |
|
0 commit comments