-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathstart.js
146 lines (120 loc) · 4.07 KB
/
start.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const { app } = require('electron');
const path = require('path');
const temp = require('temp');
const parseCommandLine = require('./parse-command-line');
const { getReleaseChannel, getConfigFilePath } = require('../get-app-details.js');
const atomPaths = require('../atom-paths');
const fs = require('fs');
const CSON = require('season');
const Config = require('../config');
const StartupTime = require('../startup-time');
StartupTime.setStartTime();
module.exports = function start(resourcePath, devResourcePath, startTime) {
global.shellStartTime = startTime;
StartupTime.addMarker('main-process:start');
process.on('uncaughtException', function(error = {}) {
if (error.message != null) {
console.log(error.message);
}
if (error.stack != null) {
console.log(error.stack);
}
});
process.on('unhandledRejection', function(error = {}) {
if (error.message != null) {
console.log(error.message);
}
if (error.stack != null) {
console.log(error.stack);
}
});
// TodoElectronIssue this should be set to true before Electron 12 - https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = false;
app.commandLine.appendSwitch('enable-experimental-web-platform-features');
const args = parseCommandLine(process.argv.slice(1));
args.resourcePath = normalizeDriveLetterName(resourcePath);
args.devResourcePath = normalizeDriveLetterName(devResourcePath);
atomPaths.setAtomHome(app.getPath('home'));
atomPaths.setUserData(app);
const config = getConfig();
const colorProfile = config.get('core.colorProfile');
if (colorProfile && colorProfile !== 'default') {
app.commandLine.appendSwitch('force-color-profile', colorProfile);
}
if (args.test && args.mainProcess) {
app.setPath(
'userData',
temp.mkdirSync('atom-user-data-dir-for-main-process-tests')
);
app.on('ready', function() {
const testRunner = require(path.join(
args.resourcePath,
'spec/main-process/mocha-test-runner'
));
testRunner(args.pathsToOpen);
});
return;
}
const releaseChannel = getReleaseChannel(app.getVersion());
let appUserModelId = 'dev.pulsar-edit.pulsar.' + process.arch;
// If the release channel is not stable, we append it to the app user model id.
// This allows having the different release channels as separate items in the taskbar.
if (releaseChannel !== 'stable') {
appUserModelId += `-${releaseChannel}`;
}
// NB: This prevents Win10 from showing dupe items in the taskbar.
app.setAppUserModelId(appUserModelId);
function addPathToOpen(event, pathToOpen) {
event.preventDefault();
args.pathsToOpen.push(pathToOpen);
}
function addUrlToOpen(event, urlToOpen) {
event.preventDefault();
args.urlsToOpen.push(urlToOpen);
}
app.on('open-file', addPathToOpen);
app.on('open-url', addUrlToOpen);
if (args.userDataDir != null) {
app.setPath('userData', args.userDataDir);
} else if (args.test) {
app.setPath('userData', temp.mkdirSync('atom-test-data'));
}
StartupTime.addMarker('main-process:electron-onready:start');
app.on('ready', function() {
StartupTime.addMarker('main-process:electron-onready:end');
app.removeListener('open-file', addPathToOpen);
app.removeListener('open-url', addUrlToOpen);
const AtomApplication = require(path.join(
args.resourcePath,
'src',
'main-process',
'atom-application'
));
AtomApplication.open(args);
});
};
function getConfig() {
const config = new Config();
let configFilePath = getConfigFilePath();
if (configFilePath) {
CSON.readFile(configFilePath, (error, data) => {
// Duplicated from `./src/config-file.js`.reload()
if (error) {
console.log(error.message);
} else {
config.resetUserSettings(data);
}
});
}
return config;
}
function normalizeDriveLetterName(filePath) {
if (process.platform === 'win32' && filePath) {
return filePath.replace(
/^([a-z]):/,
([driveLetter]) => driveLetter.toUpperCase() + ':'
);
} else {
return filePath;
}
}