/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	Object.defineProperty(exports, '__esModule', {
	  value: true
	});

	var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

	var _crashReporter = __webpack_require__(1);

	var _crashReporter2 = _interopRequireDefault(_crashReporter);

	var _path = __webpack_require__(2);

	var _fs = __webpack_require__(3);

	var _app = __webpack_require__(4);

	var _app2 = _interopRequireDefault(_app);

	var _dialog = __webpack_require__(5);

	var _dialog2 = _interopRequireDefault(_dialog);

	var _shell = __webpack_require__(6);

	var _shell2 = _interopRequireDefault(_shell);

	var _mediator = __webpack_require__(7);

	var _mediator2 = _interopRequireDefault(_mediator);

	var _events = __webpack_require__(9);

	var _events2 = _interopRequireDefault(_events);

	var _menu = __webpack_require__(10);

	var _menu2 = _interopRequireDefault(_menu);

	var _window = __webpack_require__(13);

	var _window2 = _interopRequireDefault(_window);

	_crashReporter2['default'].start();

	var Main = (function () {
	  function Main() {
	    _classCallCheck(this, Main);

	    this.VERSION = _app2['default'].getVersion();
	    this.onWindowClose = this.onWindowClose.bind(this);
	    this.onOpenHelpRequested = this.onOpenHelpRequested.bind(this);
	    this.onOpenAboutDialogRequested = this.onOpenAboutDialogRequested.bind(this);
	    this.onQuitRequested = this.onQuitRequested.bind(this);
	    this.onOpenNewWindowRequested = this.onOpenNewWindowRequested.bind(this);
	    this.onQuit = this.onQuit.bind(this);
	    this.onWindowAllClosed = this.onWindowAllClosed.bind(this);
	    this.onReady = this.onReady.bind(this);

	    _app2['default'].on('ready', this.onReady);
	    _app2['default'].on('window-all-closed', this.onWindowAllClosed);
	    _app2['default'].on('quit', this.onQuit);
	    _mediator2['default'].on(_events2['default'].OPEN_NEW_WINDOW, this.onOpenNewWindowRequested);
	    _mediator2['default'].on(_events2['default'].QUIT, this.onQuitRequested);
	    _mediator2['default'].on(_events2['default'].OPEN_ABOUT_DIALOG, this.onOpenAboutDialogRequested);
	    _mediator2['default'].on(_events2['default'].OPEN_HELP, this.onOpenHelpRequested);
	  }

	  _createClass(Main, [{
	    key: 'onReady',
	    value: function onReady() {
	      var argv = process.argv;

	      console.log('Markn argv:', argv);
	      var filename = argv[1];
	      if (filename) {
	        filename = (0, _path.resolve)(filename);
	        console.log('try to open ' + filename);
	        try {
	          var stats = (0, _fs.statSync)(filename, 'r');
	          if (!stats.isFile()) {
	            filename = null;
	          }
	        } catch (err) {
	          console.error(err);
	          filename = null;
	        }
	      }

	      this.menu = new _menu2['default']();
	      this.openNewWindow(filename);
	    }
	  }, {
	    key: 'onWindowAllClosed',
	    value: function onWindowAllClosed() {
	      if (process.platform !== 'darwin') {
	        _app2['default'].quit();
	      }
	    }
	  }, {
	    key: 'onQuit',
	    value: function onQuit() {
	      console.log('onQuit');
	      this.closeAllWindows();
	    }
	  }, {
	    key: 'onOpenNewWindowRequested',
	    value: function onOpenNewWindowRequested() {
	      this.openNewWindow();
	    }
	  }, {
	    key: 'onQuitRequested',
	    value: function onQuitRequested() {
	      this.quit();
	    }
	  }, {
	    key: 'onOpenAboutDialogRequested',
	    value: function onOpenAboutDialogRequested() {
	      this.openAboutDialog();
	    }
	  }, {
	    key: 'onOpenHelpRequested',
	    value: function onOpenHelpRequested() {
	      this.openHelp();
	    }
	  }, {
	    key: 'openNewWindow',
	    value: function openNewWindow(filename) {
	      if (!filename) {
	        filename = (0, _path.join)(__dirname, '../README.md');
	      }
	      console.log('open ' + filename);

	      var window = new _window2['default'](filename);
	      window.on('close', this.onWindowClose);
	    }
	  }, {
	    key: 'closeAllWindows',
	    value: function closeAllWindows() {
	      _window2['default'].closeAllWindows();
	    }
	  }, {
	    key: 'onWindowClose',
	    value: function onWindowClose(e) {
	      var window = e.currentTarget;
	      window.removeAllListeners();
	    }
	  }, {
	    key: 'quit',
	    value: function quit() {
	      _app2['default'].quit();
	    }
	  }, {
	    key: 'openAboutDialog',
	    value: function openAboutDialog() {
	      _dialog2['default'].showMessageBox({
	        type: 'info',
	        buttons: ['ok'],
	        title: 'About Markn',
	        message: 'Markn',
	        detail: "Lightweight markdown viewer\nv" + this.VERSION
	      });
	    }
	  }, {
	    key: 'openHelp',
	    value: function openHelp() {
	      _shell2['default'].openExternal("https://github.com/minodisk/markn/blob/v" + this.VERSION + "/README.md#readme");
	    }
	  }]);

	  return Main;
	})();

	exports['default'] = Main;

	new Main();
	module.exports = exports['default'];

