Revert "Electron v2.0.0 (#47289)"

This reverts commit f7ec491c3e.
This commit is contained in:
Benjamin Pasero 2018-04-20 16:05:52 +02:00
parent 1aa0bb83bc
commit 6cb06b7cb5
17 changed files with 3757 additions and 7351 deletions

View file

@ -1,3 +1,3 @@
disturl "https://atom.io/download/electron"
target "2.0.0-beta.7"
target "1.7.12"
runtime "electron"

View file

@ -29,7 +29,7 @@ set ELECTRON_ENABLE_LOGGING=1
set ELECTRON_ENABLE_STACK_DUMPING=1
:: Launch Code
%CODE% --inspect=5874 out\cli.js . %*
%CODE% --debug=5874 out\cli.js . %*
popd
endlocal

View file

@ -32,7 +32,7 @@ function code() {
VSCODE_DEV=1 \
ELECTRON_ENABLE_LOGGING=1 \
ELECTRON_ENABLE_STACK_DUMPING=1 \
"$CODE" --inspect=5874 "$ROOT/out/cli.js" . "$@"
"$CODE" --debug=5874 "$ROOT/out/cli.js" . "$@"
}
code "$@"

View file

@ -3,10 +3,6 @@
if [[ "$OSTYPE" == "darwin"* ]]; then
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
ROOT=$(dirname "$(dirname "$(realpath "$0")")")
# On Linux with Electron 2.0.x running out of a VM causes
# a freeze so we only enable this flag on macOS
export ELECTRON_ENABLE_LOGGING=1
else
ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
fi
@ -44,6 +40,7 @@ function code() {
export NODE_ENV=development
export VSCODE_DEV=1
export VSCODE_CLI=1
export ELECTRON_ENABLE_LOGGING=1
export ELECTRON_ENABLE_STACK_DUMPING=1
# Launch Code

View file

@ -4,10 +4,6 @@
if [[ "$OSTYPE" == "darwin"* ]]; then
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
ROOT=$(dirname $(dirname $(realpath "$0")))
# On Linux with Electron 2.0.x running out of a VM causes
# a freeze so we only enable this flag on macOS
export ELECTRON_ENABLE_LOGGING=1
else
ROOT=$(dirname $(dirname $(readlink -f $0)))
fi
@ -29,6 +25,7 @@ test -d node_modules || yarn
node build/lib/electron.js || ./node_modules/.bin/gulp electron
# Unit Tests
export ELECTRON_ENABLE_LOGGING=1
if [[ "$OSTYPE" == "darwin"* ]]; then
cd $ROOT ; ulimit -n 4096 ; \
"$CODE" \

File diff suppressed because it is too large Load diff

9570
src/typings/node.d.ts vendored

File diff suppressed because it is too large Load diff

View file

@ -146,7 +146,7 @@ function showContextMenu(e) {
})
);
menu.popup({ window: remote.getCurrentWindow() });
menu.popup(remote.getCurrentWindow());
}
}

View file

