File size: 2,626 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* eslint-disable import/order */
const path = require( 'path' );
const { app } = require( 'electron' );
const { mkdirSync } = require( 'fs' );

/**
 * Initialize core components
 */

const state = require( './lib/state' );
const config = require( './lib/config' );
const appData = path.join( app.getPath( 'appData' ), config.appPathName );

// Initialize log path prior to requiring any modules that log
const logPath = process.env.WP_DEBUG_LOG
	? process.env.WP_DEBUG_LOG
	: path.join( appData, 'logs', 'wpdesktop-main.log' );
mkdirSync( path.dirname( logPath ), { recursive: true } );
state.setLogPath( logPath );

// Initialize settings
const Settings = require( './lib/settings' );

// Catch-all error handler
// We hook in very early to catch issues during the startup process
require( './app-handlers/exceptions' )();

// if app path set to asar, switch to the dir, not file
let apppath = app.getAppPath();
if ( path.extname( apppath ) === '.asar' ) {
	apppath = path.dirname( apppath );
}
process.chdir( apppath );

// Set app config path
app.setPath( 'userData', appData );

// Default value of false deprecated in Electron v9
app.allowRendererProcessReuse = true;

// Fixes rendering bug on Linux when sandbox === true (Electron 11.0)
if ( process.platform === 'linux' ) {
	app.disableHardwareAcceleration();
}

// Force sandbox: true for all BrowserWindow instances
app.enableSandbox();

if ( Settings.isDebug() ) {
	process.env.DEBUG = config.debug.namespace;
}

/**
 * These setup things for Calypso. We have to do them inside the app as we can't set any env variables in the packaged release
 * This has to come after the DEBUG_* variables
 */
const log = require( './lib/logger' )( 'desktop:boot' );
log.info( `Booting ${ config.appPathName + ' v' + config.version }` );
log.info( `App Path: ${ app.getAppPath() }` );
log.info( `App Data: ${ app.getPath( 'userData' ) }` );
log.info( 'Settings:', Settings._getAll() );

if ( Settings.getSetting( 'proxy-type' ) === '' ) {
	log.info( 'Proxy: none' );
	app.commandLine.appendSwitch( 'no-proxy-server' );
} else if ( Settings.getSetting( 'proxy-type' ) === 'custom' ) {
	log.info(
		'Proxy: ' + Settings.getSetting( 'proxy-url' ) + ':' + Settings.getSetting( 'proxy-port' )
	);
	app.commandLine.appendSwitch(
		'proxy-server',
		Settings.getSetting( 'proxy-url' ) + ':' + Settings.getSetting( 'proxy-port' )
	);

	if ( Settings.getSetting( 'proxy-pac' ) !== '' ) {
		log.info( 'Proxy PAC: ' + Settings.getSetting( 'proxy-pac' ) );

		// todo: this doesnt seem to work yet
		app.commandLine.appendSwitch( 'proxy-pac-url', Settings.getSetting( 'proxy-pac' ) );
	}
}