Skip to content

Commit

Permalink
attempt to fix windows ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvadratni committed Feb 4, 2025
1 parent 63d432f commit 2140135
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ui/desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "goose-app",
"productName": "Goose",
"version": "1.0.4",
"version": "1.0.4b",
"description": "Goose App",
"main": ".vite/build/main.js",
"scripts": {
Expand Down
34 changes: 28 additions & 6 deletions ui/desktop/src/goosed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawn } from 'child_process';
import { createServer } from 'net';
import os from 'node:os';
import path from 'node:path';
import { getBinaryPath } from './utils/binaryPath';
import log from './utils/logger';
import { ChildProcessByStdio } from 'node:child_process';
Expand Down Expand Up @@ -56,9 +57,13 @@ export const startGoosed = async (
): Promise<[number, string, ChildProcessByStdio<null, Readable, Readable>]> => {
// we default to running goosed in home dir - if not specified
const homeDir = os.homedir();
const isWindows = process.platform === 'win32';

// Ensure dir is properly normalized for the platform
if (!dir) {
dir = homeDir;
}
dir = path.normalize(dir);

// Get the goosed binary path using the shared utility
let goosedPath = getBinaryPath(app, 'goosed');
Expand All @@ -72,34 +77,48 @@ export const startGoosed = async (
HOME: homeDir,
// Set USERPROFILE for Windows
USERPROFILE: homeDir,

// Set APPDATA for Windows
APPDATA: process.env.APPDATA || path.join(homeDir, 'AppData', 'Roaming'),
// Set LOCAL_APPDATA for Windows
LOCALAPPDATA: process.env.LOCALAPPDATA || path.join(homeDir, 'AppData', 'Local'),
// Set PATH to include the binary directory
PATH: `${path.dirname(goosedPath)}${path.delimiter}${process.env.PATH}`,
// start with the port specified
GOOSE_PORT: String(port),

GOOSE_SERVER__SECRET_KEY: process.env.GOOSE_SERVER__SECRET_KEY,

// Add any additional environment variables passed in
...env,
};

// Merge parent environment with additional environment variables
const processEnv = { ...process.env, ...additionalEnv };

// Configure spawn options with Windows-specific settings
const isWindows = process.platform === 'win32';

// Add detailed logging for troubleshooting
log.info(`Process platform: ${process.platform}`);
log.info(`Process cwd: ${process.cwd()}`);
log.info(`Target working directory: ${dir}`);
log.info(`Environment HOME: ${processEnv.HOME}`);
log.info(`Environment USERPROFILE: ${processEnv.USERPROFILE}`);
log.info(`Environment APPDATA: ${processEnv.APPDATA}`);
log.info(`Environment LOCALAPPDATA: ${processEnv.LOCALAPPDATA}`);
log.info(`Environment PATH: ${processEnv.PATH}`);

// Ensure proper executable path on Windows
if (isWindows && !goosedPath.toLowerCase().endsWith('.exe')) {
goosedPath += '.exe';
}
log.info(`Binary path resolved to: ${goosedPath}`);

// Verify binary exists
try {
const fs = require('fs');
const stats = fs.statSync(goosedPath);
log.info(`Binary exists: ${stats.isFile()}`);
} catch (error) {
log.error(`Binary not found at ${goosedPath}:`, error);
throw new Error(`Binary not found at ${goosedPath}`);
}

const spawnOptions = {
cwd: dir,
env: processEnv,
Expand All @@ -112,6 +131,9 @@ export const startGoosed = async (
shell: false,
};

// Log spawn options for debugging
log.info('Spawn options:', JSON.stringify(spawnOptions, null, 2));

// Spawn the goosed process
const goosedProcess = spawn(goosedPath, ['agent'], spawnOptions);

Expand Down
2 changes: 1 addition & 1 deletion ui/desktop/src/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
import { HashRouter as Router } from 'react-router-dom';
import App from './App';

// Error Boundary Component
Expand Down
40 changes: 36 additions & 4 deletions ui/desktop/src/utils/binaryPath.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
import path from 'node:path';
import fs from 'node:fs';
import Electron from 'electron';
import log from './logger';

export const getBinaryPath = (app: Electron.App, binaryName: string): string => {
const isDev = process.env.NODE_ENV === 'development';
const isPackaged = app.isPackaged;
const isWindows = process.platform === 'win32';
const executableName = isWindows ? `${binaryName}.exe` : binaryName;

// List of possible paths to check
const possiblePaths = [];

if (isDev && !isPackaged) {
// In development, use the absolute path from the project root
return path.join(process.cwd(), 'src', 'bin', executableName);
// In development, check multiple possible locations
possiblePaths.push(
path.join(process.cwd(), 'src', 'bin', executableName),
path.join(process.cwd(), 'bin', executableName),
path.join(process.cwd(), '..', '..', 'target', 'release', executableName)
);
} else {
// In production, always use resources/bin path for consistency
return path.join(process.resourcesPath, 'bin', executableName);
// In production, check resources paths
possiblePaths.push(
path.join(process.resourcesPath, 'bin', executableName),
path.join(app.getAppPath(), 'resources', 'bin', executableName)
);
}

// Log all paths we're checking
log.info('Checking binary paths:', possiblePaths);

// Try each path and return the first one that exists
for (const binPath of possiblePaths) {
try {
if (fs.existsSync(binPath)) {
log.info(`Found binary at: ${binPath}`);
return binPath;
}
} catch (error) {
log.error(`Error checking path ${binPath}:`, error);
}
}

// If we get here, we couldn't find the binary
const error = `Could not find ${binaryName} binary in any of the expected locations: ${possiblePaths.join(', ')}`;
log.error(error);
throw new Error(error);
};

0 comments on commit 2140135

Please sign in to comment.