/***/ },
/* 1 */
/***/ function(module, exports) {

	module.exports = require('crash-reporter');

/***/ },
/* 2 */
/***/ function(module, exports) {

	module.exports = require('path');

/***/ },
/* 3 */
/***/ function(module, exports) {

	module.exports = require('fs');

/***/ },
/* 4 */
/***/ function(module, exports) {

	module.exports = require('app');

/***/ },
/* 5 */
/***/ function(module, exports) {

	module.exports = require('dialog');

/***/ },
/* 6 */
/***/ function(module, exports) {

	module.exports = require('shell');

/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	Object.defineProperty(exports, '__esModule', {
	  value: true
	});

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

	var _events = __webpack_require__(8);

	var _events2 = _interopRequireDefault(_events);

	exports['default'] = new _events2['default']();
	module.exports = exports['default'];

/***/ },
/* 8 */
/***/ function(module, exports) {

	// Copyright Joyent, Inc. and other Node contributors.
	//
	// Permission is hereby granted, free of charge, to any person obtaining a
	// copy of this software and associated documentation files (the
	// "Software"), to deal in the Software without restriction, including
	// without limitation the rights to use, copy, modify, merge, publish,
	// distribute, sublicense, and/or sell copies of the Software, and to permit
	// persons to whom the Software is furnished to do so, subject to the
	// following conditions:
	//
	// The above copyright notice and this permission notice shall be included
	// in all copies or substantial portions of the Software.
	//
	// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
	// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
	// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
	// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
	// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
	// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
	// USE OR OTHER DEALINGS IN THE SOFTWARE.

	'use strict';

	function EventEmitter() {
	  this._events = this._events || {};
	  this._maxListeners = this._maxListeners || undefined;
	}
	module.exports = EventEmitter;

	// Backwards-compat with node 0.10.x
	EventEmitter.EventEmitter = EventEmitter;

	EventEmitter.prototype._events = undefined;
	EventEmitter.prototype._maxListeners = undefined;

	// By default EventEmitters will print a warning if more than 10 listeners are
	// added to it. This is a useful default which helps finding memory leaks.
	EventEmitter.defaultMaxListeners = 10;

	// Obviously not all Emitters should be limited to 10. This function allows
	// that to be increased. Set to zero for unlimited.
	EventEmitter.prototype.setMaxListeners = function (n) {
	  if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number');
	  this._maxListeners = n;
	  return this;
	};

	EventEmitter.prototype.emit = function (type) {
	  var er, handler, len, args, i, listeners;

	  if (!this._events) this._events = {};

	  // If there is no 'error' event listener then throw.
	  if (type === 'error') {
	    if (!this._events.error || isObject(this._events.error) && !this._events.error.length) {
	      er = arguments[1];
	      if (er instanceof Error) {
	        throw er; // Unhandled 'error' event
	      }
	      throw TypeError('Uncaught, unspecified "error" event.');
	    }
	  }

	  handler = this._events[type];

	  if (isUndefined(handler)) return false;

	  if (isFunction(handler)) {
	    switch (arguments.length) {
	      // fast cases
	      case 1:
	        handler.call(this);
	        break;
	      case 2:
	        handler.call(this, arguments[1]);
	        break;
	      case 3:
	        handler.call(this, arguments[1], arguments[2]);
	        break;
	      // slower
	      default:
	        len = arguments.length;
	        args = new Array(len - 1);
	        for (i = 1; i < len; i++) args[i - 1] = arguments[i];
	        handler.apply(this, args);
	    }
	  } else if (isObject(handler)) {
	    len = arguments.length;
	    args = new Array(len - 1);
	    for (i = 1; i < len; i++) args[i - 1] = arguments[i];

	    listeners = handler.slice();
	    len = listeners.length;
	    for (i = 0; i < len; i++) listeners[i].apply(this, args);
	  }

	  return true;
	};

	EventEmitter.prototype.addListener = function (type, listener) {
	  var m;

	  if (!isFunction(listener)) throw TypeError('listener must be a function');

	  if (!this._events) this._events = {};

	  // To avoid recursion in the case that type === "newListener"! Before
	  // adding it to the listeners, first emit "newListener".
	  if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener);

	  if (!this._events[type])
	    // Optimize the case of one listener. Don't need the extra array object.
	    this._events[type] = listener;else if (isObject(this._events[type]))
	    // If we've already got an array, just append.
	    this._events[type].push(listener);else
	    // Adding the second element, need to change to array.
	    this._events[type] = [this._events[type], listener];

	  // Check for listener leak
	  if (isObject(this._events[type]) && !this._events[type].warned) {
	    var m;
	    if (!isUndefined(this._maxListeners)) {
	      m = this._maxListeners;
	    } else {
	      m = EventEmitter.defaultMaxListeners;
	    }

	    if (m && m > 0 && this._events[type].length > m) {
	      this._events[type].warned = true;
	      console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length);
	      if (typeof console.trace === 'function') {
	        // not supported in IE 10
	        console.trace();
	      }
	    }
	  }

	  return this;
	};

	EventEmitter.prototype.on = EventEmitter.prototype.addListener;

	EventEmitter.prototype.once = function (type, listener) {
	  if (!isFunction(listener)) throw TypeError('listener must be a function');

	  var fired = false;

	  function g() {
	    this.removeListener(type, g);

	    if (!fired) {
	      fired = true;
	      listener.apply(this, arguments);
	    }
	  }

	  g.listener = listener;
	  this.on(type, g);

	  return this;
	};

	// emits a 'removeListener' event iff the listener was removed
	EventEmitter.prototype.removeListener = function (type, listener) {
	  var list, position, length, i;

	  if (!isFunction(listener)) throw TypeError('listener must be a function');

	  if (!this._events || !this._events[type]) return this;

	  list = this._events[type];
	  length = list.length;
	  position = -1;

	  if (list === listener || isFunction(list.listener) && list.listener === listener) {
	    delete this._events[type];
	    if (this._events.removeListener) this.emit('removeListener', type, listener);
	  } else if (isObject(list)) {
	    for (i = length; i-- > 0;) {
	      if (list[i] === listener || list[i].listener && list[i].listener === listener) {
	        position = i;
	        break;
	      }
	    }

	    if (position < 0) return this;

	    if (list.length === 1) {
	      list.length = 0;
	      delete this._events[type];
	    } else {
	      list.splice(position, 1);
	    }

	    if (this._events.removeListener) this.emit('removeListener', type, listener);
	  }

	  return this;
	};

	EventEmitter.prototype.removeAllListeners = function (type) {
	  var key, listeners;

	  if (!this._events) return this;

	  // not listening for removeListener, no need to emit
	  if (!this._events.removeListener) {
	    if (arguments.length === 0) this._events = {};else if (this._events[type]) delete this._events[type];
	    return this;
	  }

	  // emit removeListener for all listeners on all events
	  if (arguments.length === 0) {
	    for (key in this._events) {
	      if (key === 'removeListener') continue;
	      this.removeAllListeners(key);
	    }
	    this.removeAllListeners('removeListener');
	    this._events = {};
	    return this;
	  }

	  listeners = this._events[type];

	  if (isFunction(listeners)) {
	    this.removeListener(type, listeners);
	  } else {
	    // LIFO order
	    while (listeners.length) this.removeListener(type, listeners[listeners.length - 1]);
	  }
	  delete this._events[type];

	  return this;
	};

	EventEmitter.prototype.listeners = function (type) {
	  var ret;
	  if (!this._events || !this._events[type]) ret = [];else if (isFunction(this._events[type])) ret = [this._events[type]];else ret = this._events[type].slice();
	  return ret;
	};

	EventEmitter.listenerCount = function (emitter, type) {
	  var ret;
	  if (!emitter._events || !emitter._events[type]) ret = 0;else if (isFunction(emitter._events[type])) ret = 1;else ret = emitter._events[type].length;
	  return ret;
	};

	function isFunction(arg) {
	  return typeof arg === 'function';
	}

	function isNumber(arg) {
	  return typeof arg === 'number';
	}

	function isObject(arg) {
	  return typeof arg === 'object' && arg !== null;
	}

	function isUndefined(arg) {
	  return arg === void 0;
	}

