Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src-electron/ipc/node-child-process-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ import ChildProcess from 'child_process';
export function hookChildProcessIpc(browserWindow: BrowserWindow) {
ipcMain.on("node:child_process:execSync", (event, path) => {
event.returnValue = ChildProcess.execSync(path).toString();
})
});

ipcMain.on("node:child_process:spawnSync", (event, path, args, options) => {
event.returnValue = ChildProcess.spawnSync(path, args, options).stdout;
})
});

ipcMain.handle("node:child_process:exec", (event, path, options) => {
return new Promise(resolve => {
ChildProcess.exec(path, options, err => {
resolve(err);
});
})
})
});
});

ipcMain.handle("node:child_process:spawn", (event, path, args, options) => {
return new Promise((resolve, reject) => {
try {
ChildProcess.spawn(path, args, options)
resolve(undefined);
} catch (e) {
reject(JSON.stringify(e));
}
});
});


}
6 changes: 5 additions & 1 deletion src-electron/preload/node-child-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export function exec(path: string, options: any) {
}

export function spawnSync(path: string, args: string[], options: object) {
return ipcRenderer.sendSync('node:child_process:spawnSync', path, options);
return ipcRenderer.sendSync('node:child_process:spawnSync', path, args, options);
}

export function spawn(path: string, args: string[], options: object) {
return ipcRenderer.invoke('node:child_process:spawn', path, args, options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const NodeChildProcessImplementation: NodeChildProcessProvider = {
});
},
spawnSync: (path, args, options) => window.node.child_process.spawnSync(path, args, options),
spawn: async (path, args, options) => window.node.child_process.spawn(path, args, options),
}
2 changes: 2 additions & 0 deletions src/providers/node/child_process/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type NodeChildProcessProvider = {
execSync: (path: string, options?: any) => string;
exec: (path: string, options?: any, callback?: (err: Error) => void) => Promise<void>;
spawnSync: (path: string, args?: string[], options?: object) => string;
spawn: (path: string, args?: string[], options?: object) => Promise<any>;
}

let implementation: () => NodeChildProcessProvider;
Expand All @@ -23,6 +24,7 @@ const childProcess: NodeChildProcessProvider = {
execSync: path => getImplementation().execSync(path),
exec: (path, options, callback) => getImplementation().exec(path, options, callback),
spawnSync: (path, args, options) => getImplementation().spawnSync(path, args, options),
spawn: (path, args, options) => getImplementation().spawn(path, args, options),
};

export default childProcess;
28 changes: 16 additions & 12 deletions src/r2mm/launching/runners/multiplatform/DirectGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import GameDirectoryResolverProvider from '../../../../providers/ror2/game/GameD
import FsProvider from '../../../../providers/generic/file/FsProvider';
import LoggerProvider, { LogSeverity } from '../../../../providers/ror2/logging/LoggerProvider';
import ChildProcess from '../../../../providers/node/child_process/child_process';
import { parse as parseShell } from "shell-quote";

export default class DirectGameRunner extends GameRunnerProvider {

Expand Down Expand Up @@ -45,20 +46,23 @@ export default class DirectGameRunner extends GameRunnerProvider {

const mappedArgs = args.map(value => `"${value}"`).join(' ');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes below leaves this row unused.


LoggerProvider.instance.Log(LogSeverity.INFO, `Running command: ${gameDir}/${gameExecutable} ${mappedArgs} ${settings.getContext().gameSpecific.launchParameters}`);
const allArgs = [
...args,
...parseShell(settings.getContext().gameSpecific.launchParameters)
];

const childProcess = ChildProcess.exec(`"${gameExecutable}" ${mappedArgs} ${settings.getContext().gameSpecific.launchParameters}`, {
LoggerProvider.instance.Log(LogSeverity.INFO, `Running command: ${gameDir}/${gameExecutable} ${allArgs.join(" ")}`);

ChildProcess.spawn(`"${gameExecutable}"`, allArgs, {
cwd: gameDir,
windowsHide: false,
}, (err => {
if (err !== null) {
LoggerProvider.instance.Log(LogSeverity.ACTION_STOPPED, 'Error was thrown whilst starting modded');
LoggerProvider.instance.Log(LogSeverity.ERROR, err.message);
const r2err = new R2Error('Error starting the game', err.message, 'Ensure that the game folder has been set correctly in the settings');
return reject(r2err);
}
return resolve();
}));
shell: true,
detached: true,
}).catch(reason => {
LoggerProvider.instance.Log(LogSeverity.ACTION_STOPPED, 'Error was thrown whilst starting modded');
LoggerProvider.instance.Log(LogSeverity.ERROR, reason);
const r2err = new R2Error('Error starting the game', reason, 'Ensure that the game folder has been set correctly in the settings');
return reject(r2err);
});
});
}
}
Loading