Skip to content
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

[v1.0, chore, ui] close processes when window closes #584

Closed
wants to merge 5 commits into from
Closed
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: 1 addition & 1 deletion ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
chats,
setChats,
selectedChatId,
setSelectedChatId,

Check warning on line 46 in ui/desktop/src/ChatWindow.tsx

View workflow job for this annotation

GitHub Actions / build

'setSelectedChatId' is defined but never used. Allowed unused args must match /^_/u
initialQuery,
setProgressMessage,
setWorking,
Expand Down Expand Up @@ -124,7 +124,7 @@
c.id === selectedChatId ? { ...c, messages } : c
);
setChats(updatedChats);
}, [messages, selectedChatId]);

Check warning on line 127 in ui/desktop/src/ChatWindow.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has missing dependencies: 'chats' and 'setChats'. Either include them or remove the dependency array. If 'setChats' changes too often, find the parent component that defines it and wrap that definition in useCallback

const initialQueryAppended = useRef(false);
useEffect(() => {
Expand All @@ -132,7 +132,7 @@
append({ role: 'user', content: initialQuery });
initialQueryAppended.current = true;
}
}, [initialQuery]);

Check warning on line 135 in ui/desktop/src/ChatWindow.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has a missing dependency: 'append'. Either include it or remove the dependency array

useEffect(() => {
if (messages.length > 0) {
Expand Down Expand Up @@ -324,7 +324,7 @@
const addSystemConfig = async (system: string) => {
console.log("calling add system")
// Get the app instance from electron
const app = window.electron.app;

Check warning on line 327 in ui/desktop/src/ChatWindow.tsx

View workflow job for this annotation

GitHub Actions / build

'app' is assigned a value but never used. Allowed unused vars must match /^_/u

const systemConfig = {
type: "Stdio",
Expand Down Expand Up @@ -421,7 +421,7 @@

// Initialize system config when window loads
useEffect(() => {
addSystemConfig("developer2");
addSystemConfig("developer2");
}, []);

window.electron.logInfo('ChatWindow loaded');
Expand Down
14 changes: 6 additions & 8 deletions ui/desktop/src/goosed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { createServer } from 'net';
import os from 'node:os';
import { getBinaryPath } from './utils/binaryPath';
import log from './utils/logger';
import { ChildProcessByStdio } from 'node:child_process';
import { Readable } from 'node:stream';

// Find an available port to start goosed on
export const findAvailablePort = (): Promise<number> => {
Expand Down Expand Up @@ -58,7 +60,7 @@ const checkServerStatus = async (port: number, maxAttempts: number = 60, interva
return false;
};

export const startGoosed = async (app, dir=null, env={}): Promise<[number, string, string]> => {
export const startGoosed = async (app, dir=null, env={}): Promise<[number, string, ChildProcessByStdio<null, Readable, Readable>]> => {
// In will use this later to determine if we should start process
const isDev = process.env.NODE_ENV === 'development';

Expand All @@ -71,7 +73,7 @@ export const startGoosed = async (app, dir=null, env={}): Promise<[number, strin
// Skip starting goosed if configured in dev mode
if (isDev && !app.isPackaged && process.env.VITE_START_EMBEDDED_SERVER === 'no') {
log.info('Skipping starting goosed in development mode');
return [3000, dir, 'dev'];
return [3000, dir, null];
}

// Get the goosed binary path using the shared utility
Expand Down Expand Up @@ -130,17 +132,13 @@ export const startGoosed = async (app, dir=null, env={}): Promise<[number, strin
throw new Error(`Goosed server failed to start on port ${port}`);
}


// Ensure goosed is terminated when the app quits
// TODO will need to do it at tab level next
app.on('will-quit', () => {
log.info('App quitting, terminating goosed server');
goosedProcess.kill();
});

// Wait for the server to start and fetch the agent version
await new Promise(resolve => setTimeout(resolve, 1000)); // Give the server time to start
const agentVersion = await fetchAgentVersion(port);

log.info(`Goosed server successfully started on port ${port}`);
return [port, dir, agentVersion];
return [port, dir, goosedProcess];
};
10 changes: 7 additions & 3 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
if (checkApiCredentials()) {
return startGoosed(app, dir);
} else {
return [0, '', ''];
return [0, '', null];
}
}

const [port, working_dir, agentVersion] = await maybeStartGoosed();
const [port, working_dir, goosedProcess] = await maybeStartGoosed();

const mainWindow = new BrowserWindow({
titleBarStyle: 'hidden',
Expand All @@ -152,7 +152,6 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
...appConfig,
GOOSE_SERVER__PORT: port,
GOOSE_WORKING_DIR: working_dir,
GOOSE_AGENT_VERSION: agentVersion,
REQUEST_DIR: dir
})],
},
Expand Down Expand Up @@ -191,7 +190,11 @@ const createChat = async (app, query?: string, dir?: string, version?: string) =
windowMap.set(windowId, mainWindow);
mainWindow.on('closed', () => {
windowMap.delete(windowId);
if (goosedProcess) {
goosedProcess?.kill();
}
});

};

const createTray = () => {
Expand Down Expand Up @@ -249,6 +252,7 @@ const showWindow = () => {
});
};


const buildRecentFilesMenu = () => {
const recentDirs = loadRecentDirs();
return recentDirs.map(dir => ({
Expand Down
Loading