-
Notifications
You must be signed in to change notification settings - Fork 625
fix: sync font size changes across all tabs in real-time #786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -691,6 +691,9 @@ export const useSettingsStore = defineStore('settings', () => { | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 设置拷贝事件监听器 | ||||||||||||||||||||||||||||||||||||||||||||||||
| setupCopyWithCotEnabledListener() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 设置字体大小事件监听器 | ||||||||||||||||||||||||||||||||||||||||||||||||
| setupFontSizeListener() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 更新本地模型状态,不触发后端请求 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1434,6 +1437,15 @@ export const useSettingsStore = defineStore('settings', () => { | |||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const setupFontSizeListener = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| window.electron.ipcRenderer.on( | ||||||||||||||||||||||||||||||||||||||||||||||||
| CONFIG_EVENTS.FONT_SIZE_CHANGED, | ||||||||||||||||||||||||||||||||||||||||||||||||
| (_event, newFontSizeLevel: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| fontSizeLevel.value = newFontSizeLevel | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1440
to
+1448
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMake the listener idempotent and validate/clamp payload before applying. Guard against multiple registrations and out-of-range/invalid payloads. This avoids leaks under HMR and prevents invalid class indexing. -const setupFontSizeListener = () => {
- window.electron.ipcRenderer.on(
- CONFIG_EVENTS.FONT_SIZE_CHANGED,
- (_event, newFontSizeLevel: number) => {
- fontSizeLevel.value = newFontSizeLevel
- }
- )
-}
+const setupFontSizeListener = () => {
+ // Ensure idempotency: remove any existing handlers before binding
+ window.electron?.ipcRenderer?.removeAllListeners(CONFIG_EVENTS.FONT_SIZE_CHANGED)
+ window.electron.ipcRenderer.on(
+ CONFIG_EVENTS.FONT_SIZE_CHANGED,
+ (_event, newFontSizeLevel: number) => {
+ // Validate and clamp to valid range
+ const parsed =
+ typeof newFontSizeLevel === 'number' ? newFontSizeLevel : Number(newFontSizeLevel)
+ const clamped = Number.isFinite(parsed)
+ ? Math.max(0, Math.min(parsed, FONT_SIZE_CLASSES.length - 1))
+ : DEFAULT_FONT_SIZE_LEVEL
+ fontSizeLevel.value = clamped
+ }
+ )
+}After applying, trigger a few rapid font-size changes in one tab and confirm only one handler fires by temporarily logging inside the listener once. You should see a single log per event across tabs. 🏁 Script executed: #!/bin/bash
# Search for the setupFontSizeListener implementation
rg -n "setupFontSizeListener" -C3 --type=ts
# Check for FONT_SIZE_CLASSES definition or usage
rg -n "FONT_SIZE_CLASSES" -C3 --type=ts
# Check for DEFAULT_FONT_SIZE_LEVEL definition or usage
rg -n "DEFAULT_FONT_SIZE_LEVEL" -C3 --type=ts
# Inspect ipcRenderer usage patterns
rg -n "ipcRenderer" -C3 --type=tsLength of output: 29703 Implement Idempotent Font-Size Listener with Input Validation To avoid duplicate handlers during HMR and prevent out-of-range values from corrupting the UI, update the listener in • Before registering, clear any existing Apply this diff at lines ~1439–1448: const setupFontSizeListener = () => {
- window.electron.ipcRenderer.on(
- CONFIG_EVENTS.FONT_SIZE_CHANGED,
- (_event, newFontSizeLevel: number) => {
- fontSizeLevel.value = newFontSizeLevel
- }
- )
+ // Ensure single registration (idempotent under HMR)
+ window.electron.ipcRenderer.removeAllListeners(CONFIG_EVENTS.FONT_SIZE_CHANGED)
+ window.electron.ipcRenderer.on(
+ CONFIG_EVENTS.FONT_SIZE_CHANGED,
+ (_event, payload: unknown) => {
+ // Parse and clamp the new level
+ const raw = typeof payload === 'number' ? payload : Number(payload)
+ const valid = Number.isFinite(raw)
+ ? Math.min(Math.max(0, raw), FONT_SIZE_CLASSES.length - 1)
+ : DEFAULT_FONT_SIZE_LEVEL
+ fontSizeLevel.value = valid
+ }
+ )
}Locations to update:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| /////////////////////////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||||
| const findModelByIdOrName = ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| modelId: string | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Duplicate listener registration path; move or guard setupFontSizeListener to avoid double handlers.
setupProviderListener() is invoked inside initSettings() and again in onMounted(), which means setupFontSizeListener() is currently registered at least twice. This will cause duplicate event handling and jitter when FONT_SIZE_CHANGED fires. The AI summary also states it’s called directly during initialization, but in code it’s nested under setupProviderListener().
Apply this diff to prevent duplicate registration here (call it once from initSettings instead; see snippet below):
Additionally, update the initialization and lifecycle (outside this hunk) as follows:
Example (outside changed ranges):
Optionally, add cleanup:
🤖 Prompt for AI Agents