Skip to content

Commit

Permalink
feat: Add app message improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Oct 26, 2023
1 parent 75a42e2 commit aba5c4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/back/GameLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ export namespace GameLauncher {

export async function launchAdditionalApplication(opts: LaunchAddAppOpts, child: boolean, serverOverride?: string): Promise<void> {
await checkAndInstallPlatform(opts.addApp.parentGame.platforms, opts.state, opts.openDialog);
// @FIXTHIS It is not possible to open dialog windows from the back process (all electron APIs are undefined).
switch (opts.addApp.applicationPath) {
case ':message:':
return new Promise((resolve) => {
opts.openDialog({
largeMessage: true,
message: opts.addApp.launchCommand,
buttons: ['Ok'],
}).finally(() => resolve());
case ':message:': {
const dialogId = await opts.openDialog({
largeMessage: true,
message: opts.addApp.launchCommand,
buttons: opts.addApp.waitForExit ? ['Ok', 'Cancel'] : ['Ok'],
});
const result = (await awaitDialog(opts.state, dialogId)).buttonIdx;
if (result !== 0) {
throw 'User aborted game launch (denied message box)';
}
return;
}
case ':extras:': {
const folderPath = fixSlashes(path.join(opts.fpPath, path.posix.join('Extras', opts.addApp.launchCommand)));
return opts.openExternal(folderPath, { activate: true })
Expand Down Expand Up @@ -118,10 +121,14 @@ export namespace GameLauncher {
logProcessOutput(proc);
log.info(logSource, `Launch Add-App "${opts.addApp.name}" (PID: ${proc.pid}) [ path: "${opts.addApp.applicationPath}", arg: "${opts.addApp.launchCommand}" ]`);
return new Promise((resolve, reject) => {
if (proc.killed) { resolve(); }
else {
proc.once('exit', () => { resolve(); });
proc.once('error', error => { reject(error); });
if (opts.addApp.waitForExit) {
resolve();
} else {
if (proc.killed) { resolve(); }
else {
proc.once('exit', () => { resolve(); });
proc.once('error', error => { reject(error); });
}
}
});
}
Expand Down Expand Up @@ -168,8 +175,7 @@ export namespace GameLauncher {
for (const addApp of opts.game.addApps) {
if (addApp.autoRunBefore) {
addApp.parentGame = opts.game;
const promise = launchAdditionalApplication({ ...addAppOpts, addApp }, curation);
if (addApp.waitForExit) { await promise; }
await launchAdditionalApplication({ ...addAppOpts, addApp }, curation);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,9 @@ export class App extends React.Component<AppProps> {
gameId
});
await window.Shared.back.request(BackIn.LAUNCH_GAME, gameId)
.catch((error) => {
log.error('Launcher', `Failed to launch game - ${gameId} - ERROR: ${error}`);
})
.finally(() => {
this.props.dispatchMain({
type: MainActionType.UNBUSY_GAME,
Expand Down

0 comments on commit aba5c4f

Please sign in to comment.