提交 4252e67b 编写于 作者: B Benjamin Pasero

fix one part of #60192

上级 1ac04b53
......@@ -49,6 +49,7 @@ import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { CommandLineDialogService } from 'vs/platform/dialogs/node/dialogService';
import { ILabelService, LabelService } from 'vs/platform/label/common/label';
import { createWaitMarkerFile } from 'vs/code/node/wait';
function createServices(args: ParsedArgs, bufferLogService: BufferLogService): IInstantiationService {
const services = new ServiceCollection();
......@@ -293,23 +294,7 @@ function quit(accessor: ServicesAccessor, reason?: ExpectedError | Error): void
lifecycleService.kill(exitCode);
}
function main() {
// Set the error handler early enough so that we are not getting the
// default electron error dialog popping up
setUnexpectedErrorHandler(err => console.error(err));
let args: ParsedArgs;
try {
args = parseMainProcessArgv(process.argv);
args = validatePaths(args);
} catch (err) {
console.error(err.message);
app.exit(1);
return void 0;
}
function startup(args: ParsedArgs): void {
// We need to buffer the spdlog logs until we are sure
// we are the only instance running, otherwise we'll have concurrent
// log file access on Windows
......@@ -317,7 +302,7 @@ function main() {
const bufferLogService = new BufferLogService();
const instantiationService = createServices(args, bufferLogService);
return instantiationService.invokeFunction(accessor => {
instantiationService.invokeFunction(accessor => {
// Patch `process.env` with the instance's environment
const environmentService = accessor.get(IEnvironmentService);
......@@ -343,4 +328,46 @@ function main() {
}).then(null, err => instantiationService.invokeFunction(quit, err));
}
function main(): void {
// Set the error handler early enough so that we are not getting the
// default electron error dialog popping up
setUnexpectedErrorHandler(err => console.error(err));
// Parse arguments
let args: ParsedArgs;
try {
args = parseMainProcessArgv(process.argv);
args = validatePaths(args);
} catch (err) {
console.error(err.message);
app.exit(1);
return void 0;
}
// If we are started with --wait create a random temporary file
// and pass it over to the starting instance. We can use this file
// to wait for it to be deleted to monitor that the edited file
// is closed and then exit the waiting process.
//
// Note: we are not doing this if the wait marker has been already
// added as argument. This can happen if Code was started from CLI.
if (args.wait && !args.waitMarkerFilePath) {
createWaitMarkerFile(args.verbose).then(waitMarkerFilePath => {
if (waitMarkerFilePath) {
process.argv.push('--waitMarkerFilePath', waitMarkerFilePath);
args.waitMarkerFilePath = waitMarkerFilePath;
}
startup(args);
});
}
// Otherwise just startup normally
else {
startup(args);
}
}
main();
......@@ -20,6 +20,7 @@ import * as iconv from 'iconv-lite';
import { writeFileAndFlushSync } from 'vs/base/node/extfs';
import { isWindows } from 'vs/base/common/platform';
import { ProfilingSession } from 'v8-inspect-profiler';
import { createWaitMarkerFile } from 'vs/code/node/wait';
function shouldSpawnCliProcess(argv: ParsedArgs): boolean {
return !!argv['install-source']
......@@ -228,22 +229,9 @@ export async function main(argv: string[]): Promise<any> {
// is closed and then exit the waiting process.
let waitMarkerFilePath: string;
if (args.wait) {
let waitMarkerError: Error;
const randomTmpFile = paths.join(os.tmpdir(), Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10));
try {
fs.writeFileSync(randomTmpFile, '');
waitMarkerFilePath = randomTmpFile;
waitMarkerFilePath = await createWaitMarkerFile(verbose);
if (waitMarkerFilePath) {
argv.push('--waitMarkerFilePath', waitMarkerFilePath);
} catch (error) {
waitMarkerError = error;
}
if (verbose) {
if (waitMarkerError) {
console.error(`Failed to create marker file for --wait: ${waitMarkerError.toString()}`);
} else {
console.log(`Marker file for --wait created: ${waitMarkerFilePath}`);
}
}
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { join } from 'path';
import { tmpdir } from 'os';
import { writeFile } from 'vs/base/node/pfs';
export function createWaitMarkerFile(verbose?: boolean): Promise<string> {
const randomWaitMarkerPath = join(tmpdir(), Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10));
return writeFile(randomWaitMarkerPath, '').then(() => {
if (verbose) {
console.log(`Marker file for --wait created: ${randomWaitMarkerPath}`);
}
return randomWaitMarkerPath;
}, error => {
if (verbose) {
console.error(`Failed to create marker file for --wait: ${error}`);
}
return Promise.resolve(void 0);
});
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册