Skip to content

Commit

Permalink
Add "(Administrator)" suffix to window title when running as administ…
Browse files Browse the repository at this point in the history
…rator in Windows (fixes #19707)
  • Loading branch information
bpasero committed Dec 11, 2017
1 parent d850984 commit 83ba5d1
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ function packageTask(platform, arch, opts) {
.pipe(util.cleanNodeModule('oniguruma', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node', 'src/*.js']))
.pipe(util.cleanNodeModule('windows-mutex', ['binding.gyp', 'build/**', 'src/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('native-keymap', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('native-is-elevated', ['binding.gyp', 'build/**', 'src/**', 'deps/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('native-watchdog', ['binding.gyp', 'build/**', 'src/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('spdlog', ['binding.gyp', 'build/**', 'deps/**', 'src/**', 'test/**'], ['**/*.node']))
.pipe(util.cleanNodeModule('jschardet', ['dist/**']))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"jschardet": "1.6.0",
"keytar": "^4.0.5",
"minimist": "1.2.0",
"native-is-elevated": "^0.2.1",
"native-keymap": "1.2.5",
"native-watchdog": "0.3.0",
"node-pty": "0.7.4",
Expand Down
10 changes: 10 additions & 0 deletions src/typings/native-is-elevated.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'native-is-elevated' {
function isElevated(): boolean;

export = isElevated;
}
35 changes: 21 additions & 14 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { IAction, Action } from 'vs/base/common/actions';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
Expand All @@ -31,15 +30,21 @@ 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 { isMacintosh } from 'vs/base/common/platform';
import { isMacintosh, isWindows } from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';

export interface ITitleProperties {
isPure: boolean;
isAdmin: boolean;
}

export class TitlebarPart extends Part implements ITitleService {

public _serviceBrand: any;

private static readonly NLS_UNSUPPORTED = nls.localize('patchedWindowTitle', "[Unsupported]");
private static NLS_USER_IS_ADMIN = nls.localize('userIsAdmin', "(Administrator)");
private static readonly NLS_EXTENSION_HOST = nls.localize('devExtensionWindowTitlePrefix', "[Extension Development Host]");
private static readonly TITLE_DIRTY = '\u25cf ';
private static readonly TITLE_SEPARATOR = isMacintosh ? ' — ' : ' - '; // macOS uses special - separator
Expand All @@ -52,7 +57,7 @@ export class TitlebarPart extends Part implements ITitleService {

private isInactive: boolean;

private isPure: boolean;
private properties: ITitleProperties;
private activeEditorListeners: IDisposable[];

constructor(
Expand All @@ -63,15 +68,14 @@ export class TitlebarPart extends Part implements ITitleService {
@IWindowsService private windowsService: IWindowsService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IIntegrityService private integrityService: IIntegrityService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IThemeService themeService: IThemeService,
@ILifecycleService private lifecycleService: ILifecycleService
) {
super(id, { hasTitle: false }, themeService);

this.isPure = true;
this.properties = { isPure: true, isAdmin: false };
this.activeEditorListeners = [];

this.init();
Expand All @@ -83,14 +87,6 @@ export class TitlebarPart extends Part implements ITitleService {

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

// Integrity for window title
this.integrityService.isPure().then(r => {
if (!r.isPure) {
this.isPure = false;
this.setTitle(this.getWindowTitle());
}
});
}

private registerListeners(): void {
Expand Down Expand Up @@ -149,7 +145,11 @@ export class TitlebarPart extends Part implements ITitleService {
title = this.environmentService.appNameLong;
}

if (!this.isPure) {
if (isWindows && this.properties.isAdmin) {
title = `${title} ${TitlebarPart.NLS_USER_IS_ADMIN}`;
}

if (!this.properties.isPure) {
title = `${title} ${TitlebarPart.NLS_UNSUPPORTED}`;
}

Expand All @@ -161,6 +161,13 @@ export class TitlebarPart extends Part implements ITitleService {
return title;
}

public updateProperties(properties: ITitleProperties): void {
if (properties.isAdmin !== this.properties.isAdmin || properties.isPure !== this.properties.isPure) {
this.properties = properties;
this.setTitle(this.getWindowTitle());
}
}

/**
* Possible template values:
*
Expand Down
4 changes: 0 additions & 4 deletions src/vs/workbench/electron-browser/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { CodeEditorServiceImpl } from 'vs/editor/browser/services/codeEditorServiceImpl';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IntegrityServiceImpl } from 'vs/platform/integrity/node/integrityServiceImpl';
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';
Expand Down Expand Up @@ -393,8 +391,6 @@ export class WorkbenchShell {

serviceCollection.set(ICodeEditorService, new SyncDescriptor(CodeEditorServiceImpl));

serviceCollection.set(IIntegrityService, new SyncDescriptor(IntegrityServiceImpl));

return [instantiationService, serviceCollection];
}

Expand Down
16 changes: 16 additions & 0 deletions src/vs/workbench/electron-browser/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { getServices } from 'vs/platform/instantiation/common/extensions';
import { Position, Parts, IPartService, ILayoutOptions, Dimension } from 'vs/workbench/services/part/common/partService';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IntegrityServiceImpl } from 'vs/platform/integrity/node/integrityServiceImpl';
import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
import { ContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -512,6 +514,10 @@ export class Workbench implements IPartService {
// Services we contribute
serviceCollection.set(IPartService, this);

// Integrity
const integrityService = this.instantiationService.createInstance(IntegrityServiceImpl);
serviceCollection.set(IIntegrityService, integrityService);

// Clipboard
serviceCollection.set(IClipboardService, new ClipboardService());

Expand Down Expand Up @@ -574,6 +580,16 @@ export class Workbench implements IPartService {
this.titlebarPart = this.instantiationService.createInstance(TitlebarPart, Identifiers.TITLEBAR_PART);
this.toUnbind.push({ dispose: () => this.titlebarPart.shutdown() });
serviceCollection.set(ITitleService, this.titlebarPart);
this.lifecycleService.when(LifecyclePhase.Eventually).then(() => {
return integrityService.isPure().then(res => {
return import('native-is-elevated').then(nativeIsElevated => {
this.titlebarPart.updateProperties({
isPure: res.isPure,
isAdmin: nativeIsElevated()
});
});
});
});

// History
serviceCollection.set(IHistoryService, new SyncDescriptor(HistoryService));
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3742,6 +3742,10 @@ nan@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a"

native-is-elevated@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/native-is-elevated/-/native-is-elevated-0.2.1.tgz#70a2123a8575b9f624a3ef465d98cb74ae017385"

[email protected]:
version "1.2.5"
resolved "https://registry.yarnpkg.com/native-keymap/-/native-keymap-1.2.5.tgz#1035a9417b9a9340cf8097763a43c76d588165a5"
Expand Down

0 comments on commit 83ba5d1

Please sign in to comment.