From befa9795c1fc12c74f25048f6a470365bc11a7dc Mon Sep 17 00:00:00 2001 From: luxick Date: Sat, 28 Mar 2026 12:47:38 +0100 Subject: [PATCH] Update main.go --- main.go | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 1947919..643a9c5 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,8 @@ type openResponse struct { } type settingsConfig struct { - PathMap map[string]string `json:"path_map"` + PathMap map[string]string `json:"path_map"` + OpenLocationCommand string `json:"open_location_command"` } type configStore struct { @@ -84,7 +85,10 @@ func newConfigStore() (*configStore, error) { func (s *configStore) Snapshot() config.Config { s.mu.RLock() defer s.mu.RUnlock() - return config.Config{PathMap: clonePathMap(s.cfg.PathMap)} + return config.Config{ + PathMap: clonePathMap(s.cfg.PathMap), + OpenLocationCommand: s.cfg.OpenLocationCommand, + } } func (s *configStore) Update(cfg config.Config) error { @@ -292,7 +296,11 @@ func main() { case http.MethodGet: cfg := configStore.Snapshot() w.Header().Set("Content-Type", "application/json") - _ = json.NewEncoder(w).Encode(map[string]any{"ok": true, "path_map": cfg.PathMap}) + _ = json.NewEncoder(w).Encode(map[string]any{ + "ok": true, + "path_map": cfg.PathMap, + "open_location_command": cfg.OpenLocationCommand, + }) return case http.MethodPost, http.MethodPut: dec := json.NewDecoder(http.MaxBytesReader(w, r.Body, 128*1024)) @@ -309,12 +317,18 @@ func main() { return } - if err := configStore.Update(config.Config{PathMap: pathMap}); err != nil { + openCmd := strings.TrimSpace(req.OpenLocationCommand) + + if err := configStore.Update(config.Config{PathMap: pathMap, OpenLocationCommand: openCmd}); err != nil { writeJSON(w, http.StatusInternalServerError, openResponse{OK: false, Message: err.Error()}) return } w.Header().Set("Content-Type", "application/json") - _ = json.NewEncoder(w).Encode(map[string]any{"ok": true, "path_map": pathMap}) + _ = json.NewEncoder(w).Encode(map[string]any{ + "ok": true, + "path_map": pathMap, + "open_location_command": openCmd, + }) return default: w.WriteHeader(http.StatusMethodNotAllowed) @@ -372,10 +386,16 @@ func main() { return } - if err := openfolder.OpenLocation(target); err != nil { - errLog.Printf("/open open-failed method=%s path=%q normalized=%q err=%v dur=%s", r.Method, rawPath, target, err, time.Since(start)) - notify.Show("luxtools-client", fmt.Sprintf("Failed to open: %s (%v)", target, err)) - writeJSON(w, http.StatusInternalServerError, openResponse{OK: false, Message: err.Error()}) + var openErr error + if customCmd := configStore.Snapshot().OpenLocationCommand; customCmd != "" { + openErr = openfolder.OpenLocationCustom(customCmd, target) + } else { + openErr = openfolder.OpenLocation(target) + } + if openErr != nil { + errLog.Printf("/open open-failed method=%s path=%q normalized=%q err=%v dur=%s", r.Method, rawPath, target, openErr, time.Since(start)) + notify.Show("luxtools-client", fmt.Sprintf("Failed to open: %s (%v)", target, openErr)) + writeJSON(w, http.StatusInternalServerError, openResponse{OK: false, Message: openErr.Error()}) return } infoLog.Printf("/open opened method=%s path=%q normalized=%q dur=%s", r.Method, rawPath, target, time.Since(start))