fix: keep tray session switches in sync
Open tray sessions from the correct directory Allow remote instances to update the tray Update the active project when switching sessions
This commit is contained in:
@@ -4004,6 +4004,7 @@ const COMMANDS_SAFE_FOR_REMOTE = new Set([
|
||||
'desktop_get_app_version',
|
||||
'desktop_get_lan_address',
|
||||
'desktop_capture_page_rect',
|
||||
'desktop_tray_update',
|
||||
]);
|
||||
|
||||
ipcMain.handle('openchamber:invoke', async (event, command, args) => {
|
||||
|
||||
@@ -180,13 +180,13 @@ export const createTrayController = ({ idleIconPath, unseenIconPath, breathIconP
|
||||
{ type: 'separator' },
|
||||
{ label: 'Deny', click: () => onAction({ type: 'respond-permission', sessionId: approval.sessionId, id: approval.id, response: 'reject' }) },
|
||||
{ type: 'separator' },
|
||||
{ label: 'Open in app', click: () => onAction({ type: 'focus-session', sessionId: approval.sessionId }) },
|
||||
{ label: 'Open in app', click: () => onAction({ type: 'focus-session', sessionId: approval.sessionId, directory: approval.directory || '' }) },
|
||||
],
|
||||
};
|
||||
}
|
||||
return {
|
||||
label: approvalLabel(approval),
|
||||
click: () => onAction({ type: 'focus-session', sessionId: approval.sessionId }),
|
||||
click: () => onAction({ type: 'focus-session', sessionId: approval.sessionId, directory: approval.directory || '' }),
|
||||
};
|
||||
};
|
||||
for (const approval of approvals.slice(0, MAX_APPROVALS)) {
|
||||
@@ -209,7 +209,7 @@ export const createTrayController = ({ idleIconPath, unseenIconPath, breathIconP
|
||||
icon: statusIcons[statusIconKey(session)] || statusIcons.blank,
|
||||
// Secondary smaller line (macOS): project · branch.
|
||||
...(session.subtitle ? { sublabel: truncate(session.subtitle, 48) } : {}),
|
||||
click: () => onAction({ type: 'focus-session', sessionId: session.id }),
|
||||
click: () => onAction({ type: 'focus-session', sessionId: session.id, directory: session.directory || '' }),
|
||||
});
|
||||
|
||||
if (sessions.length > 0) {
|
||||
|
||||
@@ -442,6 +442,14 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
)
|
||||
const fallbackDir = opencodeClient.getDirectory() ?? directoryState.currentDirectory ?? null
|
||||
const resolvedDir = (directoryHint ? normalizePath(directoryHint) : null) ?? sessionDir ?? fallbackDir
|
||||
const projectsState = useProjectsStore.getState()
|
||||
const sessionProject = resolvedDir
|
||||
? resolveProjectForSessionDirectory(
|
||||
projectsState.projects,
|
||||
get().availableWorktreesByProject,
|
||||
resolvedDir,
|
||||
)
|
||||
: null
|
||||
|
||||
// Set the directory together with the session id so chat hooks read the
|
||||
// same child store that send/SSE events will update during startup races.
|
||||
@@ -452,6 +460,9 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
if (resolvedDir && directoryState.currentDirectory !== resolvedDir) {
|
||||
directoryState.setDirectory(resolvedDir, { showOverlay: false })
|
||||
}
|
||||
if (sessionProject && projectsState.activeProjectId !== sessionProject.id) {
|
||||
projectsState.setActiveProjectIdOnly(sessionProject.id)
|
||||
}
|
||||
opencodeClient.setDirectory(resolvedDir ?? undefined)
|
||||
} catch (e) {
|
||||
console.warn("Failed to set OpenCode directory for session switch:", e)
|
||||
|
||||
Reference in New Issue
Block a user