feat(input): add hot reload for keyboard shortcuts
- commit
- e6c3832537e73ab84f76a1991ef1e09d8aadeff8
- author
- bnema · · 2026-01-11 14:21 UTC
- committer
- brice · · 2026-01-24 06:22 UTC
- parent
- 7e934a8
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +18 -1
M internal/ui/app.go +5 -1
| @@ -1946,11 +1946,15 @@ func (a *App) initConfigWatcher(ctx context.Context) { | |||
| 1946 | 1946 | return | |
| 1947 | 1947 | } | |
| 1948 | 1948 | ||
| 1949 | - | // Only appearance is hot-reloaded for now. | |
| 1949 | + | // Hot-reload appearance and keybindings on config change. | |
| 1950 | 1950 | a.configManager.OnConfigChange(func(newCfg *config.Config) { | |
| 1951 | 1951 | cfgCopy := newCfg | |
| 1952 | 1952 | cb := glib.SourceFunc(func(_ uintptr) bool { | |
| 1953 | 1953 | a.applyAppearanceConfig(ctx, cfgCopy) | |
| 1954 | + | // Reload keyboard shortcuts | |
| 1955 | + | if a.keyboardHandler != nil { | |
| 1956 | + | a.keyboardHandler.ReloadShortcuts(ctx, cfgCopy) | |
| 1957 | + | } | |
| 1954 | 1958 | return false | |
| 1955 | 1959 | }) | |
| 1956 | 1960 | glib.IdleAdd(&cb, 0) | |
| @@ -1946,11 +1946,15 @@ func (a *App) initConfigWatcher(ctx context.Context) { | |||||
| 1946 | return | 1946 | return | ||
| 1947 | } | 1947 | } | ||
| 1948 | 1948 | ||||
| 1949 | - | // Only appearance is hot-reloaded for now. | 1949 | + | // Hot-reload appearance and keybindings on config change. |
| 1950 | a.configManager.OnConfigChange(func(newCfg *config.Config) { | 1950 | a.configManager.OnConfigChange(func(newCfg *config.Config) { | ||
| 1951 | cfgCopy := newCfg | 1951 | cfgCopy := newCfg | ||
| 1952 | cb := glib.SourceFunc(func(_ uintptr) bool { | 1952 | cb := glib.SourceFunc(func(_ uintptr) bool { | ||
| 1953 | a.applyAppearanceConfig(ctx, cfgCopy) | 1953 | a.applyAppearanceConfig(ctx, cfgCopy) | ||
| 1954 | + | // Reload keyboard shortcuts | |||
| 1955 | + | if a.keyboardHandler != nil { | |||
| 1956 | + | a.keyboardHandler.ReloadShortcuts(ctx, cfgCopy) | |||
| 1957 | + | } | |||
| 1954 | return false | 1958 | return false | ||
| 1955 | }) | 1959 | }) | ||
| 1956 | glib.IdleAdd(&cb, 0) | 1960 | glib.IdleAdd(&cb, 0) | ||
M internal/ui/input/keyboard.go +13 -0
| @@ -79,6 +79,19 @@ func (h *KeyboardHandler) SetOnAction(fn ActionHandler) { | |||
| 79 | 79 | h.onAction = fn | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | + | // ReloadShortcuts rebuilds the shortcut set from the new config. | |
| 83 | + | // This enables hot-reloading of keybindings without restarting. | |
| 84 | + | func (h *KeyboardHandler) ReloadShortcuts(ctx context.Context, cfg *config.Config) { | |
| 85 | + | h.mu.Lock() | |
| 86 | + | defer h.mu.Unlock() | |
| 87 | + | ||
| 88 | + | log := logging.FromContext(ctx) | |
| 89 | + | log.Debug().Msg("reloading shortcuts from config") | |
| 90 | + | ||
| 91 | + | h.shortcuts = NewShortcutSet(ctx, cfg) | |
| 92 | + | h.cfg = cfg | |
| 93 | + | } | |
| 94 | + | ||
| 82 | 95 | // SetOnModeChange sets the callback for mode changes (for UI updates). | |
| 83 | 96 | func (h *KeyboardHandler) SetOnModeChange(fn func(from, to Mode)) { | |
| 84 | 97 | h.modal.SetOnModeChange(fn) | |
| @@ -79,6 +79,19 @@ func (h *KeyboardHandler) SetOnAction(fn ActionHandler) { | |||||
| 79 | h.onAction = fn | 79 | h.onAction = fn | ||
| 80 | } | 80 | } | ||
| 81 | 81 | ||||
| 82 | + | // ReloadShortcuts rebuilds the shortcut set from the new config. | |||
| 83 | + | // This enables hot-reloading of keybindings without restarting. | |||
| 84 | + | func (h *KeyboardHandler) ReloadShortcuts(ctx context.Context, cfg *config.Config) { | |||
| 85 | + | h.mu.Lock() | |||
| 86 | + | defer h.mu.Unlock() | |||
| 87 | + | ||||
| 88 | + | log := logging.FromContext(ctx) | |||
| 89 | + | log.Debug().Msg("reloading shortcuts from config") | |||
| 90 | + | ||||
| 91 | + | h.shortcuts = NewShortcutSet(ctx, cfg) | |||
| 92 | + | h.cfg = cfg | |||
| 93 | + | } | |||
| 94 | + | ||||
| 82 | // SetOnModeChange sets the callback for mode changes (for UI updates). | 95 | // SetOnModeChange sets the callback for mode changes (for UI updates). | ||
| 83 | func (h *KeyboardHandler) SetOnModeChange(fn func(from, to Mode)) { | 96 | func (h *KeyboardHandler) SetOnModeChange(fn func(from, to Mode)) { | ||
| 84 | h.modal.SetOnModeChange(fn) | 97 | h.modal.SetOnModeChange(fn) | ||