Skip to content

Commit

Permalink
Merge pull request #2328 from Chia-Network/checkpoint/main_from_relea…
Browse files Browse the repository at this point in the history
…se_2.3.0_1283cc784d1a1243d1cdbb97664daf97c8f954b5

checkpoint: into main from release/2.3.0  @ 1283cc7
  • Loading branch information
pmaslana authored May 1, 2024
2 parents 1a59459 + 2e6a6a0 commit da821b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/gui/src/electron/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import packageJson from '../../package.json';
import AppIcon from '../assets/img/chia64x64.png';
import About from '../components/about/About';
import { i18n } from '../config/locales';
import chiaEnvironment from '../util/chiaEnvironment';
import loadConfig from '../util/loadConfig';
import chiaEnvironment, { chiaInit } from '../util/chiaEnvironment';
import loadConfig, { checkConfigFileExists } from '../util/loadConfig';
import manageDaemonLifetime from '../util/manageDaemonLifetime';
import { setUserDataDir } from '../util/userData';

Expand Down Expand Up @@ -72,6 +72,12 @@ let mainWindow: BrowserWindow | null = null;
let currentDownloadRequest: any;
let abortDownloadingFiles: boolean = false;

// When there is no config file, it is assumed to be the first run.
// At that time, the config file is created here by `chia init`.
if (!checkConfigFileExists()) {
chiaInit();
}

// Set the userData directory to its location within CHIA_ROOT/gui
setUserDataDir();

Expand Down
26 changes: 26 additions & 0 deletions packages/gui/src/util/chiaEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ const getChiaVersion = () => {
return version;
};

const chiaInit = () => {
if (guessPackaged()) {
const executablePath = getExecutablePath(PY_DIST_EXECUTABLE);
console.info(`Executing: ${executablePath} init`);

try {
const output = childProcess.execFileSync(executablePath, ['init']);
console.info(output.toString());
} catch (e) {
console.error('Error: ');
console.error(e);
}
} else {
console.info(`Executing: ${PY_DEV_EXECUTABLE} init`);

try {
const output = childProcess.execFileSync(PY_DEV_EXECUTABLE, ['init']);
console.info(output.toString());
} catch (e) {
console.error('Error: ');
console.error(e);
}
}
};

const startChiaDaemon = () => {
pyProc = null;

Expand Down Expand Up @@ -142,6 +167,7 @@ const startChiaDaemon = () => {
};

module.exports = {
chiaInit,
startChiaDaemon,
getChiaVersion,
guessPackaged,
Expand Down
5 changes: 5 additions & 0 deletions packages/gui/src/util/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export function getConfigRootDir(net = 'mainnet'): string {
return 'CHIA_ROOT' in process.env ? untildify(process.env.CHIA_ROOT) : path.join(homedir, '.chia', net);
}

export function checkConfigFileExists(net?: string): boolean {
const configRootDir = getConfigRootDir(net);
return fs.existsSync(path.resolve(configRootDir, 'config/config.yaml'));
}

export function readConfigFile(net?: string): string {
const configRootDir = getConfigRootDir(net);

Expand Down

0 comments on commit da821b2

Please sign in to comment.