@ -61,8 +61,6 @@ import { LogLevelSetterChannel } from 'vs/platform/log/common/logIpc';
import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { ElectronURLListener } from 'vs/platform/url/electron-main/electronUrlListener';
import { serve as serveDriver } from 'vs/platform/driver/electron-main/driver';
import { join } from 'path';
import { copy, exists, rename } from 'vs/base/node/pfs';
export class CodeApplication {
@ -264,55 +262,49 @@ export class CodeApplication {
this.logService.debug(`from: ${this.environmentService.appRoot}`);
this.logService.debug('args:', this.environmentService.args);
// Handle local storage (TODO@Ben remove me after a while)
this.logService.trace('Handling localStorage if needed...');
return this.handleLocalStorage().then(() => {
// Make sure we associate the program with the app user model id
// This will help Windows to associate the running program with
// any shortcut that is pinned to the taskbar and prevent showing
// two icons in the taskbar for the same app.
if (platform.isWindows && product.win32AppUserModelId) {
app.setAppUserModelId(product.win32AppUserModelId);
}
// Make sure we associate the program with the app user model id
// This will help Windows to associate the running program with
// any shortcut that is pinned to the taskbar and prevent showing
// two icons in the taskbar for the same app.
if (platform.isWindows && product.win32AppUserModelId) {
app.setAppUserModelId(product.win32AppUserModelId);
// Create Electron IPC Server
this.electronIpcServer = new ElectronIPCServer();
// Resolve unique machine ID
this.logService.trace('Resolving machine identifier...');
return this.resolveMachineId().then(machineId => {
this.logService.trace(`Resolved machine identifier: ${machineId}`);
// Spawn shared process
this.sharedProcess = new SharedProcess(this.environmentService, this.lifecycleService, this.logService, machineId, this.userEnv);
this.sharedProcessClient = this.sharedProcess.whenReady().then(() => connect(this.environmentService.sharedIPCHandle, 'main'));
// Services
const appInstantiationService = this.initServices(machineId);
let promise: TPromise<any> = TPromise.as(null);
// Create driver
if (this.environmentService.driverHandle) {
serveDriver(this.electronIpcServer, this.environmentService.driverHandle, appInstantiationService).then(server => {
this.logService.info('Driver started at:', this.environmentService.driverHandle);
this.toDispose.push(server);
});
}
// Create Electron IPC Server
this.electronIpcServer = new ElectronIPCServer();
return promise.then(() => {
// Setup Auth Handler
const authHandler = appInstantiationService.createInstance(ProxyAuthHandler);
this.toDispose.push(authHandler);
// Resolve unique machine ID
this.logService.trace('Resolving machine identifier...');
return this.resolveMachineId().then(machineId => {
this.logService.trace(`Resolved machine identifier: ${machineId}`);
// Open Windows
appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor));
// Spawn shared process
this.sharedProcess = new SharedProcess(this.environmentService, this.lifecycleService, this.logService, machineId, this.userEnv);
this.sharedProcessClient = this.sharedProcess.whenReady().then(() => connect(this.environmentService.sharedIPCHandle, 'main'));
// Services
const appInstantiationService = this.initServices(machineId);
let promise: TPromise<any> = TPromise.as(null);
// Create driver
if (this.environmentService.driverHandle) {
serveDriver(this.electronIpcServer, this.environmentService.driverHandle, appInstantiationService).then(server => {
this.logService.info('Driver started at:', this.environmentService.driverHandle);
this.toDispose.push(server);
});
}
return promise.then(() => {
// Setup Auth Handler
const authHandler = appInstantiationService.createInstance(ProxyAuthHandler);
this.toDispose.push(authHandler);
// Open Windows
appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor));
// Post Open Windows Tasks
appInstantiationService.invokeFunction(accessor => this.afterWindowOpen(accessor));
});
// Post Open Windows Tasks
appInstantiationService.invokeFunction(accessor => this.afterWindowOpen(accessor));
});
});
}
@ -332,36 +324,6 @@ export class CodeApplication {
});
}
private handleLocalStorage(): TPromise<void> {
const localStorageFile = join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage');
const localStorageJournalFile = join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage-journal');
const localStorageBackupFile = join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage.vscbak');
const localStorageJournalBackupFile = join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage-journal.vscbak');
// Electron 1.7.12: Restore storage
if (process.versions.electron === '1.7.12') {
return exists(localStorageBackupFile).then(localStorageBackupFileExists => {
return exists(localStorageJournalBackupFile).then(localStorageJournalBackupFileExists => {
return TPromise.join([
localStorageBackupFileExists ? rename(localStorageBackupFile, localStorageFile) : TPromise.as(void 0),
localStorageJournalBackupFileExists ? rename(localStorageJournalBackupFile, localStorageJournalFile) : TPromise.as(void 0)
]);
});
}).then(() => void 0, () => void 0);
}
// Electron 2.0: Backup
else {
return exists(localStorageBackupFile).then(backupExists => {
if (backupExists) {
return void 0; // do not backup if backup already exists
}
return copy(localStorageFile, localStorageBackupFile).then(() => copy(localStorageJournalFile, localStorageJournalBackupFile));
}).then(() => void 0, () => void 0);
}
}
private initServices(machineId: string): IInstantiationService {
const services = new ServiceCollection();
@ -519,4 +481,4 @@ export class CodeApplication {
private dispose(): void {
this.toDispose = dispose(this.toDispose);
}
}
}

View file

