-
Notifications
You must be signed in to change notification settings - Fork 990
feat(desktop): allow opening additional windows from tray #1953
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
e33bde2
7068e1d
46cfc22
9ef4f1b
46e0033
c41833c
5b70038
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,99 @@ | ||||||||||||||||||||||||||||||||||||
| import { appState } from "."; | ||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||
| defaultAppState, | ||||||||||||||||||||||||||||||||||||
| type TabsState, | ||||||||||||||||||||||||||||||||||||
| type WindowTabsState, | ||||||||||||||||||||||||||||||||||||
| } from "./schemas"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| function getWindowKey(windowId: number | null | undefined): string | null { | ||||||||||||||||||||||||||||||||||||
| return windowId === null || windowId === undefined ? null : String(windowId); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| function toWindowTabsState( | ||||||||||||||||||||||||||||||||||||
| state: Partial<TabsState> | undefined, | ||||||||||||||||||||||||||||||||||||
| ): WindowTabsState { | ||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||
| activeTabIds: state?.activeTabIds ?? {}, | ||||||||||||||||||||||||||||||||||||
| focusedPaneIds: state?.focusedPaneIds ?? {}, | ||||||||||||||||||||||||||||||||||||
| tabHistoryStacks: state?.tabHistoryStacks ?? {}, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export function getTabsStateForWindow( | ||||||||||||||||||||||||||||||||||||
| windowId: number | null | undefined, | ||||||||||||||||||||||||||||||||||||
| ): TabsState { | ||||||||||||||||||||||||||||||||||||
| const sharedState = appState.data.tabsState ?? defaultAppState.tabsState; | ||||||||||||||||||||||||||||||||||||
| const key = getWindowKey(windowId); | ||||||||||||||||||||||||||||||||||||
| const windowState = | ||||||||||||||||||||||||||||||||||||
| (key ? appState.data.tabsStateByWindow[key] : undefined) ?? | ||||||||||||||||||||||||||||||||||||
| toWindowTabsState(sharedState); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+29
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. Guard On Line 28, 💡 Proposed fix export function getTabsStateForWindow(
windowId: number | null | undefined,
): TabsState {
const sharedState = appState.data.tabsState ?? defaultAppState.tabsState;
const key = getWindowKey(windowId);
+ const byWindow = appState.data.tabsStateByWindow ?? {};
const windowState =
- (key ? appState.data.tabsStateByWindow[key] : undefined) ??
+ (key ? byWindow[key] : undefined) ??
toWindowTabsState(sharedState);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||
| tabs: sharedState.tabs, | ||||||||||||||||||||||||||||||||||||
| panes: sharedState.panes, | ||||||||||||||||||||||||||||||||||||
| activeTabIds: windowState.activeTabIds, | ||||||||||||||||||||||||||||||||||||
| focusedPaneIds: windowState.focusedPaneIds, | ||||||||||||||||||||||||||||||||||||
| tabHistoryStacks: windowState.tabHistoryStacks, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| function getMergedWindowTabsState(): WindowTabsState { | ||||||||||||||||||||||||||||||||||||
| const merged = toWindowTabsState(appState.data.tabsState); | ||||||||||||||||||||||||||||||||||||
| const byWindow = appState.data.tabsStateByWindow; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| for (const state of Object.values(byWindow ?? {})) { | ||||||||||||||||||||||||||||||||||||
| const windowState = toWindowTabsState(state); | ||||||||||||||||||||||||||||||||||||
| Object.assign(merged.activeTabIds, windowState.activeTabIds); | ||||||||||||||||||||||||||||||||||||
| Object.assign(merged.focusedPaneIds, windowState.focusedPaneIds); | ||||||||||||||||||||||||||||||||||||
| Object.assign(merged.tabHistoryStacks, windowState.tabHistoryStacks); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return merged; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export function setTabsStateForWindow( | ||||||||||||||||||||||||||||||||||||
| windowId: number | null | undefined, | ||||||||||||||||||||||||||||||||||||
| tabsState: TabsState, | ||||||||||||||||||||||||||||||||||||
| ): void { | ||||||||||||||||||||||||||||||||||||
| const windowState: WindowTabsState = { | ||||||||||||||||||||||||||||||||||||
| activeTabIds: tabsState.activeTabIds, | ||||||||||||||||||||||||||||||||||||
| focusedPaneIds: tabsState.focusedPaneIds, | ||||||||||||||||||||||||||||||||||||
| tabHistoryStacks: tabsState.tabHistoryStacks, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const key = getWindowKey(windowId); | ||||||||||||||||||||||||||||||||||||
| if (key) { | ||||||||||||||||||||||||||||||||||||
| appState.data.tabsStateByWindow = { | ||||||||||||||||||||||||||||||||||||
| ...appState.data.tabsStateByWindow, | ||||||||||||||||||||||||||||||||||||
| [key]: windowState, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Shared across windows: tab/pane topology. | ||||||||||||||||||||||||||||||||||||
| // Legacy fallback keeps the latest caller's view state. | ||||||||||||||||||||||||||||||||||||
| appState.data.tabsState = { | ||||||||||||||||||||||||||||||||||||
| tabs: tabsState.tabs, | ||||||||||||||||||||||||||||||||||||
| panes: tabsState.panes, | ||||||||||||||||||||||||||||||||||||
| activeTabIds: windowState.activeTabIds, | ||||||||||||||||||||||||||||||||||||
| focusedPaneIds: windowState.focusedPaneIds, | ||||||||||||||||||||||||||||||||||||
| tabHistoryStacks: windowState.tabHistoryStacks, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export function getMergedTabsState(): TabsState { | ||||||||||||||||||||||||||||||||||||
| const sharedState = appState.data.tabsState ?? defaultAppState.tabsState; | ||||||||||||||||||||||||||||||||||||
| const mergedWindowState = getMergedWindowTabsState(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||
| tabs: sharedState.tabs, | ||||||||||||||||||||||||||||||||||||
| panes: sharedState.panes, | ||||||||||||||||||||||||||||||||||||
| activeTabIds: mergedWindowState.activeTabIds, | ||||||||||||||||||||||||||||||||||||
| focusedPaneIds: mergedWindowState.focusedPaneIds, | ||||||||||||||||||||||||||||||||||||
| tabHistoryStacks: mergedWindowState.tabHistoryStacks, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export function resetTabsState(): void { | ||||||||||||||||||||||||||||||||||||
| appState.data.tabsState = defaultAppState.tabsState; | ||||||||||||||||||||||||||||||||||||
| appState.data.tabsStateByWindow = {}; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+96
to
+98
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. Avoid assigning Line 97 reuses the same object instance from defaults; later in-place mutations can corrupt the canonical default object. 💡 Proposed fix export function resetTabsState(): void {
- appState.data.tabsState = defaultAppState.tabsState;
+ appState.data.tabsState = {
+ tabs: [...defaultAppState.tabsState.tabs],
+ panes: { ...defaultAppState.tabsState.panes },
+ activeTabIds: { ...defaultAppState.tabsState.activeTabIds },
+ focusedPaneIds: { ...defaultAppState.tabsState.focusedPaneIds },
+ tabHistoryStacks: { ...defaultAppState.tabsState.tabHistoryStacks },
+ };
appState.data.tabsStateByWindow = {};
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
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.
toWindowTabsStatecurrently aliases maps, causing merge-time mutation side effects.Lines 16-18 return original map references. Then Lines 46-48 mutate those objects via
Object.assign, which can unintentionally mutate shared persisted state during read/merge.💡 Proposed fix
function toWindowTabsState( state: Partial<TabsState> | undefined, ): WindowTabsState { return { - activeTabIds: state?.activeTabIds ?? {}, - focusedPaneIds: state?.focusedPaneIds ?? {}, - tabHistoryStacks: state?.tabHistoryStacks ?? {}, + activeTabIds: { ...(state?.activeTabIds ?? {}) }, + focusedPaneIds: { ...(state?.focusedPaneIds ?? {}) }, + tabHistoryStacks: { ...(state?.tabHistoryStacks ?? {}) }, }; }Also applies to: 40-49
🤖 Prompt for AI Agents