3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { BrowserWindow , BrowserWindowConstructorOptions , contentTracing , Display , IpcMainEvent , screen } from 'electron' ;
6
+ import { BrowserWindow , BrowserWindowConstructorOptions , Display , screen } from 'electron' ;
7
7
import { arch , release , type } from 'os' ;
8
8
import { raceTimeout } from 'vs/base/common/async' ;
9
9
import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
10
- import { randomPath } from 'vs/base/common/extpath' ;
11
10
import { DisposableStore } from 'vs/base/common/lifecycle' ;
12
11
import { FileAccess } from 'vs/base/common/network' ;
13
12
import { IProcessEnvironment , isMacintosh } from 'vs/base/common/platform' ;
14
- import { listProcesses } from 'vs/base/node/ps' ;
15
13
import { validatedIpcMain } from 'vs/base/parts/ipc/electron-main/ipcMain' ;
16
14
import { localize } from 'vs/nls' ;
17
- import { IDiagnosticsService , isRemoteDiagnosticError , PerformanceInfo , SystemInfo } from 'vs/platform/diagnostics/common/diagnostics' ;
18
- import { IDiagnosticsMainService } from 'vs/platform/diagnostics/electron-main/diagnosticsMainService' ;
19
15
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService' ;
20
16
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService' ;
21
- import { IIssueMainService , IssueReporterData , IssueReporterWindowConfiguration , ProcessExplorerData , ProcessExplorerWindowConfiguration } from 'vs/platform/issue/common/issue' ;
17
+ import { IIssueMainService , IssueReporterData , IssueReporterWindowConfiguration } from 'vs/platform/issue/common/issue' ;
22
18
import { ILogService } from 'vs/platform/log/common/log' ;
23
19
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService' ;
24
20
import product from 'vs/platform/product/common/product' ;
25
- import { IProductService } from 'vs/platform/product/common/productService' ;
26
21
import { IIPCObjectUrl , IProtocolMainService } from 'vs/platform/protocol/electron-main/protocol' ;
27
- import { IStateService } from 'vs/platform/state/node/state' ;
28
- import { UtilityProcess } from 'vs/platform/utilityProcess/electron-main/utilityProcess' ;
29
22
import { zoomLevelToZoomFactor } from 'vs/platform/window/common/window' ;
30
23
import { ICodeWindow , IWindowState } from 'vs/platform/window/electron-main/window' ;
31
24
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows' ;
32
25
33
- const processExplorerWindowState = 'issue.processExplorerWindowState' ;
34
-
35
26
interface IBrowserWindowOptions {
36
27
backgroundColor : string | undefined ;
37
28
title : string ;
@@ -50,94 +41,15 @@ export class IssueMainService implements IIssueMainService {
50
41
private issueReporterWindow : BrowserWindow | null = null ;
51
42
private issueReporterParentWindow : BrowserWindow | null = null ;
52
43
53
- private processExplorerWindow : BrowserWindow | null = null ;
54
- private processExplorerParentWindow : BrowserWindow | null = null ;
55
-
56
44
constructor (
57
45
private userEnv : IProcessEnvironment ,
58
46
@IEnvironmentMainService private readonly environmentMainService : IEnvironmentMainService ,
59
47
@ILogService private readonly logService : ILogService ,
60
- @IDiagnosticsService private readonly diagnosticsService : IDiagnosticsService ,
61
- @IDiagnosticsMainService private readonly diagnosticsMainService : IDiagnosticsMainService ,
62
48
@IDialogMainService private readonly dialogMainService : IDialogMainService ,
63
49
@INativeHostMainService private readonly nativeHostMainService : INativeHostMainService ,
64
50
@IProtocolMainService private readonly protocolMainService : IProtocolMainService ,
65
- @IProductService private readonly productService : IProductService ,
66
- @IStateService private readonly stateService : IStateService ,
67
51
@IWindowsMainService private readonly windowsMainService : IWindowsMainService ,
68
- ) {
69
- this . registerListeners ( ) ;
70
- }
71
-
72
- //#region Register Listeners
73
-
74
- private registerListeners ( ) : void {
75
- validatedIpcMain . on ( 'vscode:listProcesses' , async event => {
76
- const processes = [ ] ;
77
-
78
- try {
79
- processes . push ( { name : localize ( 'local' , "Local" ) , rootProcess : await listProcesses ( process . pid ) } ) ;
80
-
81
- const remoteDiagnostics = await this . diagnosticsMainService . getRemoteDiagnostics ( { includeProcesses : true } ) ;
82
- remoteDiagnostics . forEach ( data => {
83
- if ( isRemoteDiagnosticError ( data ) ) {
84
- processes . push ( {
85
- name : data . hostName ,
86
- rootProcess : data
87
- } ) ;
88
- } else {
89
- if ( data . processes ) {
90
- processes . push ( {
91
- name : data . hostName ,
92
- rootProcess : data . processes
93
- } ) ;
94
- }
95
- }
96
- } ) ;
97
- } catch ( e ) {
98
- this . logService . error ( `Listing processes failed: ${ e } ` ) ;
99
- }
100
-
101
- this . safeSend ( event , 'vscode:listProcessesResponse' , processes ) ;
102
- } ) ;
103
-
104
- validatedIpcMain . on ( 'vscode:workbenchCommand' , ( _ : unknown , commandInfo : { id : any ; from : any ; args : any } ) => {
105
- const { id, from, args } = commandInfo ;
106
-
107
- let parentWindow : BrowserWindow | null ;
108
- switch ( from ) {
109
- case 'processExplorer' :
110
- parentWindow = this . processExplorerParentWindow ;
111
- break ;
112
- default :
113
- // The issue reporter does not use this anymore.
114
- throw new Error ( `Unexpected command source: ${ from } ` ) ;
115
- }
116
-
117
- parentWindow ?. webContents . send ( 'vscode:runAction' , { id, from, args } ) ;
118
- } ) ;
119
-
120
- validatedIpcMain . on ( 'vscode:closeProcessExplorer' , event => {
121
- this . processExplorerWindow ?. close ( ) ;
122
- } ) ;
123
-
124
- validatedIpcMain . on ( 'vscode:pidToNameRequest' , async event => {
125
- const mainProcessInfo = await this . diagnosticsMainService . getMainDiagnostics ( ) ;
126
-
127
- const pidToNames : [ number , string ] [ ] = [ ] ;
128
- for ( const window of mainProcessInfo . windows ) {
129
- pidToNames . push ( [ window . pid , `window [${ window . id } ] (${ window . title } )` ] ) ;
130
- }
131
-
132
- for ( const { pid, name } of UtilityProcess . getAll ( ) ) {
133
- pidToNames . push ( [ pid , name ] ) ;
134
- }
135
-
136
- this . safeSend ( event , 'vscode:pidToNameResponse' , pidToNames ) ;
137
- } ) ;
138
- }
139
-
140
- //#endregion
52
+ ) { }
141
53
142
54
//#region Used by renderer
143
55
@@ -196,125 +108,9 @@ export class IssueMainService implements IIssueMainService {
196
108
}
197
109
}
198
110
199
- async openProcessExplorer ( data : ProcessExplorerData ) : Promise < void > {
200
- if ( ! this . processExplorerWindow ) {
201
- this . processExplorerParentWindow = BrowserWindow . getFocusedWindow ( ) ;
202
- if ( this . processExplorerParentWindow ) {
203
- const processExplorerDisposables = new DisposableStore ( ) ;
204
-
205
- const processExplorerWindowConfigUrl = processExplorerDisposables . add ( this . protocolMainService . createIPCObjectUrl < ProcessExplorerWindowConfiguration > ( ) ) ;
206
-
207
- const savedPosition = this . stateService . getItem < IWindowState > ( processExplorerWindowState , undefined ) ;
208
- const position = isStrictWindowState ( savedPosition ) ? savedPosition : this . getWindowPosition ( this . processExplorerParentWindow , 800 , 500 ) ;
209
-
210
- this . processExplorerWindow = this . createBrowserWindow ( position , processExplorerWindowConfigUrl , {
211
- backgroundColor : data . styles . backgroundColor ,
212
- title : localize ( 'processExplorer' , "Process Explorer" ) ,
213
- zoomLevel : data . zoomLevel ,
214
- alwaysOnTop : true
215
- } , 'process-explorer' ) ;
216
-
217
- // Store into config object URL
218
- processExplorerWindowConfigUrl . update ( {
219
- appRoot : this . environmentMainService . appRoot ,
220
- windowId : this . processExplorerWindow . id ,
221
- userEnv : this . userEnv ,
222
- data,
223
- product
224
- } ) ;
225
-
226
- this . processExplorerWindow . loadURL (
227
- FileAccess . asBrowserUri ( `vs/code/electron-sandbox/processExplorer/processExplorer${ this . environmentMainService . isBuilt ? '' : '-dev' } .html` ) . toString ( true )
228
- ) ;
229
-
230
- this . processExplorerWindow . on ( 'close' , ( ) => {
231
- this . processExplorerWindow = null ;
232
- processExplorerDisposables . dispose ( ) ;
233
- } ) ;
234
-
235
- this . processExplorerParentWindow . on ( 'close' , ( ) => {
236
- if ( this . processExplorerWindow ) {
237
- this . processExplorerWindow . close ( ) ;
238
- this . processExplorerWindow = null ;
239
-
240
- processExplorerDisposables . dispose ( ) ;
241
- }
242
- } ) ;
243
-
244
- const storeState = ( ) => {
245
- if ( ! this . processExplorerWindow ) {
246
- return ;
247
- }
248
- const size = this . processExplorerWindow . getSize ( ) ;
249
- const position = this . processExplorerWindow . getPosition ( ) ;
250
- if ( ! size || ! position ) {
251
- return ;
252
- }
253
- const state : IWindowState = {
254
- width : size [ 0 ] ,
255
- height : size [ 1 ] ,
256
- x : position [ 0 ] ,
257
- y : position [ 1 ]
258
- } ;
259
- this . stateService . setItem ( processExplorerWindowState , state ) ;
260
- } ;
261
-
262
- this . processExplorerWindow . on ( 'moved' , storeState ) ;
263
- this . processExplorerWindow . on ( 'resized' , storeState ) ;
264
- }
265
- }
266
-
267
- if ( this . processExplorerWindow ) {
268
- this . focusWindow ( this . processExplorerWindow ) ;
269
- }
270
- }
271
-
272
- async stopTracing ( ) : Promise < void > {
273
- if ( ! this . environmentMainService . args . trace ) {
274
- return ; // requires tracing to be on
275
- }
276
-
277
- const path = await contentTracing . stopRecording ( `${ randomPath ( this . environmentMainService . userHome . fsPath , this . productService . applicationName ) } .trace.txt` ) ;
278
-
279
- // Inform user to report an issue
280
- await this . dialogMainService . showMessageBox ( {
281
- type : 'info' ,
282
- message : localize ( 'trace.message' , "Successfully created the trace file" ) ,
283
- detail : localize ( 'trace.detail' , "Please create an issue and manually attach the following file:\n{0}" , path ) ,
284
- buttons : [ localize ( { key : 'trace.ok' , comment : [ '&& denotes a mnemonic' ] } , "&&OK" ) ] ,
285
- } , BrowserWindow . getFocusedWindow ( ) ?? undefined ) ;
286
-
287
- // Show item in explorer
288
- this . nativeHostMainService . showItemInFolder ( undefined , path ) ;
289
- }
290
-
291
- async getSystemStatus ( ) : Promise < string > {
292
- const [ info , remoteData ] = await Promise . all ( [ this . diagnosticsMainService . getMainDiagnostics ( ) , this . diagnosticsMainService . getRemoteDiagnostics ( { includeProcesses : false , includeWorkspaceMetadata : false } ) ] ) ;
293
-
294
- return this . diagnosticsService . getDiagnostics ( info , remoteData ) ;
295
- }
296
-
297
111
//#endregion
298
112
299
113
//#region used by issue reporter window
300
-
301
- async $getSystemInfo ( ) : Promise < SystemInfo > {
302
- const [ info , remoteData ] = await Promise . all ( [ this . diagnosticsMainService . getMainDiagnostics ( ) , this . diagnosticsMainService . getRemoteDiagnostics ( { includeProcesses : false , includeWorkspaceMetadata : false } ) ] ) ;
303
- const msg = await this . diagnosticsService . getSystemInfo ( info , remoteData ) ;
304
- return msg ;
305
- }
306
-
307
- async $getPerformanceInfo ( ) : Promise < PerformanceInfo > {
308
- try {
309
- const [ info , remoteData ] = await Promise . all ( [ this . diagnosticsMainService . getMainDiagnostics ( ) , this . diagnosticsMainService . getRemoteDiagnostics ( { includeProcesses : true , includeWorkspaceMetadata : true } ) ] ) ;
310
- return await this . diagnosticsService . getPerformanceInfo ( info , remoteData ) ;
311
- } catch ( error ) {
312
- this . logService . warn ( 'issueService#getPerformanceInfo ' , error . message ) ;
313
-
314
- throw error ;
315
- }
316
- }
317
-
318
114
async $reloadWithExtensionsDisabled ( ) : Promise < void > {
319
115
if ( this . issueReporterParentWindow ) {
320
116
try {
@@ -389,10 +185,6 @@ export class IssueMainService implements IIssueMainService {
389
185
this . issueReporterWindow ?. close ( ) ;
390
186
}
391
187
392
- async closeProcessExplorer ( ) : Promise < void > {
393
- this . processExplorerWindow ?. close ( ) ;
394
- }
395
-
396
188
//#endregion
397
189
398
190
private focusWindow ( window : BrowserWindow ) : void {
@@ -403,12 +195,6 @@ export class IssueMainService implements IIssueMainService {
403
195
window . focus ( ) ;
404
196
}
405
197
406
- private safeSend ( event : IpcMainEvent , channel : string , ...args : unknown [ ] ) : void {
407
- if ( ! event . sender . isDestroyed ( ) ) {
408
- event . sender . send ( channel , ...args ) ;
409
- }
410
- }
411
-
412
198
private createBrowserWindow < T > ( position : IWindowState , ipcObjectUrl : IIPCObjectUrl < T > , options : IBrowserWindowOptions , windowKind : string ) : BrowserWindow {
413
199
const window = new BrowserWindow ( {
414
200
fullscreen : false ,
@@ -509,15 +295,3 @@ export class IssueMainService implements IIssueMainService {
509
295
return state ;
510
296
}
511
297
}
512
-
513
- function isStrictWindowState ( obj : unknown ) : obj is IStrictWindowState {
514
- if ( typeof obj !== 'object' || obj === null ) {
515
- return false ;
516
- }
517
- return (
518
- 'x' in obj &&
519
- 'y' in obj &&
520
- 'width' in obj &&
521
- 'height' in obj
522
- ) ;
523
- }
0 commit comments