@ -186,6 +186,23 @@ export class CodeWindow implements ICodeWindow {
this._win = new BrowserWindow(options);
this._id = this._win.id;
// Bug in Electron (https://github.com/electron/electron/issues/10862). On multi-monitor setups,
// it can happen that the position we set to the window is not the correct one on the display.
// To workaround, we ask the window for its position and set it again if not matching.
// This only applies if the window is not fullscreen or maximized and multiple monitors are used.
if (isWindows && !isFullscreenOrMaximized) {
try {
if (screen.getAllDisplays().length > 1) {
const [x, y] = this._win.getPosition();
if (x !== this.windowState.x || y !== this.windowState.y) {
this._win.setPosition(this.windowState.x, this.windowState.y, false);
}
}
} catch (err) {
this.logService.warn(`Unexpected error fixing window position on windows with multiple windows: ${err}\n${err.stack}`);
}
}
if (useCustomTitleStyle) {
this._win.setSheetOffset(22); // offset dialogs by the height of the custom title bar if we have any
}
@ -938,6 +955,11 @@ export class CodeWindow implements ICodeWindow {
this.touchBarGroups.push(groupTouchBar);
}
// Ugly workaround for native crash on macOS 10.12.1. We are not
// leveraging the API for changing the ESC touch bar item.
// See https://github.com/electron/electron/issues/10442
(<any>this._win)._setEscapeTouchBarItem = () => { };
this._win.setTouchBar(new TouchBar({ items: this.touchBarGroups }));
}

View file

