issueService.ts 5.8 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, listHighlightForeground, 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

20
export class WorkbenchIssueService implements IWorkbenchIssueService {
21
	declare readonly _serviceBrand: undefined;
22 23

	constructor(
24 25 26
		@IIssueService private readonly issueService: IIssueService,
		@IThemeService private readonly themeService: IThemeService,
		@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
S
rename  
Sandeep Somavarapu 已提交
27
		@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
28
		@INativeWorkbenchEnvironmentService private readonly environmentService: INativeWorkbenchEnvironmentService,
29
		@IProductService private readonly productService: IProductService
30
	) { }
31

M
Matt Bierner 已提交
32
	async openReporter(dataOverrides: Partial<IssueReporterData> = {}): Promise<void> {
33
		const extensions = await this.extensionManagementService.getInstalled();
34
		const enabledExtensions = extensions.filter(extension => this.extensionEnablementService.isEnabled(extension) || (dataOverrides.extensionId && extension.identifier.id === dataOverrides.extensionId));
35
		const extensionData = enabledExtensions.map((extension): IssueReporterExtensionData => {
M
Matt Bierner 已提交
36 37 38
			const { manifest } = extension;
			const manifestKeys = manifest.contributes ? Object.keys(manifest.contributes) : [];
			const isTheme = !manifest.activationEvents && manifestKeys.length === 1 && manifestKeys[0] === 'themes';
39
			const isBuiltin = extension.type === ExtensionType.System;
M
Matt Bierner 已提交
40 41 42 43 44 45 46 47
			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,
48 49
				isTheme,
				isBuiltin,
M
Matt Bierner 已提交
50
			};
51
		});
M
Matt Bierner 已提交
52
		const theme = this.themeService.getColorTheme();
53
		const issueReporterData: IssueReporterData = Object.assign({
M
Matt Bierner 已提交
54
			styles: getIssueReporterStyles(theme),
55
			zoomLevel: getZoomLevel(),
56
			enabledExtensions: extensionData,
M
Matt Bierner 已提交
57 58
		}, dataOverrides);
		return this.issueService.openReporter(issueReporterData);
59
	}
60

J
Johannes Rieken 已提交
61
	openProcessExplorer(): Promise<void> {
M
Martin Aeschlimann 已提交
62
		const theme = this.themeService.getColorTheme();
63
		const data: ProcessExplorerData = {
64
			pid: this.environmentService.configuration.mainPid,
65
			zoomLevel: getZoomLevel(),
66
			styles: {
67 68 69 70 71
				backgroundColor: getColor(theme, editorBackground),
				color: getColor(theme, editorForeground),
				hoverBackground: getColor(theme, listHoverBackground),
				hoverForeground: getColor(theme, listHoverForeground),
				highlightForeground: getColor(theme, listHighlightForeground),
72
			},
73
			platform: process.platform,
74
			applicationName: this.productService.applicationName
75 76 77
		};
		return this.issueService.openProcessExplorer(data);
	}
78 79
}

M
Martin Aeschlimann 已提交
80
export function getIssueReporterStyles(theme: IColorTheme): IssueReporterStyles {
81
	return {
82 83 84 85 86 87 88 89 90
		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),
91 92
		inputErrorBackground: getColor(theme, inputValidationErrorBackground),
		inputErrorForeground: getColor(theme, inputValidationErrorForeground),
93 94 95 96 97 98
		buttonBackground: getColor(theme, buttonBackground),
		buttonForeground: getColor(theme, buttonForeground),
		buttonHoverBackground: getColor(theme, buttonHoverBackground),
		sliderActiveColor: getColor(theme, scrollbarSliderActiveBackground),
		sliderBackgroundColor: getColor(theme, scrollbarSliderBackground),
		sliderHoverColor: getColor(theme, scrollbarSliderHoverBackground),
99 100
	};
}
101

M
Martin Aeschlimann 已提交
102
function getColor(theme: IColorTheme, key: string): string | undefined {
103 104 105
	const color = theme.getColor(key);
	return color ? color.toString() : undefined;
}