Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ export const createInstallAppAsync = ({
path,
sendToAllWindows,
}: InstallAppAsyncDependencies) => {
const fs = require('node:fs');
const os = require('node:os');

const cleanupTmpPath = async (tmpPath: string | null) => {
if (!tmpPath) return;

await fs.promises.rm(tmpPath, {
force: true,
recursive: true,
});
};

const assertEngineInstalled = (engine: string) => {
if (getEngineAppPath(engine, app.getPath('home'))) return;

Expand Down Expand Up @@ -99,6 +111,7 @@ export const createInstallAppAsync = ({
opts,
requireAdmin,
url,
tmpPath,
}: {
cacheRoot: string;
engine: string;
Expand All @@ -109,6 +122,7 @@ export const createInstallAppAsync = ({
opts: Record<string, unknown>;
requireAdmin: boolean;
url: string | null;
tmpPath: string;
}) => {
const params = [
'--engine',
Expand Down Expand Up @@ -142,6 +156,9 @@ export const createInstallAppAsync = ({
params.push(url);
}

params.push('--tmpPath');
params.push(tmpPath);

return params;
};

Expand Down Expand Up @@ -183,6 +200,8 @@ export const createInstallAppAsync = ({
return;
}

const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(), 'chromeless-'));

const child = fork(
path.join(__dirname, 'install-app-forked-lite.js').replace('app.asar', 'app.asar.unpacked'),
buildForkParams({
Expand All @@ -195,6 +214,7 @@ export const createInstallAppAsync = ({
opts,
requireAdmin,
url,
tmpPath,
}),
{
env: {
Expand All @@ -205,11 +225,19 @@ export const createInstallAppAsync = ({
},
);

child.on('exit', () => {
void cleanupTmpPath(tmpPath).catch(() => undefined);
});

if (signal) {
if (signal.aborted) {
void cleanupTmpPath(tmpPath).catch(() => undefined);
child.kill();
} else {
const handleAbort = () => child.kill();
const handleAbort = () => {
void cleanupTmpPath(tmpPath).catch(() => undefined);
child.kill();
};
signal.addEventListener('abort', handleAbort, { once: true });
child.on('exit', () => signal.removeEventListener('abort', handleAbort));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ const argv = parseArgs([
'username',
'cacheRoot',
'browserPath',
'tmpPath',
]);
const { engine, id, name, url, icon, helperPath, homePath, installationPath, username } = argv;
const {
engine,
id,
name,
url,
icon,
helperPath,
homePath,
installationPath,
tmpPath: providedTmpPath,
username,
} = argv;
const opts = parseInstallOpts(argv.opts);
const runtime = buildInstallRuntime({
engine,
Expand Down Expand Up @@ -99,7 +111,7 @@ const sudoAsync = (prompt) =>

const getAppFolderName = () => `${name}.app`;

const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(), 'chromeless-'));
const tmpPath = providedTmpPath ?? fs.mkdtempSync(path.join(os.tmpdir(), 'chromeless-'));
tmpPathCleaner.setTmpPath(tmpPath);
const appFolderPath = path.join(tmpPath, getAppFolderName());
// Mock Electron for backward compatibility
Expand Down