Path: blob/main/src/vs/workbench/contrib/issue/electron-browser/issueService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { getZoomLevel } from '../../../../base/browser/browser.js';6import { mainWindow } from '../../../../base/browser/window.js';7import { IExtensionManagementService } from '../../../../platform/extensionManagement/common/extensionManagement.js';8import { ExtensionType } from '../../../../platform/extensions/common/extensions.js';9import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';10import { buttonBackground, buttonForeground, buttonHoverBackground, foreground, inputActiveOptionBorder, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, scrollbarSliderActiveBackground, scrollbarSliderHoverBackground, textLinkActiveForeground, textLinkForeground } from '../../../../platform/theme/common/colorRegistry.js';11import { IColorTheme, IThemeService } from '../../../../platform/theme/common/themeService.js';12import { IWorkspaceTrustManagementService } from '../../../../platform/workspace/common/workspaceTrust.js';13import { SIDE_BAR_BACKGROUND } from '../../../common/theme.js';14import { IIssueFormService, IssueReporterData, IssueReporterExtensionData, IssueReporterStyles, IWorkbenchIssueService } from '../common/issue.js';15import { IWorkbenchAssignmentService } from '../../../services/assignment/common/assignmentService.js';16import { IAuthenticationService } from '../../../services/authentication/common/authentication.js';17import { IWorkbenchExtensionEnablementService } from '../../../services/extensionManagement/common/extensionManagement.js';18import { IIntegrityService } from '../../../services/integrity/common/integrity.js';1920export class NativeIssueService implements IWorkbenchIssueService {21declare readonly _serviceBrand: undefined;2223constructor(24@IIssueFormService private readonly issueFormService: IIssueFormService,25@IThemeService private readonly themeService: IThemeService,26@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,27@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,28@IWorkspaceTrustManagementService private readonly workspaceTrustManagementService: IWorkspaceTrustManagementService,29@IWorkbenchAssignmentService private readonly experimentService: IWorkbenchAssignmentService,30@IAuthenticationService private readonly authenticationService: IAuthenticationService,31@IIntegrityService private readonly integrityService: IIntegrityService,32) { }3334async openReporter(dataOverrides: Partial<IssueReporterData> = {}): Promise<void> {35const extensionData: IssueReporterExtensionData[] = [];36try {37const extensions = await this.extensionManagementService.getInstalled();38const enabledExtensions = extensions.filter(extension => this.extensionEnablementService.isEnabled(extension) || (dataOverrides.extensionId && extension.identifier.id === dataOverrides.extensionId));39extensionData.push(...enabledExtensions.map((extension): IssueReporterExtensionData => {40const { manifest } = extension;41const manifestKeys = manifest.contributes ? Object.keys(manifest.contributes) : [];42const isTheme = !manifest.main && !manifest.browser && manifestKeys.length === 1 && manifestKeys[0] === 'themes';43const isBuiltin = extension.type === ExtensionType.System;44return {45name: manifest.name,46publisher: manifest.publisher,47version: manifest.version,48repositoryUrl: manifest.repository && manifest.repository.url,49bugsUrl: manifest.bugs && manifest.bugs.url,50displayName: manifest.displayName,51id: extension.identifier.id,52data: dataOverrides.data,53uri: dataOverrides.uri,54isTheme,55isBuiltin,56extensionData: 'Extensions data loading',57};58}));59} catch (e) {60extensionData.push({61name: 'Workbench Issue Service',62publisher: 'Unknown',63version: '0.0.0',64repositoryUrl: undefined,65bugsUrl: undefined,66extensionData: 'Extensions data loading',67displayName: `Extensions not loaded: ${e}`,68id: 'workbench.issue',69isTheme: false,70isBuiltin: true71});72}73const experiments = await this.experimentService.getCurrentExperiments();7475let githubAccessToken = '';76try {77const githubSessions = await this.authenticationService.getSessions('github');78const potentialSessions = githubSessions.filter(session => session.scopes.includes('repo'));79githubAccessToken = potentialSessions[0]?.accessToken;80} catch (e) {81// Ignore82}8384// air on the side of caution and have false be the default85let isUnsupported = false;86try {87isUnsupported = !(await this.integrityService.isPure()).isPure;88} catch (e) {89// Ignore90}9192const theme = this.themeService.getColorTheme();93const issueReporterData: IssueReporterData = Object.assign({94styles: getIssueReporterStyles(theme),95zoomLevel: getZoomLevel(mainWindow),96enabledExtensions: extensionData,97experiments: experiments?.join('\n'),98restrictedMode: !this.workspaceTrustManagementService.isWorkspaceTrusted(),99isUnsupported,100githubAccessToken101}, dataOverrides);102103return this.issueFormService.openReporter(issueReporterData);104}105106}107108export function getIssueReporterStyles(theme: IColorTheme): IssueReporterStyles {109return {110backgroundColor: getColor(theme, SIDE_BAR_BACKGROUND),111color: getColor(theme, foreground),112textLinkColor: getColor(theme, textLinkForeground),113textLinkActiveForeground: getColor(theme, textLinkActiveForeground),114inputBackground: getColor(theme, inputBackground),115inputForeground: getColor(theme, inputForeground),116inputBorder: getColor(theme, inputBorder),117inputActiveBorder: getColor(theme, inputActiveOptionBorder),118inputErrorBorder: getColor(theme, inputValidationErrorBorder),119inputErrorBackground: getColor(theme, inputValidationErrorBackground),120inputErrorForeground: getColor(theme, inputValidationErrorForeground),121buttonBackground: getColor(theme, buttonBackground),122buttonForeground: getColor(theme, buttonForeground),123buttonHoverBackground: getColor(theme, buttonHoverBackground),124sliderActiveColor: getColor(theme, scrollbarSliderActiveBackground),125sliderBackgroundColor: getColor(theme, SIDE_BAR_BACKGROUND),126sliderHoverColor: getColor(theme, scrollbarSliderHoverBackground),127};128}129130function getColor(theme: IColorTheme, key: string): string | undefined {131const color = theme.getColor(key);132return color ? color.toString() : undefined;133}134135registerSingleton(IWorkbenchIssueService, NativeIssueService, InstantiationType.Delayed);136137138