/***/ },
/* 9 */
/***/ function(module, exports) {

	'use strict';

	Object.defineProperty(exports, '__esModule', {
	  value: true
	});
	exports['default'] = {
	  OPEN_NEW_WINDOW: 'open-new-window',
	  OPEN_FILE: 'open-file',
	  OPEN_HELP: 'open-help',
	  QUIT: 'quit',
	  OPEN_ABOUT_DIALOG: 'open-about-dialog',
	  TOGGLE_DEVTOOLS: 'toggle-devtools',
	  RELOAD: 'reload',
	  FIND: 'find',
	  START_FILE: 'start-file'
	};
	module.exports = exports['default'];

/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	Object.defineProperty(exports, '__esModule', {
	  value: true
	});

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

	var _menu = __webpack_require__(11);

	var _menu2 = _interopRequireDefault(_menu);

	var _menuItem = __webpack_require__(12);

	var _menuItem2 = _interopRequireDefault(_menuItem);

	var _mediator = __webpack_require__(7);

	var _mediator2 = _interopRequireDefault(_mediator);

	var _events = __webpack_require__(9);

	var _events2 = _interopRequireDefault(_events);

	var _default = function _default() {
	  _classCallCheck(this, _default);

	  // this.onStartFile = this.onStartFile.bind(this);
	  // mediator.on(events.START_FILE, this.onStartFile);

	  this.menu = _menu2['default'].buildFromTemplate(_menu2['default'].sendActionToFirstResponder != null ? [{
	    label: 'Markn',
	    submenu: [{
	      label: 'About Markn',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_ABOUT_DIALOG);
	      }
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Hide Electron',
	      accelerator: 'CommandOrControl+H',
	      selector: 'hide:'
	    }, {
	      label: 'Hide Others',
	      accelerator: 'CommandOrControl+Shift+H',
	      selector: 'hideOtherApplications:'
	    }, {
	      label: 'Show All',
	      selector: 'unhideAllApplications:'
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Quit',
	      accelerator: 'CommandOrControl+Q',
	      selector: 'terminate:'
	    }]
	  }, {
	    label: 'File',
	    submenu: [{
	      label: 'New Window',
	      accelerator: 'CommandOrControl+N',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_NEW_WINDOW);
	      }
	    }, {
	      label: 'Open File',
	      accelerator: 'CommandOrControl+O',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_FILE);
	      }
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Recently opened files',
	      submenu: []
	    }]
	  }, {
	    label: 'Edit',
	    submenu: [{
	      label: 'Cut',
	      accelerator: 'CommandOrControl+X',
	      selector: 'cut:'
	    }, {
	      label: 'Copy',
	      accelerator: 'CommandOrControl+C',
	      selector: 'copy:'
	    }, {
	      label: 'Paste',
	      accelerator: 'CommandOrControl+V',
	      selector: 'paste:'
	    }, {
	      label: 'Select All',
	      accelerator: 'CommandOrControl+A',
	      selector: 'selectAll:'
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Find',
	      accelerator: 'CommandOrControl+F',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].FIND);
	      }
	    }]
	  }, {
	    label: 'View',
	    submenu: [{
	      label: 'Reload',
	      accelerator: 'CommandOrControl+R',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].RELOAD);
	      }
	    }, {
	      label: 'Toggle DevTools',
	      accelerator: 'Alt+CommandOrControl+I',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].TOGGLE_DEVTOOLS);
	      }
	    }]
	  }, {
	    label: 'Window',
	    submenu: [{
	      label: 'Minimize',
	      accelerator: 'CommandOrControl+M',
	      selector: 'performMiniaturize:'
	    }, {
	      label: 'Close',
	      accelerator: 'CommandOrControl+W',
	      selector: 'performClose:'
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Bring All to Front',
	      selector: 'arrangeInFront:'
	    }]
	  }, {
	    label: 'Help',
	    submenu: [{
	      label: 'Markn Help',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_HELP);
	      }
	    }]
	  }] : [{
	    label: 'File',
	    submenu: [{
	      label: 'New Window',
	      accelerator: 'CommandOrControl+N',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_NEW_WINDOW);
	      }
	    }, {
	      label: 'Open File',
	      accelerator: 'CommandOrControl+O',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_FILE);
	      }
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Recently opened files',
	      submenu: []
	    }, {
	      type: 'separator'
	    }, {
	      label: 'Exit',
	      accelerator: 'CommandOrControl+Q',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].QUIT);
	      }
	    }]
	  }, {
	    label: 'Edit',
	    submenu: [{
	      label: 'Find',
	      accelerator: 'CommandOrControl+F',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].FIND);
	      }
	    }]
	  }, {
	    label: 'View',
	    submenu: [{
	      label: 'Reload',
	      accelerator: 'CommandOrControl+R',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].RELOAD);
	      }
	    }, {
	      label: 'Toggle DevTools',
	      accelerator: 'Alt+CommandOrControl+I',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].TOGGLE_DEVTOOLS);
	      }
	    }]
	  }, {
	    label: 'Help',
	    submenu: [{
	      label: 'About Markn',
	      click: function click() {
	        _mediator2['default'].emit(_events2['default'].OPEN_ABOUT_DIALOG);
	      }
	    }]
	  }]);
	  _menu2['default'].setApplicationMenu(this.menu);

	  // this.menu.items.forEach((item) => {
	  //   switch (item.label) {
	  //     case 'File':
	  //       item.submenu.items.forEach((item) => {
	  //         switch (item.label) {
	  //           case 'Recently opened files':
	  //             this.rof = item.submenu;
	  //             break;
	  //         }
	  //       });
	  //       break;
	  //   }
	  // });
	  // console.log(this.rof);
	}

	// onStartFile(filename) {
	// console.log('----------');

	// let index;
	// this.rof.submenu.items.forEach((f, i) => {
	//   console.log(i, f.label);
	//   if (f.filename === filename) {
	//     index = i;
	//     return false;
	//   }
	// });
	// if (index != null) {
	//   this.items.splice(index, 1);
	// }
	//
	// console.log('   ---   ');

	// this.rof.insert(0, new Item({
	//   label: filename,
	//   click: () => {
	//     console.log('click:', filename);
	//   }
	// }));
	// this.rof.items.forEach((f, i) => {
	//   console.log(i, f.label);
	// });
	// }
	;

	exports['default'] = _default;
	module.exports = exports['default'];

