2015-08-22 02:56:32 +03:00
|
|
|
(function () {
|
|
|
|
var path = require('path')
|
2015-10-30 20:42:38 +03:00
|
|
|
var FileSystemBlobStore = require('../src/file-system-blob-store')
|
2015-10-30 13:36:58 +03:00
|
|
|
var NativeCompileCache = require('../src/native-compile-cache')
|
2015-05-14 19:54:22 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
var loadSettings = null
|
|
|
|
var loadSettingsError = null
|
2015-11-03 11:51:08 +03:00
|
|
|
var blobStore = null
|
2015-02-13 00:31:49 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
window.onload = function () {
|
|
|
|
try {
|
|
|
|
var startTime = Date.now()
|
2015-05-13 19:47:10 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
process.on('unhandledRejection', function (error, promise) {
|
|
|
|
console.error('Unhandled promise rejection %o with error: %o', promise, error)
|
|
|
|
})
|
2014-10-13 19:17:26 +04:00
|
|
|
|
2015-11-03 11:51:08 +03:00
|
|
|
blobStore = FileSystemBlobStore.load(
|
2015-10-30 20:42:38 +03:00
|
|
|
path.join(process.env.ATOM_HOME, 'blob-store/')
|
2015-10-27 16:03:00 +03:00
|
|
|
)
|
2015-11-03 11:51:08 +03:00
|
|
|
NativeCompileCache.setCacheStore(blobStore)
|
2015-12-11 19:47:04 +03:00
|
|
|
NativeCompileCache.setV8Version(process.versions.v8)
|
2015-10-27 16:03:00 +03:00
|
|
|
NativeCompileCache.install()
|
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
// Normalize to make sure drive letter case is consistent on Windows
|
|
|
|
process.resourcesPath = path.normalize(process.resourcesPath)
|
2015-02-13 00:31:49 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
if (loadSettingsError) {
|
|
|
|
throw loadSettingsError
|
|
|
|
}
|
2014-10-30 20:30:10 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
var devMode = loadSettings.devMode || !loadSettings.resourcePath.startsWith(process.resourcesPath + path.sep)
|
2015-05-13 19:47:10 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
if (devMode) {
|
|
|
|
setupDeprecatedPackages()
|
|
|
|
}
|
2014-10-29 20:21:23 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
if (loadSettings.profileStartup) {
|
|
|
|
profileStartup(loadSettings, Date.now() - startTime)
|
|
|
|
} else {
|
|
|
|
setupWindow(loadSettings)
|
|
|
|
setLoadTime(Date.now() - startTime)
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
handleSetupError(error)
|
2015-06-04 02:11:16 +03:00
|
|
|
}
|
2015-08-22 02:56:32 +03:00
|
|
|
}
|
2015-06-04 02:11:16 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
function setLoadTime (loadTime) {
|
|
|
|
if (global.atom) {
|
|
|
|
global.atom.loadTime = loadTime
|
|
|
|
console.log('Window load time: ' + global.atom.getWindowLoadTime() + 'ms')
|
2014-10-13 19:17:26 +04:00
|
|
|
}
|
2014-03-05 19:03:27 +04:00
|
|
|
}
|
2015-02-13 00:31:49 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
function handleSetupError (error) {
|
2015-12-23 04:44:51 +03:00
|
|
|
var currentWindow = require('electron').remote.getCurrentWindow()
|
2015-08-22 02:56:32 +03:00
|
|
|
currentWindow.setSize(800, 600)
|
|
|
|
currentWindow.center()
|
|
|
|
currentWindow.show()
|
|
|
|
currentWindow.openDevTools()
|
|
|
|
console.error(error.stack || error)
|
2015-04-29 03:42:15 +03:00
|
|
|
}
|
2015-08-22 02:56:32 +03:00
|
|
|
|
|
|
|
function setupWindow (loadSettings) {
|
|
|
|
var CompileCache = require('../src/compile-cache')
|
2015-11-04 01:36:49 +03:00
|
|
|
CompileCache.setAtomHomeDirectory(process.env.ATOM_HOME)
|
2015-08-22 02:56:32 +03:00
|
|
|
|
|
|
|
var ModuleCache = require('../src/module-cache')
|
|
|
|
ModuleCache.register(loadSettings)
|
|
|
|
ModuleCache.add(loadSettings.resourcePath)
|
|
|
|
|
|
|
|
// Start the crash reporter before anything else.
|
2015-12-23 04:44:51 +03:00
|
|
|
require('electron').crashReporter.start({
|
2015-08-22 02:56:32 +03:00
|
|
|
productName: 'Atom',
|
|
|
|
companyName: 'GitHub',
|
2015-12-23 04:44:51 +03:00
|
|
|
submitURL: 'http://54.249.141.255:1127/post',
|
2015-08-22 02:56:32 +03:00
|
|
|
// By explicitly passing the app version here, we could save the call
|
|
|
|
// of "require('remote').require('app').getVersion()".
|
|
|
|
extra: {_version: loadSettings.appVersion}
|
|
|
|
})
|
|
|
|
|
|
|
|
setupVmCompatibility()
|
|
|
|
setupCsonCache(CompileCache.getCacheDirectory())
|
|
|
|
|
2015-11-03 11:51:08 +03:00
|
|
|
var initialize = require(loadSettings.windowInitializationScript)
|
|
|
|
initialize({blobStore: blobStore})
|
2015-12-11 05:03:20 +03:00
|
|
|
require('electron').ipcRenderer.send('window-command', 'window:loaded')
|
2015-08-22 02:56:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function setupCsonCache (cacheDir) {
|
|
|
|
require('season').setCacheDir(path.join(cacheDir, 'cson'))
|
|
|
|
}
|
2015-08-21 23:35:52 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
function setupVmCompatibility () {
|
|
|
|
var vm = require('vm')
|
|
|
|
if (!vm.Script.createContext) {
|
|
|
|
vm.Script.createContext = vm.createContext
|
|
|
|
}
|
2015-05-13 19:50:11 +03:00
|
|
|
}
|
2015-04-28 04:13:35 +03:00
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
function setupDeprecatedPackages () {
|
|
|
|
var metadata = require('../package.json')
|
|
|
|
if (!metadata._deprecatedPackages) {
|
|
|
|
try {
|
|
|
|
metadata._deprecatedPackages = require('../build/deprecated-packages.json')
|
2016-01-08 01:13:56 +03:00
|
|
|
} catch (requireError) {
|
2015-08-22 02:56:32 +03:00
|
|
|
console.error('Failed to setup deprecated packages list', requireError.stack)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function profileStartup (loadSettings, initialTime) {
|
|
|
|
function profile () {
|
|
|
|
console.profile('startup')
|
|
|
|
try {
|
|
|
|
var startTime = Date.now()
|
|
|
|
setupWindow(loadSettings)
|
|
|
|
setLoadTime(Date.now() - startTime + initialTime)
|
|
|
|
} catch (error) {
|
|
|
|
handleSetupError(error)
|
|
|
|
} finally {
|
|
|
|
console.profileEnd('startup')
|
|
|
|
console.log('Switch to the Profiles tab to view the created startup profile')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 04:44:51 +03:00
|
|
|
var currentWindow = require('electron').remote.getCurrentWindow()
|
2015-08-22 02:56:32 +03:00
|
|
|
if (currentWindow.devToolsWebContents) {
|
|
|
|
profile()
|
|
|
|
} else {
|
|
|
|
currentWindow.openDevTools()
|
|
|
|
currentWindow.once('devtools-opened', function () {
|
2015-10-21 13:06:32 +03:00
|
|
|
setTimeout(profile, 1000)
|
2015-08-22 02:56:32 +03:00
|
|
|
})
|
2015-06-04 02:11:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
function parseLoadSettings () {
|
|
|
|
var rawLoadSettings = decodeURIComponent(window.location.hash.substr(1))
|
2015-04-28 04:28:29 +03:00
|
|
|
try {
|
2015-08-22 02:56:32 +03:00
|
|
|
loadSettings = JSON.parse(rawLoadSettings)
|
2015-04-28 04:28:29 +03:00
|
|
|
} catch (error) {
|
2015-08-22 02:56:32 +03:00
|
|
|
console.error('Failed to parse load settings: ' + rawLoadSettings)
|
|
|
|
loadSettingsError = error
|
2015-04-28 04:28:29 +03:00
|
|
|
}
|
2015-05-13 19:47:10 +03:00
|
|
|
}
|
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
function setupWindowBackground () {
|
|
|
|
if (loadSettings && loadSettings.isSpec) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var backgroundColor = window.localStorage.getItem('atom:window-background-color')
|
|
|
|
if (!backgroundColor) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var backgroundStylesheet = document.createElement('style')
|
|
|
|
backgroundStylesheet.type = 'text/css'
|
2015-10-15 12:05:12 +03:00
|
|
|
backgroundStylesheet.innerText = 'html, body { background: ' + backgroundColor + ' !important; }'
|
2015-08-22 02:56:32 +03:00
|
|
|
document.head.appendChild(backgroundStylesheet)
|
|
|
|
|
|
|
|
// Remove once the page loads
|
|
|
|
window.addEventListener('load', function loadWindow () {
|
|
|
|
window.removeEventListener('load', loadWindow, false)
|
|
|
|
setTimeout(function () {
|
|
|
|
backgroundStylesheet.remove()
|
|
|
|
backgroundStylesheet = null
|
|
|
|
}, 1000)
|
|
|
|
}, false)
|
2015-05-13 19:47:10 +03:00
|
|
|
}
|
|
|
|
|
2015-11-04 01:35:30 +03:00
|
|
|
var setupAtomHome = function () {
|
2015-11-04 01:36:06 +03:00
|
|
|
if (process.env.ATOM_HOME) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-11-04 01:35:30 +03:00
|
|
|
// Ensure ATOM_HOME is always set before anything else is required
|
|
|
|
// This is because of a difference in Linux not inherited between browser and render processes
|
2015-11-04 02:34:42 +03:00
|
|
|
// https://github.com/atom/atom/issues/5412
|
2015-11-04 01:35:30 +03:00
|
|
|
if (loadSettings && loadSettings.atomHome) {
|
|
|
|
process.env.ATOM_HOME = loadSettings.atomHome
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 02:56:32 +03:00
|
|
|
parseLoadSettings()
|
2015-11-04 01:35:30 +03:00
|
|
|
setupAtomHome()
|
2015-08-22 02:56:32 +03:00
|
|
|
setupWindowBackground()
|
|
|
|
})()
|