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

Fixed installation path issue #2277

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function PlotOverviewPlots() {
<Folder fontSize="small" color="info" />
</ListItemIcon>
<Typography variant="inherit" noWrap>
{isLoading || directories.length === 0 ? (
{isLoading || !directories || directories.length === 0 ? (
<Trans>Add Plot Directory</Trans>
) : (
<Trans>Manage Plot Directories</Trans>
Expand Down
65 changes: 57 additions & 8 deletions packages/gui/src/util/chiaEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,61 @@ const getChiaVersion = () => {
return version;
};

const spawnChildProcess = (command, args = [], options = undefined) => {
// As of Feb 11 2024, there is a bug in Electron that prevents electron from exiting when a child process is spawned and detached.
// This is a workaround for that bug.
if (process.platform === 'linux') {
// https://github.com/electron/electron/issues/34808#issuecomment-1275530924
return childProcess.spawn(
'/bin/bash',
[
'-c',
'for fd in $(ls /proc/$$/fd); do case "$fd" in 0|1|2|255) ;; *) eval "exec $fd<&-" ;; esac; done; exec "$@"',
'--',
command,
...args,
],
options
);
}
return childProcess.spawn(command, args, options);
};

const startChiaDaemon = () => {
const script = getScriptPath(PY_DIST_FILE);
let script = getScriptPath(PY_DIST_FILE);
const processOptions = {};
// processOptions.detached = true;
// processOptions.stdio = "ignore";
if (process.platform === 'win32') {
// We want to detach child daemon process from parent GUI process.
// You may think `detached: true` will do but it shows blank terminal on Windows.
// In order to hide the blank terminal while detaching child process,
// {detached: false, windowsHide: false, shell: true} works which is exact opposite of what we expect
// Please see the comment below for more details.
// https://github.com/nodejs/node/issues/21825#issuecomment-503766781
processOptions.detached = false;
processOptions.stdio = 'ignore';
processOptions.windowsHide = false;
processOptions.shell = true;
} else {
processOptions.detached = true;
processOptions.stdio = 'ignore';
processOptions.windowsHide = true;
}
pyProc = null;
if (guessPackaged()) {
// On Windows, we need to double-quote the script path to handle paths with spaces
if (process.platform === 'win32') {
script = `"${script}"`;
}

try {
console.info('Running python executable: ');
const Process = childProcess.spawn;
pyProc = new Process(script, ['--wait-for-unlock'], processOptions);
if (processOptions.stdio === 'ignore') {
const subProcess = spawnChildProcess(script, ['--wait-for-unlock'], processOptions);
subProcess.unref();
} else {
const Process = childProcess.spawn;
pyProc = new Process(script, ['--wait-for-unlock'], processOptions);
}
} catch (e) {
console.info('Running python executable: Error: ');
console.info(`Script ${script}`);
Expand All @@ -86,10 +130,15 @@ const startChiaDaemon = () => {
console.info('Running python script');
console.info(`Script ${script}`);

const Process = childProcess.spawn;
pyProc = new Process('python', [script, '--wait-for-unlock'], processOptions);
if (processOptions.stdio === 'ignore') {
const subProcess = spawnChildProcess('python', [script, '--wait-for-unlock'], processOptions);
subProcess.unref();
} else {
const Process = childProcess.spawn;
pyProc = new Process('python', [script, '--wait-for-unlock'], processOptions);
}
}
if (pyProc != null) {
if (pyProc != null && processOptions.stdio !== 'ignore') {
pyProc.stdout.setEncoding('utf8');

pyProc.stdout.on('data', (data) => {
Expand Down
Loading