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 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@blueprintjs/core": "^3.36.0",
"@blueprintjs/popover2": "^0.12.2",
"@blueprintjs/select": "^3.15.0",
"@electron/fiddle-core": "^1.3.3",
"@electron/fiddle-core": "^1.4.0",
"@octokit/rest": "^17.0.0",
"@sentry/electron": "^5.11.0",
"algoliasearch": "^4.12.0",
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export interface StartFiddleParams {
dir: string;
options: string[];
env: { [x: string]: string | undefined };
runFromAsar?: boolean;
}

export interface DownloadVersionParams {
Expand Down
3 changes: 2 additions & 1 deletion src/main/fiddle-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function startFiddle(
localPath,
options,
version,
runFromAsar,
} = params;
const env = { ...process.env };

Expand All @@ -53,7 +54,7 @@ export async function startFiddle(
const child = await runner.spawn(
isValidBuild && localPath ? Installer.getExecPath(localPath) : version,
dir,
{ args: options, cwd: dir, env },
{ args: options, cwd: dir, env, runFromAsar },
);
fiddleProcesses.set(webContents, child);

Expand Down
44 changes: 41 additions & 3 deletions src/renderer/components/commands-runner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import * as React from 'react';

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

import { InstallState, VersionSource } from '../../interfaces';
Expand Down Expand Up @@ -59,7 +67,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 +86,36 @@ 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} />
<AsarButton disabled={isAsarDisabled} />
</ButtonGroup>
);
}
},
);

const AsarButton = ({ disabled }: { disabled: boolean }): JSX.Element => {
const asarButton = (
<Menu>
<MenuItem
text="Run from ASAR"
icon="play"
active={!disabled}
onClick={() => {
window.app.runner.run({ runFromAsar: true });
}}
/>
</Menu>
);

return (
<Popover2 fill={true} content={asarButton} placement="bottom">
<Button icon="caret-down" style={{ minWidth: 20 }} disabled={disabled} />
</Popover2>
);
};
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
9 changes: 8 additions & 1 deletion 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',
}

export interface RunOptions {
runFromAsar?: boolean;
}

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
Original file line number Diff line number Diff line change
@@ -1,85 +1,120 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Runner component renders InstallState.downloading 1`] = `
<Blueprint3.Button
disabled={true}
icon={
<Blueprint3.Spinner
size={16}
value={50}
/>
}
id="button-run"
text="Downloading"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
disabled={true}
icon={
<Blueprint3.Spinner
size={16}
value={50}
/>
}
id="button-run"
text="Downloading"
/>
<AsarButton
disabled={true}
/>
</Blueprint3.ButtonGroup>
`;

exports[`Runner component renders InstallState.installed 1`] = `
<Blueprint3.Button
disabled={false}
icon="play"
id="button-run"
onClick={[MockFunction]}
text="Run"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
disabled={false}
icon="play"
id="button-run"
onClick={[Function]}
text="Run"
/>
<AsarButton
disabled={false}
/>
</Blueprint3.ButtonGroup>
`;

exports[`Runner component renders InstallState.installing 1`] = `
<Blueprint3.Button
disabled={true}
icon={
<Blueprint3.Spinner
size={16}
/>
}
id="button-run"
text="Unzipping"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
disabled={true}
icon={
<Blueprint3.Spinner
size={16}
/>
}
id="button-run"
text="Unzipping"
/>
<AsarButton
disabled={true}
/>
</Blueprint3.ButtonGroup>
`;

exports[`Runner component renders InstallState.missing 1`] = `
<Blueprint3.Button
disabled={true}
icon={
<Blueprint3.Spinner
size={16}
/>
}
id="button-run"
text="Checking status"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
disabled={true}
icon={
<Blueprint3.Spinner
size={16}
/>
}
id="button-run"
text="Checking status"
/>
<AsarButton
disabled={true}
/>
</Blueprint3.ButtonGroup>
`;

exports[`Runner component renders idle 1`] = `
<Blueprint3.Button
disabled={false}
icon="play"
id="button-run"
onClick={[MockFunction]}
text="Run"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
disabled={false}
icon="play"
id="button-run"
onClick={[Function]}
text="Run"
/>
<AsarButton
disabled={false}
/>
</Blueprint3.ButtonGroup>
`;

exports[`Runner component renders installing modules 1`] = `
<Blueprint3.Button
disabled={false}
icon={
<Blueprint3.Spinner
size={16}
/>
}
id="button-run"
text="Installing modules"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
disabled={false}
icon={
<Blueprint3.Spinner
size={16}
/>
}
id="button-run"
text="Installing modules"
/>
<AsarButton
disabled={true}
/>
</Blueprint3.ButtonGroup>
`;

exports[`Runner component renders running 1`] = `
<Blueprint3.Button
active={true}
disabled={false}
icon="stop"
id="button-run"
onClick={[MockFunction]}
text="Stop"
/>
<Blueprint3.ButtonGroup>
<Blueprint3.Button
active={true}
disabled={false}
icon="stop"
id="button-run"
onClick={[MockFunction]}
text="Stop"
/>
<AsarButton
disabled={true}
/>
</Blueprint3.ButtonGroup>
`;
10 changes: 10 additions & 0 deletions tests/renderer/components/__snapshots__/commands-spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ exports[`Commands component renders when system is darwin 1`] = `
<version-chooser
appState={"default StateMock"}
/>
</Blueprint3.ControlGroup>
<Blueprint3.ControlGroup
fill={true}
vertical={false}
>
<runner
appState={"default StateMock"}
/>
Expand Down Expand Up @@ -77,6 +82,11 @@ exports[`Commands component renders when system not is darwin 1`] = `
<version-chooser
appState={"default StateMock"}
/>
</Blueprint3.ControlGroup>
<Blueprint3.ControlGroup
fill={true}
vertical={false}
>
<runner
appState={"default StateMock"}
/>
Expand Down
18 changes: 14 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1089,11 +1089,21 @@
glob "^7.1.6"
minimatch "^3.0.4"

"@electron/fiddle-core@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@electron/fiddle-core/-/fiddle-core-1.3.3.tgz#adb54cd4cb3c63726c945c028808e39baa562747"
integrity sha512-aBUN+jsNsLo+Ywfl0wQy2TRRGC8TvLF42Lt9zOdrzGgT7vzDNiFvr7+UiRVvC5inGR0XgeTmZpwaS6CnT6ZPWA==
"@electron/asar@^3.3.1":
version "3.4.1"
resolved "https://registry.yarnpkg.com/@electron/asar/-/asar-3.4.1.tgz#4e9196a4b54fba18c56cd8d5cac67c5bdc588065"
integrity sha512-i4/rNPRS84t0vSRa2HorerGRXWyF4vThfHesw0dmcWHp+cspK743UanA0suA5Q5y8kzY2y6YKrvbIUn69BCAiA==
dependencies:
commander "^5.0.0"
glob "^7.1.6"
minimatch "^3.0.4"

"@electron/fiddle-core@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@electron/fiddle-core/-/fiddle-core-1.4.0.tgz#b19840053a1a8e2e6cba45db3bd80b296b90fb88"
integrity sha512-dPoLYJJ5HtvnWG8p29JorKn6mlX4JOsQb6eGKT41Q48SqAm96WXkarHCGDA4PQWj5qJq1R75aBHtH78pLjX46A==
dependencies:
"@electron/asar" "^3.3.1"
"@electron/get" "^2.0.0"
debug "^4.3.3"
env-paths "^2.2.1"
Expand Down