@@ -12,6 +12,8 @@ const lp = require('./vs/base/node/languagePacks');
1212perf . mark ( 'main:started' ) ;
1313
1414const path = require ( 'path' ) ;
15+ const fs = require ( 'fs' ) ;
16+ const os = require ( 'os' ) ;
1517const bootstrap = require ( './bootstrap' ) ;
1618const paths = require ( './paths' ) ;
1719// @ts -ignore
@@ -113,16 +115,97 @@ async function onReady() {
113115 */
114116function configureCommandlineSwitches ( cliArgs ) {
115117
116- // Force pre-Chrome-60 color profile handling (for https://github.com/Microsoft/vscode/issues/51791)
117- app . commandLine . appendSwitch ( 'disable-color-correct-rendering' ) ;
118+ // Read argv config
119+ const argvConfig = readArgvConfig ( ) ;
120+
121+ // Append each flag to Electron
122+ Object . keys ( argvConfig ) . forEach ( flag => {
123+ const value = argvConfig [ flag ] ;
124+ if ( value === true || value === 'true' ) {
125+ if ( flag === 'disable-gpu' ) {
126+ app . disableHardwareAcceleration ( ) ; // needs to be called explicitly
127+ }
128+
129+ app . commandLine . appendArgument ( flag ) ;
130+ } else {
131+ app . commandLine . appendSwitch ( flag , value ) ;
132+ }
133+ } ) ;
118134
119135 // Support JS Flags
120136 const jsFlags = getJSFlags ( cliArgs ) ;
121137 if ( jsFlags ) {
122- app . commandLine . appendSwitch ( '-- js-flags' , jsFlags ) ;
138+ app . commandLine . appendSwitch ( 'js-flags' , jsFlags ) ;
123139 }
124140}
125141
142+ function readArgvConfig ( ) {
143+
144+ // Read or create the argv.json config file sync before app('ready')
145+ const argvConfigPath = getArgvConfigPath ( ) ;
146+ let argvConfig ;
147+ try {
148+ argvConfig = JSON . parse ( stripComments ( fs . readFileSync ( argvConfigPath ) . toString ( ) ) ) ;
149+ } catch ( error ) {
150+ if ( error && error . code === 'ENOENT' ) {
151+ try {
152+ const argvConfigPathDirname = path . dirname ( argvConfigPath ) ;
153+ if ( ! fs . existsSync ( argvConfigPathDirname ) ) {
154+ fs . mkdirSync ( argvConfigPathDirname ) ;
155+ }
156+
157+ // Create initial argv.json if not existing
158+ fs . writeFileSync ( argvConfigPath , `// This configuration file allows to pass permanent command line arguments to VSCode.
159+ //
160+ // PLEASE DO NOT CHANGE WITHOUT UNDERSTANDING THE IMPACT
161+ //
162+ // If the command line argument does not have any values, simply assign
163+ // it in the JSON below with a value of 'true'. Otherwise, put the value
164+ // directly.
165+ //
166+ // If you see rendering issues in VSCode and have a better experience
167+ // with software rendering, you can configure this by adding:
168+ //
169+ // 'disable-gpu': true
170+ //
171+ // NOTE: Changing this file requires a restart of VSCode.
172+ {
173+ // Enabled by default by VSCode to resolve color issues in the renderer
174+ // See https://github.com/Microsoft/vscode/issues/51791 for details
175+ "disable-color-correct-rendering": true
176+ }` ) ;
177+ } catch ( error ) {
178+ console . error ( `Unable to create argv.json configuration file in ${ argvConfigPath } , falling back to defaults (${ error } )` ) ;
179+ }
180+ } else {
181+ console . warn ( `Unable to read argv.json configuration file in ${ argvConfigPath } , falling back to defaults (${ error } )` ) ;
182+ }
183+ }
184+
185+ // Fallback to default
186+ if ( ! argvConfig ) {
187+ argvConfig = {
188+ 'disable-color-correct-rendering' : true // Force pre-Chrome-60 color profile handling (for https://github.com/Microsoft/vscode/issues/51791)
189+ } ;
190+ }
191+
192+ return argvConfig ;
193+ }
194+
195+ function getArgvConfigPath ( ) {
196+ const vscodePortable = process . env [ 'VSCODE_PORTABLE' ] ;
197+ if ( vscodePortable ) {
198+ return path . join ( vscodePortable , 'argv.json' ) ;
199+ }
200+
201+ let dataFolderName = product . dataFolderName ;
202+ if ( process . env [ 'VSCODE_DEV' ] ) {
203+ dataFolderName = `${ dataFolderName } -dev` ;
204+ }
205+
206+ return path . join ( os . homedir ( ) , dataFolderName , 'argv.json' ) ;
207+ }
208+
126209/**
127210 * @param {ParsedArgs } cliArgs
128211 * @returns {string }
0 commit comments