v0.22.0 a85da87

config.go RawHistoryFolder

1package handlers
2
3import (
4	"context"
5	"encoding/json"
6	"fmt"
7
8	"github.com/bnema/dumber/internal/application/port"
9	"github.com/bnema/dumber/internal/application/usecase"
10	"github.com/bnema/dumber/internal/infrastructure/config"
11	"github.com/bnema/dumber/internal/infrastructure/webkit"
12	"github.com/bnema/dumber/internal/logging"
13)
14
15// ConfigHandler handles configuration-related messages.
16type ConfigHandler struct{}
17
18// NewConfigHandler creates a new ConfigHandler.
19func NewConfigHandler() *ConfigHandler {
20	return &ConfigHandler{}
21}
22
23// Handle processes the save_config message.
24func (h *ConfigHandler) Handle(ctx context.Context, _ webkit.WebViewID, payload json.RawMessage) (any, error) {
25	if h == nil {
26		return nil, fmt.Errorf("config handler is nil")
27	}
28	log := logging.FromContext(ctx).With().Str("handler", "config").Logger()
29
30	var payloadCfg port.WebUIConfig
31	if err := json.Unmarshal(payload, &payloadCfg); err != nil {
32		log.Error().Err(err).Msg("failed to unmarshal config payload")
33		return nil, fmt.Errorf("invalid config format: %w", err)
34	}
35
36	log.Info().Msg("saving appearance configuration from webui")
37	mgr := config.GetManager()
38	if mgr == nil {
39		return nil, fmt.Errorf("config manager not initialized")
40	}
41
42	uc := usecase.NewSaveWebUIConfigUseCase(config.NewWebUIConfigGateway(mgr))
43	if err := uc.Execute(ctx, payloadCfg); err != nil {
44		log.Error().Err(err).Msg("failed to save config")
45		return nil, fmt.Errorf("failed to save config: %w", err)
46	}
47
48	return map[string]any{"status": "success"}, nil
49}
50
51// RegisterConfigHandlers registers configuration handlers with the router.
52func RegisterConfigHandlers(ctx context.Context, router *webkit.MessageRouter) error {
53	handler := NewConfigHandler()
54
55	// worldName empty means main world (since dumb:// pages run in main world)
56	// callback/errorCallback can be used if we want to notify JS of success/fail
57	// In Svelte we use fetch() for GET, but for POST we use message bridge
58	// Actually, if we use message bridge, we might want response callbacks.
59
60	log := logging.FromContext(ctx).With().Str("component", "handlers").Logger()
61
62	// Message type: save_config
63	if err := router.RegisterHandlerWithCallbacks(
64		"save_config",
65		"__dumber_config_saved",
66		"__dumber_config_error",
67		"",
68		handler,
69	); err != nil {
70		return err
71	}
72
73	log.Info().Msg("registered save_config handler")
74
75	return nil
76}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close