Skip to content

Commit 08e1dfd

Browse files
fix: shell pane detection and welcome screen logic
- Fix shell pane detection where untracked panes were not being added to the tracking list (untrackedPanes.push was not being called) - Check for actual tmux panes at startup before showing welcome screen - Destroy welcome pane when other panes exist (terminal or worktree)
1 parent 3f835d2 commit 08e1dfd

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { createWelcomePane, destroyWelcomePane } from './utils/welcomePane.js';
2020
import { TMUX_COLORS } from './theme/colors.js';
2121
import { SIDEBAR_WIDTH } from './utils/layoutManager.js';
2222
import { validateSystemRequirements, printValidationResults } from './utils/systemCheck.js';
23+
import { getUntrackedPanes } from './utils/shellPaneDetection.js';
2324

2425
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2526
const require = createRequire(import.meta.url);
@@ -247,7 +248,19 @@ class Dmux {
247248
}
248249
}
249250

250-
if (controlPaneId && config.panes && config.panes.length === 0) {
251+
// Check for untracked panes (terminal panes created outside dmux tracking)
252+
const trackedPaneIds = config.panes?.map((p: any) => p.paneId) ?? [];
253+
const untrackedPanes = await getUntrackedPanes(
254+
this.sessionName,
255+
trackedPaneIds,
256+
controlPaneId,
257+
config.welcomePaneId
258+
);
259+
260+
// Only show welcome pane if there are no tracked AND no untracked panes
261+
const hasAnyPanes = (config.panes?.length ?? 0) > 0 || untrackedPanes.length > 0;
262+
263+
if (controlPaneId && !hasAnyPanes) {
251264
if (!hasValidWelcomePane) {
252265
// Create new welcome pane
253266
const welcomePaneId = await createWelcomePane(controlPaneId);
@@ -269,6 +282,13 @@ class Dmux {
269282
execSync(`tmux select-layout main-vertical`, { stdio: 'pipe' });
270283
await tmuxService.refreshClient();
271284
}
285+
} else if (hasValidWelcomePane && hasAnyPanes) {
286+
// If welcome pane exists but there are other panes, destroy it
287+
LogService.getInstance().info('Destroying welcome pane because other panes exist', 'Setup');
288+
await destroyWelcomePane(config.welcomePaneId);
289+
config.welcomePaneId = undefined;
290+
config.lastUpdated = new Date().toISOString();
291+
await fs.writeFile(this.panesFile, JSON.stringify(config, null, 2));
272292
}
273293
} catch (error) {
274294
// Ignore errors in sidebar setup - will work without it

src/utils/shellPaneDetection.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,47 +119,36 @@ export async function getUntrackedPanes(
119119

120120
// CRITICAL: Skip internal dmux panes by title
121121
if (title === 'dmux-spacer') {
122-
// // LogService.getInstance().debug(`Excluding spacer pane: ${paneId}`, 'shellDetection');
123-
// continue;
124-
// }
125-
// if (title && title.startsWith('dmux v')) {
126-
// // LogService.getInstance().debug(`Excluding control pane by title: ${paneId} (${title})`, 'shellDetection');
122+
continue;
123+
}
124+
if (title && title.startsWith('dmux v')) {
127125
continue;
128126
}
129127
if (title === 'Welcome') {
130-
// // LogService.getInstance().debug(`Excluding welcome pane: ${paneId}`, 'shellDetection');
131-
// continue;
132-
// }
133-
//
134-
// // CRITICAL: Skip control and welcome panes by ID (most reliable method)
135-
// if (controlPaneId && paneId === controlPaneId) {
136-
// // LogService.getInstance().debug(`Excluding control pane by ID: ${paneId}`, 'shellDetection');
128+
continue;
129+
}
130+
131+
// CRITICAL: Skip control and welcome panes by ID (most reliable method)
132+
if (controlPaneId && paneId === controlPaneId) {
137133
continue;
138134
}
139135
if (welcomePaneId && paneId === welcomePaneId) {
140-
// // LogService.getInstance().debug(`Excluding welcome pane by ID: ${paneId}`, 'shellDetection');
141-
// continue;
142-
// }
143-
//
144-
// // CRITICAL: Skip panes running dmux itself (node process running dmux)
145-
// if (command && (command === 'node' || command.includes('dmux'))) {
146-
// // LogService.getInstance().debug(`Excluding dmux process pane: ${paneId} (command: ${command})`, 'shellDetection');
136+
continue;
137+
}
138+
139+
// CRITICAL: Skip panes running dmux itself (node process running dmux)
140+
if (command && (command === 'node' || command.includes('dmux'))) {
147141
continue;
148142
}
149143

150144
// Skip already tracked panes
151145
if (trackedPaneIds.includes(paneId)) continue;
152146

153-
// // LogService.getInstance().debug(`Found untracked pane: ${paneId} (title: ${title}, command: ${command})`, 'shellDetection');
154-
// untrackedPanes.push({ paneId, title: title || '', command: command || '' });
147+
untrackedPanes.push({ paneId, title: title || '', command: command || '' });
155148
}
156149

157150
return untrackedPanes;
158151
} catch (error) {
159-
// LogService.getInstance().debug(
160-
// 'Failed to get untracked panes',
161-
// 'shellDetection'
162-
// );
163152
return [];
164153
}
165154
}

0 commit comments

Comments
 (0)