"Fossies" - the Fresh Open Source Software Archive

Member "vscode-1.49.1/src/vs/workbench/services/accessibility/electron-browser/accessibilityService.ts" (16 Sep 2020, 4392 Bytes) of package /linux/misc/vscode-1.49.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "accessibilityService.ts": 1.48.2_vs_1.49.0.

    1 /*---------------------------------------------------------------------------------------------
    2  *  Copyright (c) Microsoft Corporation. All rights reserved.
    3  *  Licensed under the MIT License. See License.txt in the project root for license information.
    4  *--------------------------------------------------------------------------------------------*/
    5 
    6 import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
    7 import { isWindows, isLinux } from 'vs/base/common/platform';
    8 import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
    9 import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
   10 import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
   11 import { Registry } from 'vs/platform/registry/common/platform';
   12 import { AccessibilityService } from 'vs/platform/accessibility/common/accessibilityService';
   13 import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
   14 import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
   15 import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
   16 import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
   17 import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
   18 import { IEnvironmentService } from 'vs/platform/environment/common/environment';
   19 import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
   20 
   21 interface AccessibilityMetrics {
   22     enabled: boolean;
   23 }
   24 type AccessibilityMetricsClassification = {
   25     enabled: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
   26 };
   27 
   28 export class NativeAccessibilityService extends AccessibilityService implements IAccessibilityService {
   29 
   30     declare readonly _serviceBrand: undefined;
   31 
   32     private didSendTelemetry = false;
   33 
   34     constructor(
   35         @IWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService,
   36         @IContextKeyService contextKeyService: IContextKeyService,
   37         @IConfigurationService configurationService: IConfigurationService,
   38         @ITelemetryService private readonly _telemetryService: ITelemetryService
   39     ) {
   40         super(contextKeyService, configurationService);
   41         this.setAccessibilitySupport(environmentService.configuration.accessibilitySupport ? AccessibilitySupport.Enabled : AccessibilitySupport.Disabled);
   42     }
   43 
   44     async alwaysUnderlineAccessKeys(): Promise<boolean> {
   45         if (!isWindows) {
   46             return false;
   47         }
   48 
   49         const Registry = await import('vscode-windows-registry');
   50 
   51         let value: string | undefined = undefined;
   52         try {
   53             value = Registry.GetStringRegKey('HKEY_CURRENT_USER', 'Control Panel\\Accessibility\\Keyboard Preference', 'On');
   54         } catch {
   55             return false;
   56         }
   57 
   58         return value === '1';
   59     }
   60 
   61     setAccessibilitySupport(accessibilitySupport: AccessibilitySupport): void {
   62         super.setAccessibilitySupport(accessibilitySupport);
   63 
   64         if (!this.didSendTelemetry && accessibilitySupport === AccessibilitySupport.Enabled) {
   65             this._telemetryService.publicLog2<AccessibilityMetrics, AccessibilityMetricsClassification>('accessibility', { enabled: true });
   66             this.didSendTelemetry = true;
   67         }
   68     }
   69 }
   70 
   71 registerSingleton(IAccessibilityService, NativeAccessibilityService, true);
   72 
   73 // On linux we do not automatically detect that a screen reader is detected, thus we have to implicitly notify the renderer to enable accessibility when user configures it in settings
   74 class LinuxAccessibilityContribution implements IWorkbenchContribution {
   75     constructor(
   76         @IJSONEditingService jsonEditingService: IJSONEditingService,
   77         @IAccessibilityService accessibilityService: AccessibilityService,
   78         @IEnvironmentService environmentService: IEnvironmentService
   79     ) {
   80         const forceRendererAccessibility = () => {
   81             if (accessibilityService.isScreenReaderOptimized()) {
   82                 jsonEditingService.write(environmentService.argvResource, [{ path: ['force-renderer-accessibility'], value: true }], true);
   83             }
   84         };
   85         forceRendererAccessibility();
   86         accessibilityService.onDidChangeScreenReaderOptimized(forceRendererAccessibility);
   87     }
   88 }
   89 
   90 if (isLinux) {
   91     Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(LinuxAccessibilityContribution, LifecyclePhase.Ready);
   92 }