Files
azuredatastudio/src/vs/workbench/services/issue/electron-sandbox/issueService.ts
Charles Gagnon 3005d5435f Add preview features enabled flag to issue reporter info (#20808)
* Add preview features enabled flag to issue reporter info

* fix tests

* fix key
2022-10-11 15:46:32 -07:00

153 lines
8.5 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IssueReporterStyles, IssueReporterData, ProcessExplorerData, IssueReporterExtensionData } from 'vs/platform/issue/common/issue';
import { IIssueService } from 'vs/platform/issue/electron-sandbox/issue';
import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService';
import { textLinkForeground, inputBackground, inputBorder, inputForeground, buttonBackground, buttonHoverBackground, buttonForeground, inputValidationErrorBorder, foreground, inputActiveOptionBorder, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, editorBackground, editorForeground, listHoverBackground, listHoverForeground, textLinkActiveForeground, inputValidationErrorBackground, inputValidationErrorForeground, listActiveSelectionBackground, listActiveSelectionForeground, listFocusOutline, listFocusBackground, listFocusForeground, activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IWorkbenchExtensionEnablementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { getZoomLevel } from 'vs/base/browser/browser';
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
import { platform } from 'vs/base/common/process';
import { IProductService } from 'vs/platform/product/common/productService';
import { ITASExperimentService } from 'vs/workbench/services/experiment/common/experimentService';
import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
import { registerMainProcessRemoteService } from 'vs/platform/ipc/electron-sandbox/services';
import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; // {{SQL CARBON EDIT}} Add preview features flag
import { CONFIG_WORKBENCH_ENABLEPREVIEWFEATURES } from 'sql/workbench/common/constants'; // {{SQL CARBON EDIT}} Add preview features flag
export class WorkbenchIssueService implements IWorkbenchIssueService {
declare readonly _serviceBrand: undefined;
constructor(
@IIssueService private readonly issueService: IIssueService,
@IThemeService private readonly themeService: IThemeService,
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
@INativeWorkbenchEnvironmentService private readonly environmentService: INativeWorkbenchEnvironmentService,
@IWorkspaceTrustManagementService private readonly workspaceTrustManagementService: IWorkspaceTrustManagementService,
@IProductService private readonly productService: IProductService,
@ITASExperimentService private readonly experimentService: ITASExperimentService,
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
@IConfigurationService private readonly configurationService: IConfigurationService // {{SQL CARBON EDIT}} Add preview features flag
) { }
async openReporter(dataOverrides: Partial<IssueReporterData> = {}): Promise<void> {
const extensionData: IssueReporterExtensionData[] = [];
try {
const extensions = await this.extensionManagementService.getInstalled();
const enabledExtensions = extensions.filter(extension => this.extensionEnablementService.isEnabled(extension) || (dataOverrides.extensionId && extension.identifier.id === dataOverrides.extensionId));
extensionData.push(...enabledExtensions.map((extension): IssueReporterExtensionData => {
const { manifest } = extension;
const manifestKeys = manifest.contributes ? Object.keys(manifest.contributes) : [];
const isTheme = !manifest.activationEvents && manifestKeys.length === 1 && manifestKeys[0] === 'themes';
const isBuiltin = extension.type === ExtensionType.System;
return {
name: manifest.name,
publisher: manifest.publisher,
version: manifest.version,
repositoryUrl: manifest.repository && manifest.repository.url,
bugsUrl: manifest.bugs && manifest.bugs.url,
displayName: manifest.displayName,
id: extension.identifier.id,
isTheme,
isBuiltin,
};
}));
} catch (e) {
extensionData.push({
name: 'Workbench Issue Service',
publisher: 'Unknown',
version: '0.0.0',
repositoryUrl: undefined,
bugsUrl: undefined,
displayName: `Extensions not loaded: ${e}`,
id: 'workbench.issue',
isTheme: false,
isBuiltin: true
});
}
const experiments = await this.experimentService.getCurrentExperiments();
let githubAccessToken = '';
try {
const githubSessions = await this.authenticationService.getSessions('github');
const potentialSessions = githubSessions.filter(session => session.scopes.includes('repo'));
githubAccessToken = potentialSessions[0]?.accessToken;
} catch (e) {
// Ignore
}
const theme = this.themeService.getColorTheme();
const issueReporterData: IssueReporterData = Object.assign({
styles: getIssueReporterStyles(theme),
zoomLevel: getZoomLevel(),
enabledExtensions: extensionData,
experiments: experiments?.join('\n'),
restrictedMode: !this.workspaceTrustManagementService.isWorkspaceTrusted(),
previewFeaturesEnabled: this.configurationService.getValue(CONFIG_WORKBENCH_ENABLEPREVIEWFEATURES), // {{SQL CARBON EDIT}} Add preview features flag
githubAccessToken,
}, dataOverrides);
return this.issueService.openReporter(issueReporterData);
}
openProcessExplorer(): Promise<void> {
const theme = this.themeService.getColorTheme();
const data: ProcessExplorerData = {
pid: this.environmentService.configuration.mainPid,
zoomLevel: getZoomLevel(),
styles: {
backgroundColor: getColor(theme, editorBackground),
color: getColor(theme, editorForeground),
listHoverBackground: getColor(theme, listHoverBackground),
listHoverForeground: getColor(theme, listHoverForeground),
listFocusBackground: getColor(theme, listFocusBackground),
listFocusForeground: getColor(theme, listFocusForeground),
listFocusOutline: getColor(theme, listFocusOutline),
listActiveSelectionBackground: getColor(theme, listActiveSelectionBackground),
listActiveSelectionForeground: getColor(theme, listActiveSelectionForeground),
listHoverOutline: getColor(theme, activeContrastBorder),
},
platform: platform,
applicationName: this.productService.applicationName
};
return this.issueService.openProcessExplorer(data);
}
}
export function getIssueReporterStyles(theme: IColorTheme): IssueReporterStyles {
return {
backgroundColor: getColor(theme, SIDE_BAR_BACKGROUND),
color: getColor(theme, foreground),
textLinkColor: getColor(theme, textLinkForeground),
textLinkActiveForeground: getColor(theme, textLinkActiveForeground),
inputBackground: getColor(theme, inputBackground),
inputForeground: getColor(theme, inputForeground),
inputBorder: getColor(theme, inputBorder),
inputActiveBorder: getColor(theme, inputActiveOptionBorder),
inputErrorBorder: getColor(theme, inputValidationErrorBorder),
inputErrorBackground: getColor(theme, inputValidationErrorBackground),
inputErrorForeground: getColor(theme, inputValidationErrorForeground),
buttonBackground: getColor(theme, buttonBackground),
buttonForeground: getColor(theme, buttonForeground),
buttonHoverBackground: getColor(theme, buttonHoverBackground),
sliderActiveColor: getColor(theme, scrollbarSliderActiveBackground),
sliderBackgroundColor: getColor(theme, scrollbarSliderBackground),
sliderHoverColor: getColor(theme, scrollbarSliderHoverBackground),
};
}
function getColor(theme: IColorTheme, key: string): string | undefined {
const color = theme.getColor(key);
return color ? color.toString() : undefined;
}
registerMainProcessRemoteService(IIssueService, 'issue', { supportsDelayedInstantiation: true });