/***/ },
/* 11 */
/***/ function(module, exports) {

	module.exports = require('menu');

/***/ },
/* 12 */
/***/ function(module, exports) {

	module.exports = require('menu-item');

/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	Object.defineProperty(exports, '__esModule', {
	  value: true
	});

	var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

	var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

	function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

	var _events = __webpack_require__(8);

	var _events2 = _interopRequireDefault(_events);

	var _fs = __webpack_require__(3);

	var _path = __webpack_require__(2);

	var _chokidar = __webpack_require__(14);

	var _browserWindow = __webpack_require__(15);

	var _browserWindow2 = _interopRequireDefault(_browserWindow);

	var _dialog = __webpack_require__(5);

	var _shell = __webpack_require__(6);

	var _shell2 = _interopRequireDefault(_shell);

	var _mediator = __webpack_require__(7);

	var _mediator2 = _interopRequireDefault(_mediator);

	var _events3 = __webpack_require__(9);

	var _events4 = _interopRequireDefault(_events3);

	var _storage = __webpack_require__(16);

	var _storage2 = _interopRequireDefault(_storage);

	var _util = __webpack_require__(17);

	var URL = 'file://' + (0, _path.join)(__dirname, '..', 'index.html');
	var EXTENSIONS = ['.markdown', '.mdown', '.mkdn', '.md', '.mkd', '.mdwn', '.mdtxt', '.mdtext', '.text'];

	var Window = (function (_EventEmitter) {
	  _inherits(Window, _EventEmitter);

	  _createClass(Window, null, [{
	    key: 'add',
	    value: function add(window) {
	      if (!this.windows) this.windows = [];
	      this.windows.push(window);
	    }
	  }, {
	    key: 'remove',
	    value: function remove(window) {
	      this.windows.splice(this.windows.indexOf(window), 1);
	    }
	  }, {
	    key: 'closeAllWindows',
	    value: function closeAllWindows() {
	      this.windows.forEach(function (window) {
	        return window.close();
	      });
	    }
	  }]);

	  function Window(filename) {
	    var _this = this;

	    _classCallCheck(this, Window);

	    _get(Object.getPrototypeOf(Window.prototype), 'constructor', this).call(this);

	    Window.add(this);

	    this.filename = filename;
	    this.onFileChanged = this.onFileChanged.bind(this);
	    this.onReloadRequested = this.onReloadRequested.bind(this);
	    this.onFindRequested = this.onFindRequested.bind(this);
	    this.onToggleDevToolsRequested = this.onToggleDevToolsRequested.bind(this);
	    this.onOpenFileRequested = this.onOpenFileRequested.bind(this);
	    this.onClose = this.onClose.bind(this);
	    this.onResized = this.onResized.bind(this);
	    this.onMoved = this.onMoved.bind(this);
	    this.onContentsWillNavigate = this.onContentsWillNavigate.bind(this);
	    this.onContentsDidFinishLoad = this.onContentsDidFinishLoad.bind(this);

	    this.storage = new _storage2['default']();
	    this.storage.get('bounds', function (err, bounds) {
	      if (err) {
	        bounds = {
	          width: 800,
	          height: 600
	        };
	      }
	      _this.browserWindow = new _browserWindow2['default'](bounds);
	      _this.browserWindow.webContents.on('did-finish-load', _this.onContentsDidFinishLoad);
	      _this.browserWindow.webContents.on('will-navigate', _this.onContentsWillNavigate);
	      _this.browserWindow.on('move', _this.onMoved);
	      _this.browserWindow.on('resize', _this.onResized);
	      _this.browserWindow.on('close', _this.onClose);
	      _this.browserWindow.loadUrl(URL);
	      _mediator2['default'].on(_events4['default'].OPEN_FILE, _this.onOpenFileRequested);
	      _mediator2['default'].on(_events4['default'].TOGGLE_DEVTOOLS, _this.onToggleDevToolsRequested);
	      _mediator2['default'].on(_events4['default'].FIND, _this.onFindRequested);
	      _mediator2['default'].on(_events4['default'].RELOAD, _this.onReloadRequested);
	    });
	  }

	  _createClass(Window, [{
	    key: 'destruct',
	    value: function destruct() {
	      this.browserWindow.webContents.removeAllListeners();
	      this.browserWindow.removeAllListeners();
	      _mediator2['default'].removeListener(_events4['default'].OPEN_FILE, this.onOpenFileRequested);
	      _mediator2['default'].removeListener(_events4['default'].TOGGLE_DEVTOOLS, this.onToggleDevToolsRequested);
	      _mediator2['default'].removeListener(_events4['default'].FIND, this.onFindRequested);
	      _mediator2['default'].removeListener(_events4['default'].RELOAD, this.onReloadRequested);
	    }
	  }, {
	    key: 'close',
	    value: function close() {
	      this.browserWindow.close();
	    }
	  }, {
	    key: 'onContentsDidFinishLoad',
	    value: function onContentsDidFinishLoad() {
	      this.start();
	    }
	  }, {
	    key: 'onContentsWillNavigate',
	    value: function onContentsWillNavigate(e, url) {
	      // Renderer file: Reload.
	      if (url === URL) {
	        return;
	      }

	      // Prevent navigation in this application.
	      e.preventDefault();

	      // Markdown file: Render it.
	      if (EXTENSIONS.indexOf((0, _path.extname)(url).toLowerCase()) !== -1) {
	        url = url.replace(/^file:\/*/, '/');
	        this.start(url);
	        return;
	      }

	      // Others: Open external application.
	      _shell2['default'].openExternal(url);
	    }
	  }, {
	    key: 'onMoved',
	    value: function onMoved() {
	      this.registerBounds();
	    }
	  }, {
	    key: 'onResized',
	    value: function onResized() {
	      this.registerBounds();
	    }
	  }, {
	    key: 'onClose',
	    value: function onClose() {
	      console.log('onClose');
	      this.destruct();
	      this.emit('close', {
	        currentTarget: this
	      });
	      Window.remove(this);
	    }
	  }, {
	    key: 'onOpenFileRequested',
	    value: function onOpenFileRequested() {
	      var _this2 = this;

	      if (!this.browserWindow.isFocused()) {
	        return;
	      }
	      (0, _dialog.showOpenDialog)({
	        properties: ['openFile']
	      }, function (filenames) {
	        if (!filenames || !filenames[0]) {
	          return;
	        }
	        _this2.start(filenames[0]);
	      });
	    }
	  }, {
	    key: 'onToggleDevToolsRequested',
	    value: function onToggleDevToolsRequested() {
	      if (!this.browserWindow.isFocused()) {
	        return;
	      }
	      this.browserWindow.toggleDevTools();
	    }
	  }, {
	    key: 'onFindRequested',
	    value: function onFindRequested() {
	      if (!this.browserWindow.isFocused()) {
	        return;
	      }
	      this.browserWindow.webContents.send('openFind');
	    }
	  }, {
	    key: 'onReloadRequested',
	    value: function onReloadRequested() {
	      if (!(this.browserWindow.isFocused() && this.filename != null)) {
	        return;
	      }
	      this.render('');
	      this.start();
	    }
	  }, {
	    key: 'registerBounds',
	    value: function registerBounds() {
	      this.storage.set('bounds', this.browserWindow.getBounds(), function (err) {
	        if (err != null) {
	          throw err;
	        }
	      });
	    }
	  }, {
	    key: 'start',
	    value: function start(filename) {
	      if (filename) {
	        this.filename = (0, _path.normalize)(filename);
	      }

	      if (this.watcher != null) {
	        this.watcher.removeAllListeners();
	        this.watcher.close();
	      }

	      // Watch only local file.
	      if (!/^https?:\/\//.test(this.filename)) {
	        this.watcher = (0, _chokidar.watch)(this.filename);
	        this.watcher.on('change', this.onFileChanged);
	      }

	      this.browserWindow.setTitle(this.filename);
	      this.load(this.filename);
	      _mediator2['default'].emit(_events4['default'].START_FILE, this.filename);
	    }
	  }, {
	    key: 'onFileChanged',
	    value: function onFileChanged(filename) {
	      this.load(filename);
	    }
	  }, {
	    key: 'load',
	    value: function load(filename) {
	      var _this3 = this;

	      (0, _fs.readFile)(filename, 'utf8', function (err, data) {
	        if (err != null) {
	          throw err;
	        }
	        _this3.render(data, (0, _path.dirname)(filename));
	      });
	    }
	  }, {
	    key: 'render',
	    value: function render(md, dir) {
	      this.browserWindow.webContents.send('render', md, dir);
	    }
	  }]);

	  return Window;
	})(_events2['default']);

	exports['default'] = Window;
	module.exports = exports['default'];

/***/ },
/* 14 */
/***/ function(module, exports) {

	module.exports = require('chokidar');

/***/ },
/* 15 */
/***/ function(module, exports) {

	module.exports = require('browser-window');

/***/ },
/* 16 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	Object.defineProperty(exports, '__esModule', {
	  value: true
	});

	var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

	var _app = __webpack_require__(4);

	var _app2 = _interopRequireDefault(_app);

	var _path = __webpack_require__(2);

	var _fs = __webpack_require__(3);

	var Storage = (function () {
	  function Storage() {
	    _classCallCheck(this, Storage);

	    this.dataDir = _app2['default'].getPath('userData');
	  }

	  _createClass(Storage, [{
	    key: 'get',
	    value: function get(key, cb) {
	      (0, _fs.readFile)(this.path(key), 'utf8', function (err, data) {
	        if (err != null) {
	          cb(err);
	          return;
	        }
	        cb(null, JSON.parse(data));
	      });
	    }
	  }, {
	    key: 'set',
	    value: function set(key, val, cb) {
	      (0, _fs.writeFile)(this.path(key), JSON.stringify(val), function (err) {
	        cb(err);
	      });
	    }
	  }, {
	    key: 'path',
	    value: function path(key) {
	      return (0, _path.join)(this.dataDir, key);
	    }
	  }]);

	  return Storage;
	})();

	exports['default'] = Storage;
	module.exports = exports['default'];

/***/ },
/* 17 */
/***/ function(module, exports) {

	"use strict";

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	exports["default"] = {
	  bindTarget: function bindTarget(cb) {
	    return function (e) {
	      e.currentTarget = this;
	      return cb(e);
	    };
	  }
	};
	module.exports = exports["default"];

/***/ }
/******/ ]);