1
1
import { inject , injectable } from '@theia/core/shared/inversify' ;
2
- import { app , BrowserWindow , BrowserWindowConstructorOptions , ipcMain , screen , Event as ElectronEvent } from '@theia/core/electron-shared/electron' ;
2
+ import {
3
+ app ,
4
+ BrowserWindow ,
5
+ BrowserWindowConstructorOptions ,
6
+ contentTracing ,
7
+ ipcMain ,
8
+ screen ,
9
+ Event as ElectronEvent ,
10
+ } from '@theia/core/electron-shared/electron' ;
3
11
import { fork } from 'child_process' ;
4
12
import { AddressInfo } from 'net' ;
5
13
import { join , dirname } from 'path' ;
@@ -46,7 +54,15 @@ const APP_STARTED_WITH_NOSPLASH =
46
54
* If the app is started with `--open-devtools` argument, the `Dev Tools` will be opened.
47
55
*/
48
56
const APP_STARTED_WITH_DEV_TOOLS =
49
- typeof process !== 'undefined' && process . argv . indexOf ( '--open-devtools' ) !== - 1 ;
57
+ typeof process !== 'undefined' &&
58
+ process . argv . indexOf ( '--open-devtools' ) !== - 1 ;
59
+
60
+ /**
61
+ * If the app is started with `--content-trace` argument, the `Dev Tools` will be opened and content tracing will start.
62
+ */
63
+ const APP_STARTED_WITH_CONTENT_TRACE =
64
+ typeof process !== 'undefined' &&
65
+ process . argv . indexOf ( '--content-trace' ) !== - 1 ;
50
66
51
67
@injectable ( )
52
68
export class ElectronMainApplication extends TheiaElectronMainApplication {
@@ -62,7 +78,68 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
62
78
// Regression in Theia: https://github.com/eclipse-theia/theia/issues/8701
63
79
app . on ( 'ready' , ( ) => app . setName ( config . applicationName ) ) ;
64
80
this . attachFileAssociations ( ) ;
65
- return super . start ( config ) ;
81
+ this . useNativeWindowFrame = this . getTitleBarStyle ( config ) === 'native' ;
82
+ this . _config = config ;
83
+ this . hookApplicationEvents ( ) ;
84
+ const [ port ] = await Promise . all ( [ this . startBackend ( ) , app . whenReady ( ) ] ) ;
85
+ this . startContentTracing ( ) ;
86
+ this . _backendPort . resolve ( port ) ;
87
+ await Promise . all ( [
88
+ this . attachElectronSecurityToken ( port ) ,
89
+ this . startContributions ( ) ,
90
+ ] ) ;
91
+ return this . launch ( {
92
+ secondInstance : false ,
93
+ argv : this . processArgv . getProcessArgvWithoutBin ( process . argv ) ,
94
+ cwd : process . cwd ( ) ,
95
+ } ) ;
96
+ }
97
+
98
+ private startContentTracing ( ) : void {
99
+ if ( ! APP_STARTED_WITH_CONTENT_TRACE ) {
100
+ return ;
101
+ }
102
+ if ( ! app . isReady ( ) ) {
103
+ throw new Error (
104
+ 'Cannot start content tracing when the electron app is not ready.'
105
+ ) ;
106
+ }
107
+ const defaultTraceCategories : Readonly < Array < string > > = [
108
+ '-*' ,
109
+ 'devtools.timeline' ,
110
+ 'disabled-by-default-devtools.timeline' ,
111
+ 'disabled-by-default-devtools.timeline.frame' ,
112
+ 'toplevel' ,
113
+ 'blink.console' ,
114
+ 'disabled-by-default-devtools.timeline.stack' ,
115
+ 'disabled-by-default-v8.cpu_profile' ,
116
+ 'disabled-by-default-v8.cpu_profiler' ,
117
+ 'disabled-by-default-v8.cpu_profiler.hires' ,
118
+ ] ;
119
+ const traceOptions = {
120
+ categoryFilter : defaultTraceCategories . join ( ',' ) ,
121
+ traceOptions : 'record-until-full' ,
122
+ options : 'sampling-frequency=10000' ,
123
+ } ;
124
+ ( async ( ) => {
125
+ const appPath = app . getAppPath ( ) ;
126
+ let traceFile : string | undefined ;
127
+ if ( appPath ) {
128
+ const tracesPath = join ( appPath , 'traces' ) ;
129
+ await fs . promises . mkdir ( tracesPath , { recursive : true } ) ;
130
+ traceFile = join ( tracesPath , `trace-${ new Date ( ) . toISOString ( ) } .trace` ) ;
131
+ }
132
+ console . log ( '>>> Content tracing has started...' ) ;
133
+ await contentTracing . startRecording ( traceOptions ) ;
134
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 10_000 ) ) ;
135
+ contentTracing
136
+ . stopRecording ( traceFile )
137
+ . then ( ( out ) =>
138
+ console . log (
139
+ `<<< Content tracing has finished. The trace data was written to: ${ out } .`
140
+ )
141
+ ) ;
142
+ } ) ( ) ;
66
143
}
67
144
68
145
attachFileAssociations ( ) {
@@ -164,7 +241,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
164
241
return super . avoidOverlap ( options ) ;
165
242
}
166
243
167
- protected override getTitleBarStyle ( ) : 'native' | 'custom' {
244
+ protected override getTitleBarStyle ( config : FrontendApplicationConfig ) : 'native' | 'custom' {
168
245
return 'native' ;
169
246
}
170
247
0 commit comments