Skip to content

feat: add run from ASAR button #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 37 additions & 3 deletions src/renderer/components/commands-runner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';

import { Button, ButtonProps, Spinner } from '@blueprintjs/core';
import { Button, ButtonGroup, ButtonProps, Spinner } from '@blueprintjs/core';
import { Popover2 } from '@blueprintjs/popover2';
import { observer } from 'mobx-react';

import { InstallState, VersionSource } from '../../interfaces';
Expand All @@ -16,6 +17,30 @@ interface RunnerProps {
*/
export const Runner = observer(
class Runner extends React.Component<RunnerProps> {
private renderAsarButton = (disabled: boolean) => {
const asarButton = (
<Button
text="Run from ASAR"
icon="play"
disabled={disabled}
small
onClick={() => {
window.app.runner.run({ runFromAsar: true });
}}
/>
);

return (
<Popover2 fill={true} content={asarButton} placement="bottom">
<Button
icon="caret-down"
style={{ minWidth: 20 }}
disabled={disabled}
/>
</Popover2>
);
};

public render() {
const { downloaded, downloading, missing, installing, installed } =
InstallState;
Expand Down Expand Up @@ -59,7 +84,9 @@ export const Runner = observer(
props.icon = <Spinner size={16} />;
} else {
props.text = 'Run';
props.onClick = window.app.runner.run;
props.onClick = () => {
window.app.runner.run({ runFromAsar: false });
};
props.icon = 'play';
}
break;
Expand All @@ -76,8 +103,15 @@ export const Runner = observer(
props.icon = <Spinner size={16} />;
}
}
const isAsarDisabled: boolean =
props.disabled || isRunning || isInstallingModules;

return <Button id="button-run" {...props} type={undefined} />;
return (
<ButtonGroup>
<Button id="button-run" {...props} type={undefined} />
{this.renderAsarButton(isAsarDisabled)}
</ButtonGroup>
);
}
},
);
2 changes: 2 additions & 0 deletions src/renderer/components/commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const Commands = observer(
</ControlGroup>
<ControlGroup fill={true} vertical={false}>
<VersionChooser appState={appState} />
</ControlGroup>
<ControlGroup fill={true} vertical={false}>
<Runner appState={appState} />
</ControlGroup>
{isBisectCommandShowing && (
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ export enum ForgeCommands {
MAKE = 'make',
}

interface runOptions {
runFromAsar: boolean;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
interface runOptions {
runFromAsar: boolean;
}
export interface RunOptions {
runFromAsar?: boolean;
}

Should start with a capital letter to match existing style, and should be exported since it's part of the public API for this file. Since these are options, runFromAsar should be optional as more options may be added in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, missed the capital letter there, thanks for catching that!
Exported it and made runFromAsar optional.


interface RunFiddleParams {
localPath: string | undefined;
isValidBuild: boolean; // If the localPath is a valid Electron build
version: string; // The user selected version
dir: string;
runFromAsar: boolean;
}

const resultString: Record<RunResult, string> = Object.freeze({
Expand Down Expand Up @@ -139,8 +144,9 @@ export class Runner {
/**
* Actually run the fiddle.
*/
public async run(): Promise<RunResult> {
public async run(runOptions?: runOptions): Promise<RunResult> {
const options = { includeDependencies: false, includeElectron: false };
const runFromAsar = runOptions?.runFromAsar ?? false;

const { appState } = this;
const currentRunnable = appState.currentElectronVersion;
Expand Down Expand Up @@ -220,6 +226,7 @@ export class Runner {
isValidBuild,
dir,
version,
runFromAsar,
});
}

Expand Down Expand Up @@ -362,12 +369,15 @@ export class Runner {
* or the user selected electron version
*/
private async runFiddle(params: RunFiddleParams): Promise<RunResult> {
const { version, dir } = params;
const { version, dir, runFromAsar } = params;
const { pushOutput, flushOutput, executionFlags } = this.appState;
const env = this.buildChildEnvVars();

// Add user-specified cli flags if any have been set.
const options = [dir, '--inspect'].concat(executionFlags);
if (runFromAsar) {
options.push('runFromAsar');
}
Copy link
Member

Choose a reason for hiding this comment

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

This should be added to StartFiddleParams, and then it will be handled automatically by the ...params in the call to window.ElectronFiddle.startFiddle below. This will also require changes in src/main/fiddle-core.ts to plumb it into the call to runner.spawn.


const cleanup = async () => {
flushOutput();
Expand Down
Loading