@ -49,7 +49,7 @@ export class DarwinUpdateService extends AbstractUpdateService {
protected setUpdateFeedUrl(quality: string): boolean {
try {
electron.autoUpdater.setFeedURL({ url: createUpdateURL('darwin', quality) });
electron.autoUpdater.setFeedURL(createUpdateURL('darwin', quality));
} catch (e) {
// application is very likely not signed
this.logService.error('Failed to set update feed URL');

View file

@ -24,17 +24,14 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ToggleActivityBarVisibilityAction } from 'vs/workbench/browser/actions/toggleActivityBarVisibility';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ACTIVITY_BAR_BACKGROUND, ACTIVITY_BAR_BORDER, ACTIVITY_BAR_FOREGROUND, ACTIVITY_BAR_BADGE_BACKGROUND, ACTIVITY_BAR_BADGE_FOREGROUND, ACTIVITY_BAR_DRAG_AND_DROP_BACKGROUND } from 'vs/workbench/common/theme';
import { contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { CompositeBar } from 'vs/workbench/browser/parts/compositebar/compositeBar';
import { ToggleCompositePinnedAction } from 'vs/workbench/browser/parts/compositebar/compositeBarActions';
import { isMacintosh } from 'vs/base/common/platform';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { Dimension, scheduleAtNextAnimationFrame } from 'vs/base/browser/dom';
import { Color } from 'vs/base/common/color';
import { ViewLocation, ViewsRegistry } from 'vs/workbench/common/views';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { Dimension } from 'vs/base/browser/dom';
export class ActivitybarPart extends Part {
@ -62,8 +59,7 @@ export class ActivitybarPart extends Part {
@IContextMenuService private contextMenuService: IContextMenuService,
@IInstantiationService private instantiationService: IInstantiationService,
@IPartService private partService: IPartService,
@IThemeService themeService: IThemeService,
@ILifecycleService private lifecycleService: ILifecycleService
@IThemeService themeService: IThemeService
) {
super(id, { hasTitle: false }, themeService);
@ -142,27 +138,6 @@ export class ActivitybarPart extends Part {
// Top Actionbar with action items for each viewlet action
this.createGlobalActivityActionBar($('.global-activity').appendTo($result).getHTMLElement());
// TODO@Ben: workaround for https://github.com/Microsoft/vscode/issues/45700
// It looks like there are rendering glitches on macOS with Chrome 61 when
// using --webkit-mask with a background color that is different from the image
// The workaround is to promote the element onto its own drawing layer. We do
// this only after the workbench has loaded because otherwise there is ugly flicker.
if (isMacintosh) {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
scheduleAtNextAnimationFrame(() => { // another delay...
scheduleAtNextAnimationFrame(() => { // ...to prevent more flickering on startup
registerThemingParticipant((theme, collector) => {
const activityBarForeground = theme.getColor(ACTIVITY_BAR_FOREGROUND);
if (activityBarForeground && !activityBarForeground.equals(Color.white)) {
// only apply this workaround if the color is different from the image one (white)
collector.addRule('.monaco-workbench .activitybar > .content > .composite-bar > .monaco-action-bar .action-label { will-change: transform; }');
}
});
});
});
});
}
return $result.getHTMLElement();
}

View file

@ -43,7 +43,7 @@ import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
import { EditorWorkerServiceImpl } from 'vs/editor/common/services/editorWorkerServiceImpl';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { ExtensionService } from 'vs/workbench/services/extensions/electron-browser/extensionService';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
@ -83,7 +83,7 @@ import { HashService } from 'vs/workbench/services/hash/node/hashService';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
import { ILogService } from 'vs/platform/log/common/log';
import { WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme';
import { stat, existsSync } from 'fs';
import { stat } from 'fs';
import { join } from 'path';
import { ILocalizationsChannel, LocalizationsChannelClient } from 'vs/platform/localizations/common/localizationsIpc';
import { ILocalizationsService } from 'vs/platform/localizations/common/localizations';
@ -128,7 +128,6 @@ export class WorkbenchShell {
private lifecycleService: LifecycleService;
private mainProcessServices: ServiceCollection;
private notificationService: INotificationService;
private mainProcessClient: IPCClient;
private container: HTMLElement;
private toUnbind: IDisposable[];
@ -140,9 +139,7 @@ export class WorkbenchShell {
private configuration: IWindowConfiguration;
private workbench: Workbench;
private hasLocalStorageData: boolean;
constructor(container: HTMLElement, coreServices: ICoreServices, mainProcessServices: ServiceCollection, mainProcessClient: IPCClient, configuration: IWindowConfiguration) {
constructor(container: HTMLElement, coreServices: ICoreServices, mainProcessServices: ServiceCollection, private mainProcessClient: IPCClient, configuration: IWindowConfiguration) {
this.container = container;
this.configuration = configuration;
@ -155,13 +152,9 @@ export class WorkbenchShell {
this.storageService = coreServices.storageService;
this.mainProcessServices = mainProcessServices;
this.mainProcessClient = mainProcessClient;
this.toUnbind = [];
this.previousErrorTime = 0;
// TODO@Ben remove me later
this.hasLocalStorageData = !!this.storageService.get('releaseNotes/lastVersion', StorageScope.GLOBAL);
}
private createContents(parent: HTMLElement): HTMLElement {
@ -227,11 +220,6 @@ export class WorkbenchShell {
if (!this.environmentService.extensionTestsPath && this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) {
this.logLocalStorageMetrics();
}
// localStorage migration (TODO@Ben remove me later)
if (!this.environmentService.extensionTestsPath) {
this.logLocalStorageMigrationStatus();
}
});
return workbench;
@ -306,17 +294,17 @@ export class WorkbenchShell {
}
perf.mark('willReadLocalStorage');
const readyToSend = this.storageService.getBoolean('localStorageMetricsReadyToSend4');
const readyToSend = this.storageService.getBoolean('localStorageMetricsReadyToSend2');
perf.mark('didReadLocalStorage');
if (!readyToSend) {
this.storageService.store('localStorageMetricsReadyToSend4', true);
this.storageService.store('localStorageMetricsReadyToSend2', true);
return; // avoid logging localStorage metrics directly after the update, we prefer cold startup numbers
}
if (!this.storageService.getBoolean('localStorageMetricsSent4')) {
if (!this.storageService.getBoolean('localStorageMetricsSent2')) {
perf.mark('willWriteLocalStorage');
this.storageService.store('localStorageMetricsSent4', true);
this.storageService.store('localStorageMetricsSent2', true);
perf.mark('didWriteLocalStorage');
perf.mark('willStatLocalStorage');
@ -334,7 +322,7 @@ export class WorkbenchShell {
"size": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('localStorageTimers4', {
this.telemetryService.publicLog('localStorageTimers2', {
'statTime': perf.getDuration('willStatLocalStorage', 'didStatLocalStorage'),
'accessTime': perf.getDuration('willAccessLocalStorage', 'didAccessLocalStorage'),
'firstReadTime': perf.getDuration('willReadWorkspaceIdentifier', 'didReadWorkspaceIdentifier'),
@ -347,38 +335,6 @@ export class WorkbenchShell {
}
}
private logLocalStorageMigrationStatus(): void {
if (product.quality === 'insider' && !this.storageService.getBoolean('localStorageMigrationStatusLogged')) {
this.storageService.store('localStorageMigrationStatusLogged', true);
stat(join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage.vscbak'), (error, stat) => {
// if we have a backup of localStorage it means a migration was attempted
// by Electron 2.0. We log to telemetry if we had data initially which means
// the migration was successful.
if (stat) {
/* __GDPR__
"localStorageMigrationStatus" : {
"platform": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
"arch": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
"migrated": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
"size": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
"sqliteStillExists": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
"sqliteJournalExists": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
}
*/
this.telemetryService.publicLog('localStorageMigrationStatus', {
'platform': process.platform,
'arch': process.arch,
'migrated': this.hasLocalStorageData,
'size': stat.size,
'sqliteStillExists': existsSync(join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage')),
'sqliteJournalExists': existsSync(join(this.environmentService.userDataPath, 'Local Storage', 'file__0.localstorage-journal'))
});
}
});
}
}
private initServiceCollection(container: HTMLElement): [IInstantiationService, ServiceCollection] {
const serviceCollection = new ServiceCollection();
serviceCollection.set(IWorkspaceContextService, this.contextService);

View file

@ -13,24 +13,6 @@ import { Protocol } from 'vs/base/parts/ipc/node/ipc.net';
import { createConnection } from 'net';
import { Event, filterEvent } from 'vs/base/common/event';
// TODO@ben: with Electron 2.x and node.js 8.x the "natives" module
// can cause a native crash (see https://github.com/nodejs/node/issues/19891 and
// https://github.com/electron/electron/issues/10905). To prevent this from
// happening we essentially blocklist this module from getting loaded in any
// extension by patching the node require() function.
(function () {
const Module = require.__$__nodeRequire('module') as any;
const originalLoad = Module._load;
Module._load = function (request) {
if (request === 'natives') {
throw new Error('Either the extension or a NPM dependency is using the "natives" node module which is unsupported as it can cause a crash of the extension host. Click [here](https://go.microsoft.com/fwlink/?linkid=871887) to find out more');
}
return originalLoad.apply(this, arguments);
};
})();
interface IRendererConnection {
protocol: IMessagePassingProtocol;
initData: IInitData;
@ -146,6 +128,8 @@ createExtHostProtocol().then(protocol => {
return extensionHostMain.start();
}).catch(err => console.error(err));
function patchExecArgv() {
// when encountering the prevent-inspect flag we delete this
// and the prior flag

View file

@ -16,8 +16,8 @@ import { Queue } from 'vs/base/common/async';
import { stat, writeFile } from 'vs/base/node/pfs';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IWorkspaceContextService, Workspace, WorkbenchState, IWorkspaceFolder, toWorkspaceFolders, IWorkspaceFoldersChangeEvent, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { isLinux, isWindows, isMacintosh } from 'vs/base/common/platform';
import { IFileService } from 'vs/platform/files/common/files';
import { isLinux } from 'vs/base/common/platform';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ConfigurationChangeEvent, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
import { IConfigurationChangeEvent, ConfigurationTarget, IConfigurationOverrides, keyFromOverrideIdentifier, isConfigurationOverrides, IConfigurationData } from 'vs/platform/configuration/common/configuration';
@ -349,19 +349,7 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
const folderPath = URI.file(singleFolderWorkspaceIdentifier);
return stat(folderPath.fsPath)
.then(workspaceStat => {
let ctime: number;
if (isLinux) {
ctime = workspaceStat.ino; // Linux: birthtime is ctime, so we cannot use it! We use the ino instead!
} else if (isMacintosh) {
ctime = workspaceStat.birthtime.getTime(); // macOS: birthtime is fine to use as is
} else if (isWindows) {
if (typeof workspaceStat.birthtimeMs === 'number') {
ctime = Math.floor(workspaceStat.birthtimeMs); // Windows: fix precision issue in node.js 8.x to get 7.x results (see https://github.com/nodejs/node/issues/19897)
} else {
ctime = workspaceStat.birthtime.getTime();
}
}
const ctime = isLinux ? workspaceStat.ino : workspaceStat.birthtime.getTime(); // On Linux, birthtime is ctime, so we cannot use it! We use the ino instead!
const id = createHash('md5').update(folderPath.fsPath).update(ctime ? String(ctime) : '').digest('hex');
const folder = URI.file(folderPath.fsPath);
return new Workspace(id, getBaseLabel(folder), toWorkspaceFolders([{ path: folder.fsPath }]), null, ctime);

View file

@ -18,7 +18,6 @@ import { unmnemonicLabel } from 'vs/base/common/labels';
import { Event, Emitter } from 'vs/base/common/event';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IContextMenuDelegate, ContextSubMenu, IEvent } from 'vs/base/browser/contextmenu';
import { once } from 'vs/base/common/functional';
export class ContextMenuService implements IContextMenuService {
@ -43,15 +42,7 @@ export class ContextMenuService implements IContextMenuService {
}
return TPromise.timeout(0).then(() => { // https://github.com/Microsoft/vscode/issues/3638
const onHide = once(() => {
if (delegate.onHide) {
delegate.onHide(undefined);
}
this._onDidContextMenu.fire();
});
const menu = this.createMenu(delegate, actions, onHide);
const menu = this.createMenu(delegate, actions);
const anchor = delegate.getAnchor();
let x: number, y: number;
@ -70,18 +61,16 @@ export class ContextMenuService implements IContextMenuService {
x *= zoom;
y *= zoom;
menu.popup({
window: remote.getCurrentWindow(),
x: Math.floor(x),
y: Math.floor(y),
positioningItem: delegate.autoSelectFirstItem ? 0 : void 0,
callback: () => onHide()
});
menu.popup(remote.getCurrentWindow(), { x: Math.floor(x), y: Math.floor(y), positioningItem: delegate.autoSelectFirstItem ? 0 : void 0 });
this._onDidContextMenu.fire();
if (delegate.onHide) {
delegate.onHide(undefined);
}
});
});
}
private createMenu(delegate: IContextMenuDelegate, entries: (IAction | ContextSubMenu)[], onHide: () => void): Electron.Menu {
private createMenu(delegate: IContextMenuDelegate, entries: (IAction | ContextSubMenu)[]): Electron.Menu {
const menu = new remote.Menu();
const actionRunner = delegate.actionRunner || new ActionRunner();
@ -90,7 +79,7 @@ export class ContextMenuService implements IContextMenuService {
menu.append(new remote.MenuItem({ type: 'separator' }));
} else if (e instanceof ContextSubMenu) {
const submenu = new remote.MenuItem({
submenu: this.createMenu(delegate, e.entries, onHide),
submenu: this.createMenu(delegate, e.entries),
label: unmnemonicLabel(e.label)
});
@ -102,13 +91,6 @@ export class ContextMenuService implements IContextMenuService {
type: !!e.checked ? 'checkbox' : !!e.radio ? 'radio' : void 0,
enabled: !!e.enabled,
click: (menuItem, win, event) => {
// To preserve pre-electron-2.x behaviour, we first trigger
// the onHide callback and then the action.
// Fixes https://github.com/Microsoft/vscode/issues/45601
onHide();
// Run action which will close the menu
this.runAction(actionRunner, e, delegate, event);
}
};

View file

@ -193,13 +193,13 @@ export class ExtensionHostProcessWorker {
}, 100);
// Print out extension host output
onDebouncedOutput(output => {
const inspectorUrlMatch = !this._environmentService.isBuilt && output.data && output.data.match(/ws:\/\/([^\s]+)/);
if (inspectorUrlMatch) {
console.log(`%c[Extension Host] %cdebugger inspector at chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=${inspectorUrlMatch[1]}`, 'color: blue', 'color: black');
onDebouncedOutput(data => {
const inspectorUrlIndex = !this._environmentService.isBuilt && data.data && data.data.indexOf('chrome-devtools://');
if (inspectorUrlIndex >= 0) {
console.log(`%c[Extension Host] %cdebugger inspector at ${data.data.substr(inspectorUrlIndex)}`, 'color: blue', 'color: black');
} else {
console.group('Extension Host');
console.log(output.data, ...output.format);
console.log(data.data, ...data.format);
console.groupEnd();
}
});