Skip to content

Commit

Permalink
refactor: alternative approach
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Nov 30, 2023
1 parent 9d38a23 commit c670573
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions packages/api/core/src/api/start.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn, SpawnOptions } from 'child_process';
import { EventEmitter } from 'events';

import { getElectronVersion, listrCompatibleRebuildHook } from '@electron-forge/core-utils';
import { ElectronProcess, ForgeArch, ForgeListrTaskFn, ForgePlatform, ResolvedForgeConfig, StartOptions } from '@electron-forge/shared-types';
Expand All @@ -24,6 +25,8 @@ type StartContext = {
spawned: ElectronProcess;
};

const restartAppEventEmitter = new EventEmitter();

export default autoTrace(
{ name: 'start()', category: '@electron-forge/core' },
async (
Expand Down Expand Up @@ -213,20 +216,20 @@ export default autoTrace(
};

if (interactive) {
process.on('FORGE_RESTART_APP', async () => {
restartAppEventEmitter.on('restart', async () => {
if (lastSpawned) {
console.info(chalk.cyan('\nRestarting App\n'));
lastSpawned.restarted = true;
lastSpawned.kill('SIGTERM');
lastSpawned.emit('restarted', await forgeSpawnWrapper());
}
});
console.info(chalk.cyan('\nRestarting App\n'));
lastSpawned.restarted = true;
lastSpawned.kill('SIGTERM');
lastSpawned.emit('restarted', await forgeSpawnWrapper());
}
});

process.stdin.on('data', async (data) => {
if (data.toString().trim() === 'rs') {
process.emit('FORGE_RESTART_APP');
}
});
process.stdin.on('data', async (data) => {
if (data.toString().trim() === 'rs') {
restartApp();
}
});

process.stdin.resume();
}
Expand All @@ -238,3 +241,7 @@ export default autoTrace(
return spawned;
}
);

export function restartApp() {
restartAppEventEmitter.emit('restart');
}

0 comments on commit c670573

Please sign in to comment.