feat: goose windows (#880)

Co-authored-by: Ryan Versaw <ryan@versaw.com>
This commit is contained in:
Max Novich
2025-02-10 15:05:13 -08:00
committed by GitHub
parent 98aecbef23
commit cfd3ee8fd9
43 changed files with 1327 additions and 456 deletions

View File

@@ -1,24 +1,55 @@
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';
// On Windows, use .cmd for npx and .exe for uvx
const executableName = isWindows
? binaryName === 'npx'
? 'npx.cmd'
: `${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',
process.platform === 'win32' ? `${binaryName}.exe` : binaryName
// 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, use the path relative to the app resources
return path.join(
process.resourcesPath,
'bin',
process.platform === 'win32' ? `${binaryName}.exe` : binaryName
// 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);
};