Skip to content

Commit

Permalink
sandbox - expose vscode-windows-registry from native host service
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 18, 2020
1 parent e85114b commit c4aa010
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/vs/platform/native/common/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ export interface ICommonNativeHostService {

// Connectivity
resolveProxy(url: string): Promise<string | undefined>;

// Registry (windows only)
windowsGetStringRegKey(hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise<string | undefined>;
}
15 changes: 15 additions & 0 deletions src/vs/platform/native/electron-main/nativeHostMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ export class NativeHostMainService implements INativeHostMainService {

//#endregion

//#region Registry (windows)

async windowsGetStringRegKey(windowId: number | undefined, hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise<string | undefined> {
if (!isWindows) {
return undefined;
}

const Registry = await import('vscode-windows-registry');
try {
return Registry.GetStringRegKey(hive, path, name);
} catch {
return undefined;
}
}

private windowById(windowId: number | undefined): ICodeWindow | undefined {
if (typeof windowId !== 'number') {
return undefined;
Expand Down
12 changes: 4 additions & 8 deletions src/vs/workbench/contrib/tags/electron-browser/workspaceTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IRequestService } from 'vs/platform/request/common/request';
import { isWindows } from 'vs/base/common/platform';
import { getRemotes, AllowedSecondLevelDomains, getDomainsOfRemotes } from 'vs/platform/extensionManagement/common/configRemotes';
import { IDiagnosticsService } from 'vs/platform/diagnostics/node/diagnosticsService';
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';

export function getHashedRemotesFromConfig(text: string, stripEndingDotGit: boolean = false): string[] {
return getRemotes(text, stripEndingDotGit).map(r => {
Expand All @@ -33,7 +34,8 @@ export class WorkspaceTags implements IWorkbenchContribution {
@IRequestService private readonly requestService: IRequestService,
@ITextFileService private readonly textFileService: ITextFileService,
@IWorkspaceTagsService private readonly workspaceTagsService: IWorkspaceTagsService,
@IDiagnosticsService private readonly diagnosticsService: IDiagnosticsService
@IDiagnosticsService private readonly diagnosticsService: IDiagnosticsService,
@INativeHostService private readonly nativeHostService: INativeHostService
) {
if (this.telemetryService.isOptedIn) {
this.report();
Expand Down Expand Up @@ -61,13 +63,7 @@ export class WorkspaceTags implements IWorkbenchContribution {
return;
}

const Registry = await import('vscode-windows-registry');

let value;
try {
value = Registry.GetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', 'EditionID');
} catch { }

let value = await this.nativeHostService.windowsGetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', 'EditionID');
if (value === undefined) {
value = 'Unknown';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';

interface AccessibilityMetrics {
enabled: boolean;
Expand All @@ -33,7 +34,8 @@ export class NativeAccessibilityService extends AccessibilityService implements
@INativeWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService,
@IContextKeyService contextKeyService: IContextKeyService,
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService private readonly _telemetryService: ITelemetryService
@ITelemetryService private readonly _telemetryService: ITelemetryService,
@INativeHostService private readonly nativeHostService: INativeHostService
) {
super(contextKeyService, configurationService);
this.setAccessibilitySupport(environmentService.configuration.accessibilitySupport ? AccessibilitySupport.Enabled : AccessibilitySupport.Disabled);
Expand All @@ -44,15 +46,7 @@ export class NativeAccessibilityService extends AccessibilityService implements
return false;
}

const Registry = await import('vscode-windows-registry');

let value: string | undefined = undefined;
try {
value = Registry.GetStringRegKey('HKEY_CURRENT_USER', 'Control Panel\\Accessibility\\Keyboard Preference', 'On');
} catch {
return false;
}

const value = await this.nativeHostService.windowsGetStringRegKey('HKEY_CURRENT_USER', 'Control Panel\\Accessibility\\Keyboard Preference', 'On');
return value === '1';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class TestNativeHostService implements INativeHostService {
async readClipboardBuffer(format: string): Promise<Uint8Array> { return Uint8Array.from([]); }
async hasClipboard(format: string, type?: 'selection' | 'clipboard' | undefined): Promise<boolean> { return false; }
async sendInputEvent(event: MouseInputEvent): Promise<void> { }
async windowsGetStringRegKey(hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise<string | undefined> { return undefined; }
}

export function workbenchInstantiationService(): ITestInstantiationService {
Expand Down

0 comments on commit c4aa010

Please sign in to comment.