Skip to content

Commit

Permalink
get rid of joinCreation in favour of lifecycle service (for #37541)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 8, 2017
1 parent 0438b90 commit dff56ed
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 80 deletions.
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Expand Up @@ -31,9 +31,9 @@ import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/
import { Verbosity } from 'vs/platform/editor/common/editor';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER } from 'vs/workbench/common/theme';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { isMacintosh } from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';

export class TitlebarPart extends Part implements ITitleService {

Expand Down Expand Up @@ -67,7 +67,7 @@ export class TitlebarPart extends Part implements ITitleService {
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IThemeService themeService: IThemeService,
@IPartService private partService: IPartService
@ILifecycleService private lifecycleService: ILifecycleService
) {
super(id, { hasTitle: false }, themeService);

Expand All @@ -82,7 +82,7 @@ export class TitlebarPart extends Part implements ITitleService {
private init(): void {

// Initial window title when loading is done
this.partService.joinCreation().done(() => this.setTitle(this.getWindowTitle()));
this.lifecycleService.when(LifecyclePhase.Running).then(() => this.setTitle(this.getWindowTitle()));

// Integrity for window title
this.integrityService.isPure().then(r => {
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/common/actions.ts
Expand Up @@ -8,13 +8,13 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Registry } from 'vs/platform/registry/common/platform';
import { IAction } from 'vs/base/common/actions';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { IMessageService } from 'vs/platform/message/common/message';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import Severity from 'vs/base/common/severity';
import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';

export const Extensions = {
WorkbenchActions: 'workbench.contributions.actions'
Expand Down Expand Up @@ -86,15 +86,15 @@ Registry.add(Extensions.WorkbenchActions, new class implements IWorkbenchActionR
return (accessor, args) => {
const messageService = accessor.get(IMessageService);
const instantiationService = accessor.get(IInstantiationService);
const partService = accessor.get(IPartService);
const lifecycleService = accessor.get(ILifecycleService);

TPromise.as(this._triggerAndDisposeAction(instantiationService, partService, descriptor, args)).done(null, (err) => {
TPromise.as(this._triggerAndDisposeAction(instantiationService, lifecycleService, descriptor, args)).then(null, (err) => {
messageService.show(Severity.Error, err);
});
};
}

private _triggerAndDisposeAction(instantitationService: IInstantiationService, partService: IPartService, descriptor: SyncActionDescriptor, args: any): TPromise<any> {
private _triggerAndDisposeAction(instantitationService: IInstantiationService, lifecycleService: ILifecycleService, descriptor: SyncActionDescriptor, args: any): Thenable<void> {
const actionInstance = instantitationService.createInstance(descriptor.syncDescriptor);
actionInstance.label = descriptor.label || actionInstance.label;

Expand All @@ -108,7 +108,7 @@ Registry.add(Extensions.WorkbenchActions, new class implements IWorkbenchActionR
const from = args && args.from || 'keybinding';

// run action when workbench is created
return partService.joinCreation().then(() => {
return lifecycleService.when(LifecyclePhase.Running).then(() => {
try {
return TPromise.as(actionInstance.run(undefined, { from })).then(() => {
actionInstance.dispose();
Expand Down
30 changes: 11 additions & 19 deletions src/vs/workbench/electron-browser/shell.ts
Expand Up @@ -8,7 +8,6 @@
import 'vs/css!./media/shell';

import * as nls from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import * as platform from 'vs/base/common/platform';
import { Dimension, Builder, $ } from 'vs/base/browser/builder';
import dom = require('vs/base/browser/dom');
Expand Down Expand Up @@ -168,18 +167,7 @@ export class WorkbenchShell {
this.workbench = instantiationService.createInstance(Workbench, parent.getHTMLElement(), workbenchContainer.getHTMLElement(), this.configuration, serviceCollection, this.lifecycleService);
try {
this.workbench.startup({
onWorkbenchStarted: (info: IWorkbenchStartedInfo) => {

// run workbench started logic
this.onWorkbenchStarted(info);

// start cached data manager
instantiationService.createInstance(NodeCachedDataManager);

// Set lifecycle phase to `Runnning` so that other contributions
// can now do something
this.lifecycleService.phase = LifecyclePhase.Running;
}
onWorkbenchStarted: (info: IWorkbenchStartedInfo) => this.onWorkbenchStarted(info, instantiationService)
});
} catch (error) {

Expand All @@ -198,14 +186,14 @@ export class WorkbenchShell {
console.warn('Workbench did not finish loading in 10 seconds, that might be a problem that should be reported.');
}, 10000);

this.workbench.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
clearTimeout(timeoutHandle);
});

return workbenchContainer;
}

private onWorkbenchStarted(info: IWorkbenchStartedInfo): void {
private onWorkbenchStarted(info: IWorkbenchStartedInfo, instantiationService: IInstantiationService): void {

// Telemetry: workspace info
const { filesToOpen, filesToCreate, filesToDiff } = this.configuration;
Expand Down Expand Up @@ -268,9 +256,17 @@ export class WorkbenchShell {
workspaceStats.reportWorkspaceTags(this.configuration);
workspaceStats.reportCloudStats();

// Root Warning
if ((platform.isLinux || platform.isMacintosh) && process.getuid() === 0) {
this.messageService.show(Severity.Warning, nls.localize('runningAsRoot', "It is recommended not to run Code as 'root'."));
}

// Start cached data manager
instantiationService.createInstance(NodeCachedDataManager);

// Set lifecycle phase to `Runnning` so that other contributions
// can now do something
this.lifecycleService.phase = LifecyclePhase.Running;
}

private initServiceCollection(container: HTMLElement): [IInstantiationService, ServiceCollection] {
Expand Down Expand Up @@ -482,10 +478,6 @@ export class WorkbenchShell {
this.workbench.layout();
}

public joinCreation(): TPromise<boolean> {
return this.workbench.joinCreation();
}

public dispose(): void {

// Workbench
Expand Down
24 changes: 12 additions & 12 deletions src/vs/workbench/electron-browser/window.ts
Expand Up @@ -17,7 +17,6 @@ import DOM = require('vs/base/browser/dom');
import Severity from 'vs/base/common/severity';
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { IAction, Action } from 'vs/base/common/actions';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { AutoSaveConfiguration, IFileService } from 'vs/platform/files/common/files';
import { toResource } from 'vs/workbench/common/editor';
import { IWorkbenchEditorService, IResourceInputType } from 'vs/workbench/services/editor/common/editorService';
Expand Down Expand Up @@ -45,6 +44,7 @@ import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ConfigurationTarget, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { LifecyclePhase, ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';

const TextInputActions: IAction[] = [
new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && TPromise.as(true)),
Expand Down Expand Up @@ -72,7 +72,6 @@ export class ElectronWindow extends Themable {
shellContainer: HTMLElement,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IPartService private partService: IPartService,
@IWindowsService private windowsService: IWindowsService,
@IWindowService private windowService: IWindowService,
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
Expand All @@ -87,7 +86,8 @@ export class ElectronWindow extends Themable {
@ITelemetryService private telemetryService: ITelemetryService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
@IFileService private fileService: IFileService,
@IMenuService private menuService: IMenuService
@IMenuService private menuService: IMenuService,
@ILifecycleService private lifecycleService: ILifecycleService
) {
super(themeService);

Expand Down Expand Up @@ -194,13 +194,13 @@ export class ElectronWindow extends Themable {

// Fullscreen Events
ipc.on('vscode:enterFullScreen', () => {
this.partService.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
browser.setFullscreen(true);
});
});

ipc.on('vscode:leaveFullScreen', () => {
this.partService.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
browser.setFullscreen(false);
});
});
Expand All @@ -209,7 +209,7 @@ export class ElectronWindow extends Themable {
ipc.on('vscode:enterHighContrast', () => {
const windowConfig = this.configurationService.getConfiguration<IWindowSettings>('window');
if (windowConfig && windowConfig.autoDetectHighContrast) {
this.partService.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
this.themeService.setColorTheme(VS_HC_THEME, null);
});
}
Expand All @@ -218,7 +218,7 @@ export class ElectronWindow extends Themable {
ipc.on('vscode:leaveHighContrast', () => {
const windowConfig = this.configurationService.getConfiguration<IWindowSettings>('window');
if (windowConfig && windowConfig.autoDetectHighContrast) {
this.partService.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
this.themeService.setColorTheme(VS_DARK_THEME, null);
});
}
Expand Down Expand Up @@ -301,7 +301,7 @@ export class ElectronWindow extends Themable {
});

// Emit event when vscode has loaded
this.partService.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
ipc.send('vscode:workbenchLoaded', this.windowService.getCurrentWindowId());
});

Expand Down Expand Up @@ -370,7 +370,7 @@ export class ElectronWindow extends Themable {
}

private resolveKeybindings(actionIds: string[]): TPromise<{ id: string; label: string, isNative: boolean; }[]> {
return TPromise.join([this.partService.joinCreation(), this.extensionService.onReady()]).then(() => {
return TPromise.join([this.lifecycleService.when(LifecyclePhase.Running), this.extensionService.onReady()]).then(() => {
return arrays.coalesce(actionIds.map(id => {
const binding = this.keybindingService.lookupKeybinding(id);
if (!binding) {
Expand Down Expand Up @@ -417,7 +417,7 @@ export class ElectronWindow extends Themable {
}

if (inputs.length) {
this.openResources(inputs, diffMode).done(null, errors.onUnexpectedError);
this.openResources(inputs, diffMode).then(null, errors.onUnexpectedError);
}

if (request.filesToWait && inputs.length) {
Expand All @@ -436,8 +436,8 @@ export class ElectronWindow extends Themable {
}
}

private openResources(resources: (IResourceInput | IUntitledResourceInput)[], diffMode: boolean): TPromise<IEditor | IEditor[]> {
return this.partService.joinCreation().then((): TPromise<IEditor | IEditor[]> => {
private openResources(resources: (IResourceInput | IUntitledResourceInput)[], diffMode: boolean): Thenable<IEditor | IEditor[]> {
return this.lifecycleService.when(LifecyclePhase.Running).then((): TPromise<IEditor | IEditor[]> => {

// In diffMode we open 2 resources as diff
if (diffMode && resources.length === 2) {
Expand Down
27 changes: 8 additions & 19 deletions src/vs/workbench/electron-browser/workbench.ts
Expand Up @@ -8,7 +8,7 @@
import 'vs/css!./media/workbench';

import { localize } from 'vs/nls';
import { TPromise, ValueCallback } from 'vs/base/common/winjs.base';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Event, { Emitter, chain } from 'vs/base/common/event';
import DOM = require('vs/base/browser/dom');
Expand Down Expand Up @@ -188,8 +188,6 @@ export class Workbench implements IPartService {
private toDispose: IDisposable[];
private toShutdown: { shutdown: () => void; }[];
private callbacks: IWorkbenchCallbacks;
private creationPromise: TPromise<boolean>;
private creationPromiseComplete: ValueCallback;
private sideBarHidden: boolean;
private statusBarHidden: boolean;
private activityBarHidden: boolean;
Expand Down Expand Up @@ -245,10 +243,6 @@ export class Workbench implements IPartService {
this.closeEmptyWindowScheduler = new RunOnceScheduler(() => this.onAllEditorsClosed(), 50);

this._onTitleBarVisibilityChange = new Emitter<void>();

this.creationPromise = new TPromise<boolean>(c => {
this.creationPromiseComplete = c;
});
}

public get onTitleBarVisibilityChange(): Event<void> {
Expand Down Expand Up @@ -302,7 +296,6 @@ export class Workbench implements IPartService {
// Restore Parts
this.restoreParts().done(startedInfo => {
this.workbenchCreated = true;
this.creationPromiseComplete(true);

if (this.callbacks && this.callbacks.onWorkbenchStarted) {
this.callbacks.onWorkbenchStarted(startedInfo);
Expand Down Expand Up @@ -682,10 +675,6 @@ export class Workbench implements IPartService {
return this.workbenchCreated && this.workbenchStarted;
}

public joinCreation(): TPromise<boolean> {
return this.creationPromise;
}

public hasFocus(part: Parts): boolean {
const activeElement = document.activeElement;
if (!activeElement) {
Expand Down Expand Up @@ -905,7 +894,7 @@ export class Workbench implements IPartService {

private setSideBarPosition(position: Position): void {
if (this.sideBarHidden) {
this.setSideBarHidden(false, true /* Skip Layout */).done(undefined, errors.onUnexpectedError);
this.setSideBarHidden(false, true /* Skip Layout */).done(void 0, errors.onUnexpectedError);
}

const newPositionValue = (position === Position.LEFT) ? 'left' : 'right';
Expand All @@ -932,7 +921,7 @@ export class Workbench implements IPartService {

private setPanelPosition(position: Position): void {
if (this.panelHidden) {
this.setPanelHidden(false, true /* Skip Layout */).done(undefined, errors.onUnexpectedError);
this.setPanelHidden(false, true /* Skip Layout */).done(void 0, errors.onUnexpectedError);
}

const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
Expand Down Expand Up @@ -1297,8 +1286,8 @@ export class Workbench implements IPartService {
this.zenMode.transitionedToFullScreen = toggleFullScreen;
this.zenMode.wasSideBarVisible = this.isVisible(Parts.SIDEBAR_PART);
this.zenMode.wasPanelVisible = this.isVisible(Parts.PANEL_PART);
this.setPanelHidden(true, true).done(undefined, errors.onUnexpectedError);
this.setSideBarHidden(true, true).done(undefined, errors.onUnexpectedError);
this.setPanelHidden(true, true).done(void 0, errors.onUnexpectedError);
this.setSideBarHidden(true, true).done(void 0, errors.onUnexpectedError);

if (config.hideActivityBar) {
this.setActivityBarHidden(true, true);
Expand All @@ -1313,11 +1302,11 @@ export class Workbench implements IPartService {
}
} else {
if (this.zenMode.wasPanelVisible) {
this.setPanelHidden(false, true).done(undefined, errors.onUnexpectedError);
this.setPanelHidden(false, true).done(void 0, errors.onUnexpectedError);
}

if (this.zenMode.wasSideBarVisible) {
this.setSideBarHidden(false, true).done(undefined, errors.onUnexpectedError);
this.setSideBarHidden(false, true).done(void 0, errors.onUnexpectedError);
}

// Status bar and activity bar visibility come from settings -> update their visibility.
Expand All @@ -1338,7 +1327,7 @@ export class Workbench implements IPartService {
}

if (toggleFullScreen) {
this.windowService.toggleFullScreen().done(undefined, errors.onUnexpectedError);
this.windowService.toggleFullScreen().done(void 0, errors.onUnexpectedError);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/parts/backup/common/backupRestorer.ts
Expand Up @@ -9,33 +9,33 @@ import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IUntitledEditorService, UNTITLED_SCHEMA } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import errors = require('vs/base/common/errors');
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Position, IResourceInput, IUntitledResourceInput } from 'vs/platform/editor/common/editor';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { Schemas } from 'vs/base/common/network';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';

export class BackupRestorer implements IWorkbenchContribution {

private static readonly UNTITLED_REGEX = /Untitled-\d+/;

constructor(
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IPartService private partService: IPartService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IBackupFileService private backupFileService: IBackupFileService,
@ITextFileService private textFileService: ITextFileService,
@IEditorGroupService private groupService: IEditorGroupService
@IEditorGroupService private groupService: IEditorGroupService,
@ILifecycleService private lifecycleService: ILifecycleService
) {
this.restoreBackups();
}

private restoreBackups(): void {
if (this.backupFileService.backupEnabled) {
this.partService.joinCreation().then(() => {
this.lifecycleService.when(LifecyclePhase.Running).then(() => {
this.doRestoreBackups().done(null, errors.onUnexpectedError);
});
}
Expand Down

0 comments on commit dff56ed

Please sign in to comment.