refactor(infra): rename blocked to error in scheme handler + expose shortcuts
- commit
- 656339537b046e91a3a82fb28bff743ebd906176
- author
- bnema · · 2025-12-21 13:53 UTC
- parent
- d567e75
- signature
- unsigned
1 file · +16 -12
M internal/infrastructure/webkit/scheme_handler.go +16 -12
| @@ -23,10 +23,10 @@ import ( | |||
| 23 | 23 | ||
| 24 | 24 | // Scheme path constants | |
| 25 | 25 | const ( | |
| 26 | - | HomePath = "home" | |
| 27 | - | ConfigPath = "config" | |
| 28 | - | BlockedPath = "blocked" | |
| 29 | - | IndexHTML = "index.html" | |
| 26 | + | HomePath = "home" | |
| 27 | + | ConfigPath = "config" | |
| 28 | + | ErrorPath = "error" | |
| 29 | + | IndexHTML = "index.html" | |
| 30 | 30 | ) | |
| 31 | 31 | ||
| 32 | 32 | // SchemeRequest represents a request to a custom URI scheme. | |
| @@ -120,9 +120,11 @@ func (h *DumbSchemeHandler) registerDefaults() { | |||
| 120 | 120 | } `json:"appearance"` | |
| 121 | 121 | DefaultUIScale float64 `json:"default_ui_scale"` | |
| 122 | 122 | DefaultSearchEngine string `json:"default_search_engine"` | |
| 123 | + | SearchShortcuts map[string]config.SearchShortcut `json:"search_shortcuts"` | |
| 123 | 124 | }{ | |
| 124 | 125 | DefaultUIScale: cfg.DefaultUIScale, | |
| 125 | 126 | DefaultSearchEngine: cfg.DefaultSearchEngine, | |
| 127 | + | SearchShortcuts: cfg.SearchShortcuts, | |
| 126 | 128 | } | |
| 127 | 129 | resp.Appearance.SansFont = cfg.Appearance.SansFont | |
| 128 | 130 | resp.Appearance.SerifFont = cfg.Appearance.SerifFont | |
| @@ -166,9 +168,11 @@ func (h *DumbSchemeHandler) registerDefaults() { | |||
| 166 | 168 | } `json:"appearance"` | |
| 167 | 169 | DefaultUIScale float64 `json:"default_ui_scale"` | |
| 168 | 170 | DefaultSearchEngine string `json:"default_search_engine"` | |
| 171 | + | SearchShortcuts map[string]config.SearchShortcut `json:"search_shortcuts"` | |
| 169 | 172 | }{ | |
| 170 | 173 | DefaultUIScale: defaults.DefaultUIScale, | |
| 171 | 174 | DefaultSearchEngine: defaults.DefaultSearchEngine, | |
| 175 | + | SearchShortcuts: defaults.SearchShortcuts, | |
| 172 | 176 | } | |
| 173 | 177 | resp.Appearance.SansFont = defaults.Appearance.SansFont | |
| 174 | 178 | resp.Appearance.SerifFont = defaults.Appearance.SerifFont | |
| @@ -309,18 +313,18 @@ func (h *DumbSchemeHandler) handleAsset(u *url.URL) *SchemeResponse { | |||
| 309 | 313 | // dumb://config/<asset> → serve asset | |
| 310 | 314 | case host == ConfigPath && path != "": | |
| 311 | 315 | relPath = path | |
| 312 | - | // dumb://blocked or dumb://blocked/ → blocked.html | |
| 313 | - | case host == BlockedPath && (path == "" || path == "/"): | |
| 314 | - | relPath = "blocked.html" | |
| 315 | - | // dumb://blocked/<asset> → serve asset | |
| 316 | - | case host == BlockedPath && path != "": | |
| 316 | + | // dumb://error or dumb://error/ → error.html | |
| 317 | + | case host == ErrorPath && (path == "" || path == "/"): | |
| 318 | + | relPath = "error.html" | |
| 319 | + | // dumb://error/<asset> → serve asset | |
| 320 | + | case host == ErrorPath && path != "": | |
| 317 | 321 | relPath = path | |
| 318 | 322 | // dumb:home (opaque form) → index.html | |
| 319 | 323 | case u.Opaque == HomePath: | |
| 320 | 324 | relPath = IndexHTML | |
| 321 | - | // dumb:blocked (opaque form) → blocked.html | |
| 322 | - | case u.Opaque == BlockedPath: | |
| 323 | - | relPath = "blocked.html" | |
| 325 | + | // dumb:error (opaque form) → error.html | |
| 326 | + | case u.Opaque == ErrorPath: | |
| 327 | + | relPath = "error.html" | |
| 324 | 328 | default: | |
| 325 | 329 | // Not a recognized asset path | |
| 326 | 330 | return nil | |
| @@ -23,10 +23,10 @@ import ( | |||||
| 23 | 23 | ||||
| 24 | // Scheme path constants | 24 | // Scheme path constants | ||
| 25 | const ( | 25 | const ( | ||
| 26 | - | HomePath = "home" | 26 | + | HomePath = "home" |
| 27 | - | ConfigPath = "config" | 27 | + | ConfigPath = "config" |
| 28 | - | BlockedPath = "blocked" | 28 | + | ErrorPath = "error" |
| 29 | - | IndexHTML = "index.html" | 29 | + | IndexHTML = "index.html" |
| 30 | ) | 30 | ) | ||
| 31 | 31 | ||||
| 32 | // SchemeRequest represents a request to a custom URI scheme. | 32 | // SchemeRequest represents a request to a custom URI scheme. | ||
| @@ -120,9 +120,11 @@ func (h *DumbSchemeHandler) registerDefaults() { | |||||
| 120 | } `json:"appearance"` | 120 | } `json:"appearance"` | ||
| 121 | DefaultUIScale float64 `json:"default_ui_scale"` | 121 | DefaultUIScale float64 `json:"default_ui_scale"` | ||
| 122 | DefaultSearchEngine string `json:"default_search_engine"` | 122 | DefaultSearchEngine string `json:"default_search_engine"` | ||
| 123 | + | SearchShortcuts map[string]config.SearchShortcut `json:"search_shortcuts"` | |||
| 123 | }{ | 124 | }{ | ||
| 124 | DefaultUIScale: cfg.DefaultUIScale, | 125 | DefaultUIScale: cfg.DefaultUIScale, | ||
| 125 | DefaultSearchEngine: cfg.DefaultSearchEngine, | 126 | DefaultSearchEngine: cfg.DefaultSearchEngine, | ||
| 127 | + | SearchShortcuts: cfg.SearchShortcuts, | |||
| 126 | } | 128 | } | ||
| 127 | resp.Appearance.SansFont = cfg.Appearance.SansFont | 129 | resp.Appearance.SansFont = cfg.Appearance.SansFont | ||
| 128 | resp.Appearance.SerifFont = cfg.Appearance.SerifFont | 130 | resp.Appearance.SerifFont = cfg.Appearance.SerifFont | ||
| @@ -166,9 +168,11 @@ func (h *DumbSchemeHandler) registerDefaults() { | |||||
| 166 | } `json:"appearance"` | 168 | } `json:"appearance"` | ||
| 167 | DefaultUIScale float64 `json:"default_ui_scale"` | 169 | DefaultUIScale float64 `json:"default_ui_scale"` | ||
| 168 | DefaultSearchEngine string `json:"default_search_engine"` | 170 | DefaultSearchEngine string `json:"default_search_engine"` | ||
| 171 | + | SearchShortcuts map[string]config.SearchShortcut `json:"search_shortcuts"` | |||
| 169 | }{ | 172 | }{ | ||
| 170 | DefaultUIScale: defaults.DefaultUIScale, | 173 | DefaultUIScale: defaults.DefaultUIScale, | ||
| 171 | DefaultSearchEngine: defaults.DefaultSearchEngine, | 174 | DefaultSearchEngine: defaults.DefaultSearchEngine, | ||
| 175 | + | SearchShortcuts: defaults.SearchShortcuts, | |||
| 172 | } | 176 | } | ||
| 173 | resp.Appearance.SansFont = defaults.Appearance.SansFont | 177 | resp.Appearance.SansFont = defaults.Appearance.SansFont | ||
| 174 | resp.Appearance.SerifFont = defaults.Appearance.SerifFont | 178 | resp.Appearance.SerifFont = defaults.Appearance.SerifFont | ||
| @@ -309,18 +313,18 @@ func (h *DumbSchemeHandler) handleAsset(u *url.URL) *SchemeResponse { | |||||
| 309 | // dumb://config/<asset> → serve asset | 313 | // dumb://config/<asset> → serve asset | ||
| 310 | case host == ConfigPath && path != "": | 314 | case host == ConfigPath && path != "": | ||
| 311 | relPath = path | 315 | relPath = path | ||
| 312 | - | // dumb://blocked or dumb://blocked/ → blocked.html | 316 | + | // dumb://error or dumb://error/ → error.html |
| 313 | - | case host == BlockedPath && (path == "" || path == "/"): | 317 | + | case host == ErrorPath && (path == "" || path == "/"): |
| 314 | - | relPath = "blocked.html" | 318 | + | relPath = "error.html" |
| 315 | - | // dumb://blocked/<asset> → serve asset | 319 | + | // dumb://error/<asset> → serve asset |
| 316 | - | case host == BlockedPath && path != "": | 320 | + | case host == ErrorPath && path != "": |
| 317 | relPath = path | 321 | relPath = path | ||
| 318 | // dumb:home (opaque form) → index.html | 322 | // dumb:home (opaque form) → index.html | ||
| 319 | case u.Opaque == HomePath: | 323 | case u.Opaque == HomePath: | ||
| 320 | relPath = IndexHTML | 324 | relPath = IndexHTML | ||
| 321 | - | // dumb:blocked (opaque form) → blocked.html | 325 | + | // dumb:error (opaque form) → error.html |
| 322 | - | case u.Opaque == BlockedPath: | 326 | + | case u.Opaque == ErrorPath: |
| 323 | - | relPath = "blocked.html" | 327 | + | relPath = "error.html" |
| 324 | default: | 328 | default: | ||
| 325 | // Not a recognized asset path | 329 | // Not a recognized asset path | ||
| 326 | return nil | 330 | return nil | ||