fix(workspace): whitelist focus-worthy script messages
- commit
- a01372510c2c5dc90e6bd68cbea7adae89a8afcc
- author
- bamen · · 2025-10-12 08:34 UTC
- parent
- 8a3525b
- signature
- unsigned
1 file · +7 -6
M internal/app/browser/webview.go +7 -6
| @@ -210,9 +210,10 @@ func (app *BrowserApp) attachPaneHandlers(pane *BrowserPane) { | |||
| 210 | 210 | } | |
| 211 | 211 | } | |
| 212 | 212 | ||
| 213 | - | // shouldFocusForScriptMessage filters out bootstrap messages that fire without user | |
| 214 | - | // interaction (palette sync, shortcut preload, etc.). Only actionable payloads should | |
| 215 | - | // bump the pane back to the front. | |
| 213 | + | // shouldFocusForScriptMessage filters script messages and only allows focus handoff | |
| 214 | + | // for explicit user-driven actions (navigation, history commands, popup lifecycle). | |
| 215 | + | // Background bootstrap messages (palette sync, workspace bridge chatter, etc.) are | |
| 216 | + | // ignored so they don't steal focus from the user's active pane. | |
| 216 | 217 | func shouldFocusForScriptMessage(payload string) bool { | |
| 217 | 218 | var msg messaging.Message | |
| 218 | 219 | if err := json.Unmarshal([]byte(payload), &msg); err != nil { | |
| @@ -220,10 +221,10 @@ func shouldFocusForScriptMessage(payload string) bool { | |||
| 220 | 221 | } | |
| 221 | 222 | ||
| 222 | 223 | switch msg.Type { | |
| 223 | - | case "get_color_palettes", "get_search_shortcuts", "request-webview-id", "console-message", "workspace": | |
| 224 | - | return false | |
| 225 | - | default: | |
| 224 | + | case "navigate", "query", "wails", "history_recent", "history_stats", "history_search", "history_delete", "close-popup": | |
| 226 | 225 | return true | |
| 226 | + | default: | |
| 227 | + | return false | |
| 227 | 228 | } | |
| 228 | 229 | } | |
| 229 | 230 | ||
| @@ -210,9 +210,10 @@ func (app *BrowserApp) attachPaneHandlers(pane *BrowserPane) { | |||||
| 210 | } | 210 | } | ||
| 211 | } | 211 | } | ||
| 212 | 212 | ||||
| 213 | - | // shouldFocusForScriptMessage filters out bootstrap messages that fire without user | 213 | + | // shouldFocusForScriptMessage filters script messages and only allows focus handoff |
| 214 | - | // interaction (palette sync, shortcut preload, etc.). Only actionable payloads should | 214 | + | // for explicit user-driven actions (navigation, history commands, popup lifecycle). |
| 215 | - | // bump the pane back to the front. | 215 | + | // Background bootstrap messages (palette sync, workspace bridge chatter, etc.) are |
| 216 | + | // ignored so they don't steal focus from the user's active pane. | |||
| 216 | func shouldFocusForScriptMessage(payload string) bool { | 217 | func shouldFocusForScriptMessage(payload string) bool { | ||
| 217 | var msg messaging.Message | 218 | var msg messaging.Message | ||
| 218 | if err := json.Unmarshal([]byte(payload), &msg); err != nil { | 219 | if err := json.Unmarshal([]byte(payload), &msg); err != nil { | ||
| @@ -220,10 +221,10 @@ func shouldFocusForScriptMessage(payload string) bool { | |||||
| 220 | } | 221 | } | ||
| 221 | 222 | ||||
| 222 | switch msg.Type { | 223 | switch msg.Type { | ||
| 223 | - | case "get_color_palettes", "get_search_shortcuts", "request-webview-id", "console-message", "workspace": | 224 | + | case "navigate", "query", "wails", "history_recent", "history_stats", "history_search", "history_delete", "close-popup": |
| 224 | - | return false | |||
| 225 | - | default: | |||
| 226 | return true | 225 | return true | ||
| 226 | + | default: | |||
| 227 | + | return false | |||
| 227 | } | 228 | } | ||
| 228 | } | 229 | } | ||
| 229 | 230 | ||||