-
Notifications
You must be signed in to change notification settings - Fork 427
fix(settings): toggle settings shortcut #1915
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
06d41f0
db2396e
01ad0b0
63c5222
f0a0af4
3b10306
cb8277b
e2ea3a8
c199746
4361fa8
e5b4d0d
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { ViewId } from '@renderer/app/view-registry'; | ||
| import type { NavigateFnTyped } from './navigation-provider'; | ||
|
|
||
| type NonSettingsViewId = Exclude<ViewId, 'settings'>; | ||
|
|
||
| let previousView: NonSettingsViewId = 'home'; | ||
| let lastToggleAt = 0; | ||
|
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.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/renderer/lib/layout/settings-toggle.ts
Line: 5-7
Comment:
**Module-level `previousView` shared across all toggle callers**
`previousView` and `lastToggleAt` are module-level singletons. Both `AppMenuEvents` and `AppKeyboardShortcuts` call `toggleSettingsView`, so a menu-triggered toggle and a keyboard-triggered toggle that happen to arrive outside the 150 ms dedup window (e.g., under load) will each read and overwrite the same `previousView`. More broadly, if a future caller opens settings through a different code path that doesn't go through this helper, `previousView` will be stale (`'home'`) on the next close, silently dropping the user's actual context. The guard is correct for the current callers; the risk is for future additions.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| // macOS menu accelerator and renderer hotkey both fire for one Cmd+, press; | ||
| // without this guard they'd toggle then untoggle on the same keystroke. | ||
| const DEDUP_WINDOW_MS = 150; | ||
|
|
||
| export function toggleSettingsView(navigate: NavigateFnTyped, currentView: string): void { | ||
| const now = Date.now(); | ||
| if (now - lastToggleAt < DEDUP_WINDOW_MS) return; | ||
| lastToggleAt = now; | ||
|
|
||
| if (currentView === 'settings') { | ||
| // Bare navigate(viewId) preserves stored params for views that statically require them. | ||
| (navigate as (viewId: ViewId) => void)(previousView); | ||
| return; | ||
| } | ||
|
|
||
| previousView = currentView as NonSettingsViewId; | ||
| navigate('settings'); | ||
| } | ||
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.
onOpenSettingsguard runs on the close path tooonOpenSettings?.()is now called even whencurrentView === 'settings'(i.e., the user is toggling settings off). InApp.tsx, the concrete implementation callssetView('workspace')as a side effect every time — including on close — and returnsfalse(blocking navigation) when the app is in onboarding. While those specific side effects are harmless today, the callback is semantically an "open" guard and was never designed to control the close path. The fix is to callonOpenSettingsonly when the intent is to open: checkcurrentView !== 'settings'before invoking the callback.Prompt To Fix With AI