detached 5efc1b9

refactor: centralize permission URL log constant and clean up minor issues

- Move maxPermissionLogURLLen to logging.PermissionLogURLMaxLen (was duplicated in 3 files)
- Replace stringly-typed "website_data_access" with entity constant in webview.go
- Cache parsePermFlags result in permission dialog instead of computing twice
- Remove redundant hadGhost guard in omnibox clearGhostText
commit
5efc1b980e016b5fd2af07d30603ef50de900029
author
bnema · · 2026-03-27 22:07 UTC
parent
3cb3770
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
5 files · +16 -18
M internal/application/usecase/handle_permission.go +2 -4
@@ -58,8 +58,6 @@ func (uc *HandlePermissionUseCase) logger(ctx context.Context) *zerolog.Logger {
5858 return log
5959 }
6060
61-const maxPermissionLogURLLen = 96
62-
6361 func isWebsiteDataAccessPermission(permTypes []entity.PermissionType) bool {
6462 for _, permType := range permTypes {
6563 if permType == entity.PermissionTypeWebsiteDataAccess {
@@ -76,10 +74,10 @@ func permissionLoggerWithMetadata(log *zerolog.Logger, metadata entity.Permissio
7674 }
7775 ctx := log.With()
7876 if requesting := metadata[entity.PermissionMetadataKeyRequestingDomain]; requesting != "" {
79- ctx = ctx.Str("requesting_domain", logging.TruncateURL(requesting, maxPermissionLogURLLen))
77+ ctx = ctx.Str("requesting_domain", logging.TruncateURL(requesting, logging.PermissionLogURLMaxLen))
8078 }
8179 if current := metadata[entity.PermissionMetadataKeyCurrentDomain]; current != "" {
82- ctx = ctx.Str("current_domain", logging.TruncateURL(current, maxPermissionLogURLLen))
80+ ctx = ctx.Str("current_domain", logging.TruncateURL(current, logging.PermissionLogURLMaxLen))
8381 }
8482 enriched := ctx.Logger()
8583 return &enriched
@@ -58,8 +58,6 @@ func (uc *HandlePermissionUseCase) logger(ctx context.Context) *zerolog.Logger {
58 return log58 return log
59 }59 }
60 60
61-const maxPermissionLogURLLen = 96
62-
63 func isWebsiteDataAccessPermission(permTypes []entity.PermissionType) bool {61 func isWebsiteDataAccessPermission(permTypes []entity.PermissionType) bool {
64 for _, permType := range permTypes {62 for _, permType := range permTypes {
65 if permType == entity.PermissionTypeWebsiteDataAccess {63 if permType == entity.PermissionTypeWebsiteDataAccess {
@@ -76,10 +74,10 @@ func permissionLoggerWithMetadata(log *zerolog.Logger, metadata entity.Permissio
76 }74 }
77 ctx := log.With()75 ctx := log.With()
78 if requesting := metadata[entity.PermissionMetadataKeyRequestingDomain]; requesting != "" {76 if requesting := metadata[entity.PermissionMetadataKeyRequestingDomain]; requesting != "" {
79- ctx = ctx.Str("requesting_domain", logging.TruncateURL(requesting, maxPermissionLogURLLen))77+ ctx = ctx.Str("requesting_domain", logging.TruncateURL(requesting, logging.PermissionLogURLMaxLen))
80 }78 }
81 if current := metadata[entity.PermissionMetadataKeyCurrentDomain]; current != "" {79 if current := metadata[entity.PermissionMetadataKeyCurrentDomain]; current != "" {
82- ctx = ctx.Str("current_domain", logging.TruncateURL(current, maxPermissionLogURLLen))80+ ctx = ctx.Str("current_domain", logging.TruncateURL(current, logging.PermissionLogURLMaxLen))
83 }81 }
84 enriched := ctx.Logger()82 enriched := ctx.Logger()
85 return &enriched83 return &enriched
M internal/infrastructure/webkit/webview.go +3 -4
@@ -608,7 +608,6 @@ func (wv *WebView) connectFaviconSignal() {
608608
609609 // progressThrottleInterval limits progress callbacks to ~60fps to reduce UI overhead.
610610 const progressThrottleInterval = 16 * time.Millisecond
611-const maxPermissionLogURLLen = 96
612611
613612 func (wv *WebView) connectProgressSignal() {
614613 progressCb := func() {
@@ -1047,11 +1046,11 @@ func (wv *WebView) connectPermissionRequestSignal() {
10471046 wv.logger.Warn().Msg("permission request with unknown type, denying")
10481047 return false
10491048 }
1050- if len(permTypes) == 1 && permTypes[0] == "website_data_access" {
1049+ if len(permTypes) == 1 && permTypes[0] == string(entity.PermissionTypeWebsiteDataAccess) {
10511050 wv.logger.Info().
10521051 Str("origin", origin).
1053- Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], maxPermissionLogURLLen)).
1054- Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], maxPermissionLogURLLen)).
1052+ Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], logging.PermissionLogURLMaxLen)).
1053+ Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], logging.PermissionLogURLMaxLen)).
10551054 Msg("website data access permission requested")
10561055 }
10571056
@@ -608,7 +608,6 @@ func (wv *WebView) connectFaviconSignal() {
608 608
609 // progressThrottleInterval limits progress callbacks to ~60fps to reduce UI overhead.609 // progressThrottleInterval limits progress callbacks to ~60fps to reduce UI overhead.
610 const progressThrottleInterval = 16 * time.Millisecond610 const progressThrottleInterval = 16 * time.Millisecond
611-const maxPermissionLogURLLen = 96
612 611
613 func (wv *WebView) connectProgressSignal() {612 func (wv *WebView) connectProgressSignal() {
614 progressCb := func() {613 progressCb := func() {
@@ -1047,11 +1046,11 @@ func (wv *WebView) connectPermissionRequestSignal() {
1047 wv.logger.Warn().Msg("permission request with unknown type, denying")1046 wv.logger.Warn().Msg("permission request with unknown type, denying")
1048 return false1047 return false
1049 }1048 }
1050- if len(permTypes) == 1 && permTypes[0] == "website_data_access" {1049+ if len(permTypes) == 1 && permTypes[0] == string(entity.PermissionTypeWebsiteDataAccess) {
1051 wv.logger.Info().1050 wv.logger.Info().
1052 Str("origin", origin).1051 Str("origin", origin).
1053- Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], maxPermissionLogURLLen)).1052+ Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], logging.PermissionLogURLMaxLen)).
1054- Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], maxPermissionLogURLLen)).1053+ Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], logging.PermissionLogURLMaxLen)).
1055 Msg("website data access permission requested")1054 Msg("website data access permission requested")
1056 }1055 }
1057 1056
M internal/logging/logger.go +3 -0
@@ -190,6 +190,9 @@ func ParseLevel(level string) zerolog.Level {
190190 }
191191 }
192192
193+// PermissionLogURLMaxLen is the standard max length for permission-related URL logging.
194+const PermissionLogURLMaxLen = 96
195+
193196 // TruncateURL truncates a URL to maxLen characters for logging.
194197 func TruncateURL(url string, maxLen int) string {
195198 if len(url) <= maxLen {
@@ -190,6 +190,9 @@ func ParseLevel(level string) zerolog.Level {
190 }190 }
191 }191 }
192 192
193+// PermissionLogURLMaxLen is the standard max length for permission-related URL logging.
194+const PermissionLogURLMaxLen = 96
195+
193 // TruncateURL truncates a URL to maxLen characters for logging.196 // TruncateURL truncates a URL to maxLen characters for logging.
194 func TruncateURL(url string, maxLen int) string {197 func TruncateURL(url string, maxLen int) string {
195 if len(url) <= maxLen {198 if len(url) <= maxLen {
M internal/ui/component/omnibox.go +1 -2
@@ -951,14 +951,13 @@ func (o *Omnibox) setGhostText(originalInput, suffix string) {
951951 func (o *Omnibox) clearGhostText() {
952952 log := logging.FromContext(o.ctx)
953953 o.mu.Lock()
954- hadGhost := o.ghostSuffix != ""
955954 ghostSuffix := o.ghostSuffix
956955 realInput := o.realInput
957956 o.ghostSuffix = ""
958957
959958 o.mu.Unlock()
960959
961- if !hadGhost || ghostSuffix == "" || o.entry == nil {
960+ if ghostSuffix == "" || o.entry == nil {
962961 return
963962 }
964963
@@ -951,14 +951,13 @@ func (o *Omnibox) setGhostText(originalInput, suffix string) {
951 func (o *Omnibox) clearGhostText() {951 func (o *Omnibox) clearGhostText() {
952 log := logging.FromContext(o.ctx)952 log := logging.FromContext(o.ctx)
953 o.mu.Lock()953 o.mu.Lock()
954- hadGhost := o.ghostSuffix != ""
955 ghostSuffix := o.ghostSuffix954 ghostSuffix := o.ghostSuffix
956 realInput := o.realInput955 realInput := o.realInput
957 o.ghostSuffix = ""956 o.ghostSuffix = ""
958 957
959 o.mu.Unlock()958 o.mu.Unlock()
960 959
961- if !hadGhost || ghostSuffix == "" || o.entry == nil {960+ if ghostSuffix == "" || o.entry == nil {
962 return961 return
963 }962 }
964 963
M internal/ui/dialog/permission.go +7 -8
@@ -13,8 +13,6 @@ import (
1313 "github.com/bnema/dumber/internal/ui/component"
1414 )
1515
16-const maxPermissionLogURLLen = 96
17-
1816 type permissionPopup interface {
1917 Show(ctx context.Context, heading, body string, callback func(allowed, persistent bool))
2018 }
@@ -102,20 +100,21 @@ func (d *PermissionDialog) showRequest(req permissionDialogRequest) {
102100 heading := d.buildHeading(permTypes)
103101 body := d.buildBody(origin, permTypes, metadata)
104102
105- if parsePermFlags(permTypes).dataAccess {
103+ isDataAccess := parsePermFlags(permTypes).dataAccess
104+ if isDataAccess {
106105 log.Info().
107106 Str("origin", origin).
108- Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], maxPermissionLogURLLen)).
109- Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], maxPermissionLogURLLen)).
107+ Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], logging.PermissionLogURLMaxLen)).
108+ Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], logging.PermissionLogURLMaxLen)).
110109 Msg("showing website data access permission dialog")
111110 }
112111
113112 d.popup.Show(ctx, heading, body, func(allowed, persistent bool) {
114- if parsePermFlags(permTypes).dataAccess {
113+ if isDataAccess {
115114 log.Info().
116115 Str("origin", origin).
117- Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], maxPermissionLogURLLen)).
118- Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], maxPermissionLogURLLen)).
116+ Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], logging.PermissionLogURLMaxLen)).
117+ Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], logging.PermissionLogURLMaxLen)).
119118 Bool("allowed", allowed).
120119 Bool("persistent", persistent).
121120 Msg("website data access permission dialog response")
@@ -13,8 +13,6 @@ import (
13 "github.com/bnema/dumber/internal/ui/component"13 "github.com/bnema/dumber/internal/ui/component"
14 )14 )
15 15
16-const maxPermissionLogURLLen = 96
17-
18 type permissionPopup interface {16 type permissionPopup interface {
19 Show(ctx context.Context, heading, body string, callback func(allowed, persistent bool))17 Show(ctx context.Context, heading, body string, callback func(allowed, persistent bool))
20 }18 }
@@ -102,20 +100,21 @@ func (d *PermissionDialog) showRequest(req permissionDialogRequest) {
102 heading := d.buildHeading(permTypes)100 heading := d.buildHeading(permTypes)
103 body := d.buildBody(origin, permTypes, metadata)101 body := d.buildBody(origin, permTypes, metadata)
104 102
105- if parsePermFlags(permTypes).dataAccess {103+ isDataAccess := parsePermFlags(permTypes).dataAccess
104+ if isDataAccess {
106 log.Info().105 log.Info().
107 Str("origin", origin).106 Str("origin", origin).
108- Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], maxPermissionLogURLLen)).107+ Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], logging.PermissionLogURLMaxLen)).
109- Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], maxPermissionLogURLLen)).108+ Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], logging.PermissionLogURLMaxLen)).
110 Msg("showing website data access permission dialog")109 Msg("showing website data access permission dialog")
111 }110 }
112 111
113 d.popup.Show(ctx, heading, body, func(allowed, persistent bool) {112 d.popup.Show(ctx, heading, body, func(allowed, persistent bool) {
114- if parsePermFlags(permTypes).dataAccess {113+ if isDataAccess {
115 log.Info().114 log.Info().
116 Str("origin", origin).115 Str("origin", origin).
117- Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], maxPermissionLogURLLen)).116+ Str("requesting_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyRequestingDomain], logging.PermissionLogURLMaxLen)).
118- Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], maxPermissionLogURLLen)).117+ Str("current_domain", logging.TruncateURL(metadata[entity.PermissionMetadataKeyCurrentDomain], logging.PermissionLogURLMaxLen)).
119 Bool("allowed", allowed).118 Bool("allowed", allowed).
120 Bool("persistent", persistent).119 Bool("persistent", persistent).
121 Msg("website data access permission dialog response")120 Msg("website data access permission dialog response")

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