-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |