Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (process.defaultApp) {
// macOS: Handle deep link when app is already running
app.on("open-url", (event, url) => {
event.preventDefault();
console.log("Deep link URL (open-url):", url);
deepLinkManager.setUrl(url);
});

Expand All @@ -44,7 +43,6 @@ app.on("open-url", (event, url) => {
// Initialize port selection before app starts
// This ensures we get a consistent available port for this workspace
const port = await getPort();
console.log(`Using dev server port: ${port}`);

await app.whenReady();

Expand Down
34 changes: 10 additions & 24 deletions apps/desktop/src/main/lib/port-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ interface DetectedPort {
detectedAt: string;
}

export interface PortDetectedEvent extends DetectedPort {
worktreeId: string;
}

export interface PortClosedEvent {
terminalId: string;
worktreeId: string;
port: number;
}

interface MonitoredTerminal {
terminalId: string;
worktreeId: string;
Expand Down Expand Up @@ -71,10 +81,6 @@ export class PortDetector extends EventEmitter {
this.pollTerminalPorts(terminalId).catch((error) => {
console.error(`Error in initial port check for ${terminalId}:`, error);
});

console.log(
`[PortDetector] Started monitoring terminal ${terminalId} for worktree ${worktreeId}`,
);
}

/**
Expand All @@ -101,8 +107,6 @@ export class PortDetector extends EventEmitter {

// Update cache
this.updateWorktreePortsCache(monitored.worktreeId);

console.log(`[PortDetector] Stopped monitoring terminal ${terminalId}`);
}

/**
Expand Down Expand Up @@ -147,10 +151,6 @@ export class PortDetector extends EventEmitter {
...detectedPort,
worktreeId: monitored.worktreeId,
});

console.log(
`[PortDetector] Detected port ${port}${service ? ` (${service})` : ""} in terminal ${terminalId}`,
);
}

// Emit events for closed ports
Expand All @@ -160,10 +160,6 @@ export class PortDetector extends EventEmitter {
worktreeId: monitored.worktreeId,
port,
});

console.log(
`[PortDetector] Port ${port} closed in terminal ${terminalId}`,
);
}
}

Expand Down Expand Up @@ -244,7 +240,6 @@ export class PortDetector extends EventEmitter {
*/
private detectServiceName(cwd?: string): string | undefined {
if (!cwd) {
console.log("[PortDetector] No CWD provided for service detection");
return undefined;
}

Expand Down Expand Up @@ -318,10 +313,6 @@ export class PortDetector extends EventEmitter {
*/
getDetectedPortsMap(worktreeId: string): Record<string, number> {
const ports = this.getDetectedPorts(worktreeId);
console.log(
`[PortDetector] getDetectedPortsMap for worktree ${worktreeId}: found ${ports.length} ports`,
ports,
);

const map: Record<string, number> = {};

Expand All @@ -336,14 +327,10 @@ export class PortDetector extends EventEmitter {
const portKey = detected.port.toString();
if (!map[portKey]) {
map[portKey] = detected.port;
console.log(
`[PortDetector] Added unnamed port ${detected.port} with key "${portKey}"`,
);
}
}
}

console.log(`[PortDetector] Returning map:`, map);
return map;
}

Expand All @@ -362,7 +349,6 @@ export class PortDetector extends EventEmitter {
this.stopMonitoring(terminalId);
}
this.worktreePortsCache.clear();
console.log("[PortDetector] Cleaned up all monitoring");
}
}

Expand Down
7 changes: 0 additions & 7 deletions apps/desktop/src/main/lib/port-ipcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export function registerPortIpcs(): void {
// Reinitialize proxy manager with new configuration
await proxyManager.initialize(workspace);
proxyManager.updateTargets(workspace);

console.log(
`[PortIpcs] Updated ports configuration for workspace ${workspace.name}`,
);

return {
success: true,
};
Expand All @@ -64,6 +59,4 @@ export function registerPortIpcs(): void {
ipcMain.handle("proxy-get-status", async () => {
return proxyManager.getStatus();
});

console.log("[PortIpcs] Registered port-related IPC handlers");
}
42 changes: 0 additions & 42 deletions apps/desktop/src/main/lib/proxy-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export class ProxyManager extends EventEmitter {
*/
async initialize(workspace: Workspace): Promise<void> {
if (!workspace.ports || workspace.ports.length === 0) {
console.log(
"[ProxyManager] No ports configured for workspace, skipping initialization",
);
return;
}

Expand All @@ -60,9 +57,6 @@ export class ProxyManager extends EventEmitter {
}

this.initialized = true;
console.log(
`[ProxyManager] Initialized ${this.proxies.size} proxy servers for workspace ${workspace.name}`,
);
}

/**
Expand Down Expand Up @@ -130,9 +124,6 @@ export class ProxyManager extends EventEmitter {
// Start listening
await new Promise<void>((resolve, reject) => {
server.listen(canonical, "127.0.0.1", () => {
console.log(
`[ProxyManager] Proxy listening on http://localhost:${canonical}${service ? ` (${service})` : ""}`,
);
resolve();
});

Expand Down Expand Up @@ -167,9 +158,6 @@ export class ProxyManager extends EventEmitter {
*/
updateTargets(workspace: Workspace): void {
if (!this.initialized || !workspace.ports) {
console.log(
`[ProxyManager] Cannot update targets - initialized: ${this.initialized}, has ports: ${!!workspace.ports}`,
);
return;
}

Expand All @@ -178,60 +166,35 @@ export class ProxyManager extends EventEmitter {
);

if (!activeWorktree) {
console.log("[ProxyManager] No active worktree, clearing all targets");
this.clearAllTargets();
return;
}

const detectedPorts = activeWorktree.detectedPorts || {};

console.log(
`[ProxyManager] Updating targets for active worktree ${activeWorktree.branch} (${workspace.activeWorktreeId})`,
);
console.log(`[ProxyManager] Detected ports:`, detectedPorts);

// Update each proxy
for (const [canonical, instance] of this.proxies) {
let targetPort: number | undefined;

if (instance.service) {
// Named port: match by service name
targetPort = detectedPorts[instance.service];
console.log(
`[ProxyManager] Looking for service "${instance.service}" in detectedPorts:`,
detectedPorts,
);
} else {
// Unnamed port: use first available detected port
// Filter out entries that are port numbers used as keys (e.g., "3000" → 3000)
const availablePorts = Object.values(detectedPorts);
if (availablePorts.length > 0) {
targetPort = availablePorts[0];
console.log(
`[ProxyManager] No service specified, using first detected port: ${targetPort}`,
);
} else {
console.log(
`[ProxyManager] No service specified and no detected ports available`,
);
}
}

if (targetPort) {
const target = `http://localhost:${targetPort}`;
instance.target = target;
instance.active = true;

console.log(
`[ProxyManager] Port ${canonical}${instance.service ? ` (${instance.service})` : ""} → ${targetPort}`,
);
} else {
instance.target = undefined;
instance.active = false;

console.log(
`[ProxyManager] Port ${canonical}${instance.service ? ` (${instance.service})` : ""} → no backend`,
);
}
}

Expand Down Expand Up @@ -274,9 +237,6 @@ export class ProxyManager extends EventEmitter {
for (const instance of this.proxies.values()) {
const promise = new Promise<void>((resolve) => {
instance.server.close(() => {
console.log(
`[ProxyManager] Stopped proxy on port ${instance.canonical}`,
);
resolve();
});
});
Expand All @@ -290,8 +250,6 @@ export class ProxyManager extends EventEmitter {

this.proxies.clear();
this.initialized = false;

console.log("[ProxyManager] All proxies stopped");
}

/**
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/src/main/lib/terminal-ipcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export function registerTerminalIPCs(window: BrowserWindowType) {

// Clean up when this window closes
const cleanup = () => {
console.log("[Terminal IPC] Cleaning up window terminal registrations");
tmuxManager.unregisterWindow(window);
};

Expand Down
1 change: 0 additions & 1 deletion apps/desktop/src/main/lib/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class TerminalManager {

// Handle terminal exit
ptyProcess.onExit(({ exitCode }) => {
console.log(`Terminal ${id} exited with code ${exitCode}`);
// Notify renderer that terminal has exited (only if window still exists)
if (
this.mainWindow &&
Expand Down
6 changes: 0 additions & 6 deletions apps/desktop/src/main/lib/workspace/group-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export function removeEmptyGroupTabs(
// Remove this empty group
tabs.splice(i, 1);
removedAny = true;
console.log(
`Removed empty group tab: ${[...parentPath, tab.name].join(" > ")}`,
);
} else if (tab.type === "group" && tab.tabs) {
// Recursively check child tabs
const childRemoved = removeEmptyGroupTabs(tab.tabs, [
Expand All @@ -43,9 +40,6 @@ export function removeEmptyGroupTabs(
if (isEmptyGroup(tab)) {
tabs.splice(i, 1);
removedAny = true;
console.log(
`Removed newly-empty group tab: ${[...parentPath, tab.name].join(" > ")}`,
);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/main/lib/workspace/workspace-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";

import type {
CreateWorkspaceInput,
Tab,
UpdateWorkspaceInput,
Workspace,
} from "shared/types";
Expand Down Expand Up @@ -282,8 +283,8 @@ function startMonitoringWorktree(
/**
* Recursively find all terminal tabs
*/
function findTerminalTabs(tabs: any[]): any[] {
const terminals: any[] = [];
function findTerminalTabs(tabs: Tab[]): Tab[] {
const terminals: Tab[] = [];

for (const tab of tabs) {
if (tab.type === "terminal") {
Expand Down
24 changes: 9 additions & 15 deletions apps/desktop/src/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { screen } from "electron";
import { createWindow } from "lib/electron-app/factories/windows/create";
import { displayName } from "~/package.json";
import { createApplicationMenu } from "../lib/menu";
import { portDetector } from "../lib/port-detector";
import {
type PortClosedEvent,
type PortDetectedEvent,
portDetector,
} from "../lib/port-detector";
import { registerTerminalIPCs } from "../lib/terminal-ipcs";
import {
getActiveWorkspaceId,
Expand Down Expand Up @@ -40,11 +44,8 @@ export async function MainWindow() {
const cleanupTerminal = registerTerminalIPCs(window);

// Set up port detection listeners
portDetector.on("port-detected", async (event: any) => {
const { worktreeId, port, service } = event;
console.log(
`[Main] Port detected: ${port}${service ? ` (${service})` : ""} in worktree ${worktreeId}`,
);
portDetector.on("port-detected", async (event: PortDetectedEvent) => {
const { worktreeId } = event;

// Get detected ports map for this worktree
const detectedPorts = portDetector.getDetectedPortsMap(worktreeId);
Expand All @@ -60,18 +61,14 @@ export async function MainWindow() {
// Update proxy if this is the active worktree
if (workspace.activeWorktreeId === worktreeId) {
await workspaceManager.updateProxyTargets(workspace.id);
console.log(
`[Main] Updated proxy targets for active worktree ${worktree.branch}`,
);
}
break;
}
}
});

portDetector.on("port-closed", async (event: any) => {
const { worktreeId, port } = event;
console.log(`[Main] Port closed: ${port} in worktree ${worktreeId}`);
portDetector.on("port-closed", async (event: PortClosedEvent) => {
const { worktreeId } = event;

// Get updated detected ports map
const detectedPorts = portDetector.getDetectedPortsMap(worktreeId);
Expand Down Expand Up @@ -106,9 +103,6 @@ export async function MainWindow() {
const activeWorkspace = await workspaceManager.get(activeWorkspaceId);

if (activeWorkspace?.ports && activeWorkspace.ports.length > 0) {
console.log(
`[Main] Initializing proxy for workspace: ${activeWorkspace.name}`,
);
await workspaceManager.initializeProxyForWorkspace(activeWorkspaceId);
}
}
Expand Down
Loading
Loading