Skip to content

Commit

Permalink
chore: check for vscode-specific lockfile when launching
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jul 9, 2021
1 parent ec8bf1e commit feac649
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ui/configuration/chromiumDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { basename, join } from 'path';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { DebugType } from '../../common/contributionUtils';
import { isPortOpen } from '../../common/findOpenPort';
import { existsWithoutDeref } from '../../common/fsUtils';
import { some } from '../../common/promiseUtil';
import {
AnyChromiumConfiguration,
AnyChromiumLaunchConfiguration,
Expand Down Expand Up @@ -142,7 +144,7 @@ export abstract class ChromiumDebugConfigurationResolver<T extends AnyChromiumCo
}

// if there's a port configured and something's there, we can connect to it regardless
if (cast.port) {
if (cast.port && !(await isPortOpen(cast.port))) {
return config;
}

Expand All @@ -154,12 +156,17 @@ export abstract class ChromiumDebugConfigurationResolver<T extends AnyChromiumCo
cast.runtimeArgs?.includes('--headless') ? '.headless-profile' : '.profile',
);

const lockfile =
process.platform === 'win32'
? join(userDataDir, 'lockfile')
: join(userDataDir, 'SingletonLock');

if (await existsWithoutDeref(this.fs, lockfile)) {
// Warn if there's an existing instance, so we probably can't launch it in debug mode:
const platformLock = join(
userDataDir,
process.platform === 'win32' ? 'lockfile' : 'SingletonLock',
);
const lockfileExists = await some([
existsWithoutDeref(this.fs, platformLock),
existsWithoutDeref(this.fs, join(userDataDir, 'code.lock')),
]);

if (lockfileExists) {
const debugAnyway = localize('existingBrowser.debugAnyway', 'Debug Anyway');
const result = await vscode.window.showErrorMessage(
localize(
Expand All @@ -169,8 +176,8 @@ export abstract class ChromiumDebugConfigurationResolver<T extends AnyChromiumCo
? localize('existingBrowser.location.default', 'an old debug session')
: localize('existingBrowser.location.userDataDir', 'the configured userDataDir'),
),
{ modal: true },
debugAnyway,
localize('cancel', 'Cancel'),
);

if (result !== debugAnyway) {
Expand Down

0 comments on commit feac649

Please sign in to comment.