-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(web): migrate to heroicons, tokenize colors, polish UI (P0+P1) #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ package web | |||||||||||||||||||
|
|
||||||||||||||||||||
| import ( | ||||||||||||||||||||
| "encoding/json" | ||||||||||||||||||||
| "io" | ||||||||||||||||||||
| "net/http" | ||||||||||||||||||||
| "time" | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -104,5 +105,47 @@ func (s *Server) handleChannelDisable(w http.ResponseWriter, r *http.Request) { | |||||||||||||||||||
| writeJSON(w, http.StatusOK, map[string]string{"status": "ok", "state": "disabled"}) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // handleChannelBLEStatus reports whether the Bluetooth (BLE) status channel is | ||||||||||||||||||||
| // enabled in config. The actual BLE notifier is only wired at startup (and only | ||||||||||||||||||||
| // on desktop builds with CoreBluetooth), so this reflects the persisted | ||||||||||||||||||||
| // preference, which takes effect on the next launch. | ||||||||||||||||||||
| func (s *Server) handleChannelBLEStatus(w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||
| enabled := false | ||||||||||||||||||||
| if s.cfg != nil && s.cfg.Channel != nil { | ||||||||||||||||||||
| enabled = s.cfg.Channel.BLEEnabled | ||||||||||||||||||||
| } | ||||||||||||||||||||
| writeJSON(w, http.StatusOK, map[string]any{"enabled": enabled}) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // handleSetChannelBLE persists the Bluetooth (BLE) status-channel preference. | ||||||||||||||||||||
| // Like the proxy/cert settings, it takes effect after an app restart (the BLE | ||||||||||||||||||||
| // notifier is created once at startup when channel.ble_enabled is true). | ||||||||||||||||||||
| func (s *Server) handleSetChannelBLE(w http.ResponseWriter, r *http.Request) { | ||||||||||||||||||||
| var req struct { | ||||||||||||||||||||
| Enabled bool `json:"enabled"` | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if err := json.NewDecoder(io.LimitReader(r.Body, 1<<16)).Decode(&req); err != nil { | ||||||||||||||||||||
| writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request"}) | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| s.mu.Lock() | ||||||||||||||||||||
| if s.cfg == nil { | ||||||||||||||||||||
| s.mu.Unlock() | ||||||||||||||||||||
| writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "config unavailable"}) | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if s.cfg.Channel == nil { | ||||||||||||||||||||
| s.cfg.Channel = &config.ChannelConfig{} | ||||||||||||||||||||
| } | ||||||||||||||||||||
| s.cfg.Channel.BLEEnabled = req.Enabled | ||||||||||||||||||||
| if err := config.SaveConfig(s.cfg); err != nil { | ||||||||||||||||||||
| s.mu.Unlock() | ||||||||||||||||||||
| writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()}) | ||||||||||||||||||||
| return | ||||||||||||||||||||
|
Comment on lines
+141
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not return raw config save errors to the client.
Proposed fix if err := config.SaveConfig(s.cfg); err != nil {
s.mu.Unlock()
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ config.Logger().Printf("[web] BLE channel save config failed: %v", err)
+ writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "failed to save BLE setting"})
return
}As per coding guidelines, “All diagnostics must go to 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||
| } | ||||||||||||||||||||
| s.mu.Unlock() | ||||||||||||||||||||
| writeJSON(w, http.StatusOK, map[string]any{"enabled": req.Enabled}) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Ensure writeJSON is used (defined in server.go). | ||||||||||||||||||||
| var _ = json.Marshal | ||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the same mutex for BLE status reads.
handleSetChannelBLEwritess.cfg.Channelunders.mu, but this GET path reads the same pointer/field without synchronization, so concurrent requests can race.Proposed fix
func (s *Server) handleChannelBLEStatus(w http.ResponseWriter, r *http.Request) { + s.mu.Lock() enabled := false if s.cfg != nil && s.cfg.Channel != nil { enabled = s.cfg.Channel.BLEEnabled } + s.mu.Unlock() writeJSON(w, http.StatusOK, map[string]any{"enabled": enabled}) }📝 Committable suggestion
🤖 Prompt for AI Agents