diff --git a/src/atom.coffee b/src/atom.coffee
index 1cf63b397..0d029b61d 100644
--- a/src/atom.coffee
+++ b/src/atom.coffee
@@ -223,6 +223,8 @@ class Atom extends Model
@disposables?.dispose()
@disposables = new CompositeDisposable
+ @displayWindow() unless @inSpecMode()
+
@setBodyPlatformClass()
@loadTime = null
@@ -483,22 +485,27 @@ class Atom extends Model
# Extended: Set the full screen state of the current window.
setFullScreen: (fullScreen=false) ->
ipc.send('call-window-method', 'setFullScreen', fullScreen)
- if fullScreen then document.body.classList.add("fullscreen") else document.body.classList.remove("fullscreen")
+ if fullScreen
+ document.body.classList.add("fullscreen")
+ else
+ document.body.classList.remove("fullscreen")
# Extended: Toggle the full screen state of the current window.
toggleFullScreen: ->
@setFullScreen(not @isFullScreen())
- # Schedule the window to be shown and focused on the next tick.
+ # Restore the window to its previous dimensions and show it.
#
- # This is done in a next tick to prevent a white flicker from occurring
- # if called synchronously.
- displayWindow: ({maximize}={}) ->
+ # Also restores the full screen and maximized state on the next tick to
+ # prevent resize glitches.
+ displayWindow: ->
+ dimensions = @restoreWindowDimensions()
+ @show()
+
setImmediate =>
- @show()
@focus()
- @setFullScreen(true) if @workspace.fullScreen
- @maximize() if maximize
+ @setFullScreen(true) if @workspace?.fullScreen
+ @maximize() if dimensions?.maximized and process.platform isnt 'darwin'
# Get the dimensions of this window.
#
@@ -572,6 +579,13 @@ class Atom extends Model
dimensions = @getWindowDimensions()
@state.windowDimensions = dimensions if @isValidDimensions(dimensions)
+ storeWindowBackground: ->
+ return if @inSpecMode()
+
+ workspaceElement = @views.getView(@workspace)
+ backgroundColor = window.getComputedStyle(workspaceElement)['background-color']
+ window.localStorage.setItem('atom:window-background-color', backgroundColor)
+
# Call this method when establishing a real application window.
startEditorWindow: ->
{safeMode} = @getLoadSettings()
@@ -582,7 +596,6 @@ class Atom extends Model
CommandInstaller.installApmCommand false, (error) ->
console.warn error.message if error?
- dimensions = @restoreWindowDimensions()
@loadConfig()
@keymaps.loadBundledKeymaps()
@themes.loadBaseStylesheets()
@@ -602,12 +615,10 @@ class Atom extends Model
@openInitialEmptyEditorIfNecessary()
- maximize = dimensions?.maximized and process.platform isnt 'darwin'
- @displayWindow({maximize})
-
unloadEditorWindow: ->
return if not @project
+ @storeWindowBackground()
@state.grammars = @grammars.serialize()
@state.project = @project.serialize()
@state.workspace = @workspace.serialize()
@@ -747,7 +758,7 @@ class Atom extends Model
# Only reload stylesheets from non-theme packages
for pack in @packages.getActivePackages() when pack.getType() isnt 'theme'
pack.reloadStylesheets?()
- null
+ return
# Notify the browser project of the window's current project path
watchProjectPath: ->
diff --git a/static/index.html b/static/index.html
index 5559058dc..84e8d57d4 100644
--- a/static/index.html
+++ b/static/index.html
@@ -1,8 +1,6 @@
-
+
-
-
diff --git a/static/index.js b/static/index.js
index 0a377044e..ef61e8bce 100644
--- a/static/index.js
+++ b/static/index.js
@@ -1,6 +1,9 @@
var fs = require('fs');
var path = require('path');
+var loadSettings = null;
+var loadSettingsError = null;
+
window.onload = function() {
try {
var startTime = Date.now();
@@ -12,30 +15,19 @@ window.onload = function() {
// Ensure ATOM_HOME is always set before anything else is required
setupAtomHome();
- var cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache');
- // Use separate compile cache when sudo'ing as root to avoid permission issues
- if (process.env.USER === 'root' && process.env.SUDO_USER && process.env.SUDO_USER !== process.env.USER) {
- cacheDir = path.join(cacheDir, 'root');
- }
-
- var rawLoadSettings = decodeURIComponent(location.hash.substr(1));
- var loadSettings;
- try {
- loadSettings = JSON.parse(rawLoadSettings);
- } catch (error) {
- console.error("Failed to parse load settings: " + rawLoadSettings);
- throw error;
- }
-
// Normalize to make sure drive letter case is consistent on Windows
process.resourcesPath = path.normalize(process.resourcesPath);
+ if (loadSettingsError) {
+ throw loadSettingsError;
+ }
+
var devMode = loadSettings.devMode || !loadSettings.resourcePath.startsWith(process.resourcesPath + path.sep);
if (loadSettings.profileStartup) {
- profileStartup(cacheDir, loadSettings, Date.now() - startTime);
+ profileStartup(loadSettings, Date.now() - startTime);
} else {
- setupWindow(cacheDir, loadSettings);
+ setupWindow(loadSettings);
setLoadTime(Date.now() - startTime);
}
} catch (error) {
@@ -43,6 +35,15 @@ window.onload = function() {
}
}
+var getCacheDirectory = function() {
+ var cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache');
+ // Use separate compile cache when sudo'ing as root to avoid permission issues
+ if (process.env.USER === 'root' && process.env.SUDO_USER && process.env.SUDO_USER !== process.env.USER) {
+ cacheDir = path.join(cacheDir, 'root');
+ }
+ return cacheDir;
+}
+
var setLoadTime = function(loadTime) {
if (global.atom) {
global.atom.loadTime = loadTime;
@@ -59,7 +60,9 @@ var handleSetupError = function(error) {
console.error(error.stack || error);
}
-var setupWindow = function(cacheDir, loadSettings) {
+var setupWindow = function(loadSettings) {
+ var cacheDir = getCacheDirectory();
+
setupCoffeeCache(cacheDir);
ModuleCache = require('../src/module-cache');
@@ -133,16 +136,17 @@ var setupSourceMapCache = function(cacheDir) {
var setupVmCompatibility = function() {
var vm = require('vm');
- if (!vm.Script.createContext)
+ if (!vm.Script.createContext) {
vm.Script.createContext = vm.createContext;
+ }
}
-var profileStartup = function(cacheDir, loadSettings, initialTime) {
+var profileStartup = function(loadSettings, initialTime) {
var profile = function() {
console.profile('startup');
try {
var startTime = Date.now()
- setupWindow(cacheDir, loadSettings);
+ setupWindow(loadSettings);
setLoadTime(Date.now() - startTime + initialTime);
} catch (error) {
handleSetupError(error);
@@ -162,3 +166,41 @@ var profileStartup = function(cacheDir, loadSettings, initialTime) {
});
}
}
+
+var parseLoadSettings = function() {
+ var rawLoadSettings = decodeURIComponent(location.hash.substr(1));
+ try {
+ loadSettings = JSON.parse(rawLoadSettings);
+ } catch (error) {
+ console.error("Failed to parse load settings: " + rawLoadSettings);
+ loadSettingsError = error;
+ }
+}
+
+var setupWindowBackground = function() {
+ 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';
+ backgroundStylesheet.innerText = 'html, body { background: ' + backgroundColor + '; }';
+ 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);
+}
+
+parseLoadSettings();
+setupWindowBackground();