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 6acb75a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 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');
}
7 changes: 0 additions & 7 deletions typings/nodejs/index.d.ts

This file was deleted.

0 comments on commit 6acb75a

Please sign in to comment.