Mailspring/static/index.js
Ben Gotow e8f7f76080 feat(window-manager): Refactor window code, actually destroy main window when logging out
Summary:
Resolves T1200 and probably others.

This diff moves all the window management / hot loading into a new class called the WindowManager
and also changes the way the app transitions between onboarding and main window. When you log out,
the main window clears config and clearing the config causes the window manager to close the main
window and open the login window. When it detects a token again, it opens the main window.

This means you can't:
- Open the main window from the login window
- Open mailto: links and accidentally see the main window or a composer, since the draft store isn't
  running anywhere.
- Don't need to worry about properly resetting thigns when namespaces change, since the window
  is now actually re-created from scratch with the new auth token.

Be a little more defensive about namespace checks in draft-store

Move window code to window-manager

Rename AtomApplication to just `Application`

Specs fix

Test Plan: Run tests, would be good to have more for this.

Reviewers: evan

Reviewed By: evan

Maniphest Tasks: T1200

Differential Revision: https://review.inboxapp.com/D1501
2015-05-14 14:54:29 -07:00

85 lines
2.6 KiB
JavaScript

// This is to prevent React from displaying an annoying message about
// installing their dev tools. The React dev tools put a variable on the
// global scope. We need to do it here before React loads.
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {}
function registerRuntimeTranspilers() {
// This sets require.extensions['.coffee'].
require('coffee-script').register();
require('coffee-react/register');
// This redefines require.extensions['.js'].
require('../src/6to5').register();
}
window.onload = function() {
try {
var startTime = Date.now();
var fs = require('fs');
var path = require('path');
// Skip "?loadSettings=".
var rawLoadSettings = decodeURIComponent(location.search.substr(14));
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);
var devMode = loadSettings.devMode || !loadSettings.resourcePath.startsWith(process.resourcesPath + path.sep);
// Require before the module cache in dev mode
if (devMode) {
registerRuntimeTranspilers();
}
ModuleCache = require('../src/module-cache');
ModuleCache.register(loadSettings);
ModuleCache.add(loadSettings.resourcePath);
// Start the crash reporter before anything else.
require('crash-reporter').start({
productName: 'Atom',
companyName: 'GitHub',
// By explicitly passing the app version here, we could save the call
// of "require('remote').require('app').getVersion()".
extra: {_version: loadSettings.appVersion}
});
require('vm-compatibility-layer');
if (!devMode) {
registerRuntimeTranspilers();
}
require('../src/coffee-cache').register();
require(loadSettings.bootstrapScript);
// Defer by one tick to make sure the window has rendered. This was in Atom,
// but special cased in Atom.coffee instead of here.
setTimeout(function() {
require('ipc').sendChannel('window-command', 'window:loaded');
}, 1);
if (global.atom) {
global.atom.loadTime = Date.now() - startTime;
console.log('Window load time: ' + global.atom.getWindowLoadTime() + 'ms');
}
}
catch (error) {
var currentWindow = require('remote').getCurrentWindow();
currentWindow.setSize(800, 600);
currentWindow.center();
currentWindow.show();
currentWindow.openDevTools();
console.error(error.stack || error);
console.error(error.message, error);
}
}