issueService.ts 6.5 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6 7
import { IssueReporterStyles, IssueReporterData, ProcessExplorerData, IssueReporterExtensionData } from 'vs/platform/issue/common/issue';
import { IIssueService } from 'vs/platform/issue/electron-sandbox/issue';
M
Martin Aeschlimann 已提交
8
import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService';
9
import { textLinkForeground, inputBackground, inputBorder, inputForeground, buttonBackground, buttonHoverBackground, buttonForeground, inputValidationErrorBorder, foreground, inputActiveOptionBorder, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, editorBackground, editorForeground, listHoverBackground, listHoverForeground, textLinkActiveForeground, inputValidationErrorBackground, inputValidationErrorForeground } from 'vs/platform/theme/common/colorRegistry';
10
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
11
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
S
rename  
Sandeep Somavarapu 已提交
12
import { IWorkbenchExtensionEnablementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
13
import { getZoomLevel } from 'vs/base/browser/browser';
14
import { IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
15
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
16
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
17
import { process } from 'vs/base/parts/sandbox/electron-sandbox/globals';
18
import { IProductService } from 'vs/platform/product/common/productService';
19
import { ITASExperimentService } from 'vs/workbench/services/experiment/common/experimentService';
20
import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
21

22
export class WorkbenchIssueService implements IWorkbenchIssueService {
23
	declare readonly _serviceBrand: undefined;
24 25

	constructor(
26 27 28
		@IIssueService private readonly issueService: IIssueService,
		@IThemeService private readonly themeService: IThemeService,
		@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
S
rename  
Sandeep Somavarapu 已提交
29
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
30
		@INativeWorkbenchEnvironmentService private readonly environmentService: INativeWorkbenchEnvironmentService,
31
		@IProductService private readonly productService: IProductService,
32 33
		@ITASExperimentService private readonly experimentService: ITASExperimentService,
		@IAuthenticationService private readonly authenticationService: IAuthenticationService
34
	) { }
35

M
Matt Bierner 已提交
36
	async openReporter(dataOverrides: Partial<IssueReporterData> = {}): Promise<void> {
37
		const extensions = await this.extensionManagementService.getInstalled();
38
		const enabledExtensions = extensions.filter(extension => this.extensionEnablementService.isEnabled(extension) || (dataOverrides.extensionId && extension.identifier.id === dataOverrides.extensionId));
39
		const extensionData = enabledExtensions.map((extension): IssueReporterExtensionData => {
M
Matt Bierner 已提交
40 41 42
			const { manifest } = extension;
			const manifestKeys = manifest.contributes ? Object.keys(manifest.contributes) : [];
			const isTheme = !manifest.activationEvents && manifestKeys.length === 1 && manifestKeys[0] === 'themes';
43
			const isBuiltin = extension.type === ExtensionType.System;
M
Matt Bierner 已提交
44 45 46 47 48 49 50 51
			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,
52 53
				isTheme,
				isBuiltin,
M
Matt Bierner 已提交
54
			};
55
		});
56
		const experiments = await this.experimentService.getCurrentExperiments();
57 58
		const githubSessions = await this.authenticationService.getSessions('github');
		const potentialSessions = githubSessions.filter(session => session.scopes.includes('repo'));
M
Matt Bierner 已提交
59
		const theme = this.themeService.getColorTheme();
60
		const issueReporterData: IssueReporterData = Object.assign({
M
Matt Bierner 已提交
61
			styles: getIssueReporterStyles(theme),
62
			zoomLevel: getZoomLevel(),
63
			enabledExtensions: extensionData,
64 65
			experiments: experiments?.join('\n'),
			githubAccessToken: potentialSessions[0]?.accessToken
M
Matt Bierner 已提交
66 67
		}, dataOverrides);
		return this.issueService.openReporter(issueReporterData);
68
	}
69

J
Johannes Rieken 已提交
70
	openProcessExplorer(): Promise<void> {
M
Martin Aeschlimann 已提交
71
		const theme = this.themeService.getColorTheme();
72
		const data: ProcessExplorerData = {
73
			pid: this.environmentService.configuration.mainPid,
74
			zoomLevel: getZoomLevel(),
75
			styles: {
76 77 78
				backgroundColor: getColor(theme, editorBackground),
				color: getColor(theme, editorForeground),
				hoverBackground: getColor(theme, listHoverBackground),
79
				hoverForeground: getColor(theme, listHoverForeground)
80
			},
81
			platform: process.platform,
82
			applicationName: this.productService.applicationName
83 84 85
		};
		return this.issueService.openProcessExplorer(data);
	}
86 87
}

M
Martin Aeschlimann 已提交
88
export function getIssueReporterStyles(theme: IColorTheme): IssueReporterStyles {
89
	return {
90 91 92 93 94 95 96 97 98
		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),
99 100
		inputErrorBackground: getColor(theme, inputValidationErrorBackground),
		inputErrorForeground: getColor(theme, inputValidationErrorForeground),
101 102 103 104 105 106
		buttonBackground: getColor(theme, buttonBackground),
		buttonForeground: getColor(theme, buttonForeground),
		buttonHoverBackground: getColor(theme, buttonHoverBackground),
		sliderActiveColor: getColor(theme, scrollbarSliderActiveBackground),
		sliderBackgroundColor: getColor(theme, scrollbarSliderBackground),
		sliderHoverColor: getColor(theme, scrollbarSliderHoverBackground),
107 108
	};
}
109

M
Martin Aeschlimann 已提交
110
function getColor(theme: IColorTheme, key: string): string | undefined {
111 112 113
	const color = theme.getColor(key);
	return color ? color.toString() : undefined;
}