UNPKG

electron-kit

Version:

Utility kits for middle-scale electron app

81 lines (62 loc) 2.91 kB
// Generated by CoffeeScript 1.10.0 (function() { var AppWindow, BrowserWindow, CompositeDisposable, Disposable, Emitter, _, ref, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty, slice = [].slice; BrowserWindow = require("electron").BrowserWindow; _ = require("lodash"); ref = require("event-kit"), CompositeDisposable = ref.CompositeDisposable, Disposable = ref.Disposable; Emitter = require("../utils/Emitter"); /** * BrowserWindow compatible Window class */ module.exports = AppWindow = (function(superClass) { extend(AppWindow, superClass); AppWindow.prototype.browserWindow = null; _.each(Object.keys(BrowserWindow.prototype), function(methodName) { if (methodName === "constructor" || methodName === "on" || methodName === "off" || methodName === "once" || methodName === "addListener" || methodName === "removeListener" || methodName === "destroy") { return; } AppWindow.prototype[methodName] = function() { var args; args = 1 <= arguments.length ? slice.call(arguments, 0) : []; if (this.disposed) { throw new Error("Window has been disposed"); } return BrowserWindow.prototype[methodName].apply(this.browserWindow, args); }; }); function AppWindow(options) { AppWindow.__super__.constructor.apply(this, arguments); this.subscriptions = new CompositeDisposable; this.browserWindow = new BrowserWindow(options); this._handleEvents(); } /** * @protected */ AppWindow.prototype._handleEvents = function() { return ["page-title-updated", "close", "closed", "unresponsive", "responsive", "blur", "focus", "maximize", "unmaximize", "minimize", "restore", "resize", "move", "moved", "enter-full-screen", "leave-full-screen", "enter-html-full-screen", "leave-html-full-screen", "app-command"].forEach((function(_this) { return function(name) { _this.browserWindow.on(name, function() { return _this.emit.apply(_this, [name].concat(slice.call(arguments))); }); return _this.subscriptions.add(new Disposable(function() { return _this.off(name); })); }; })(this)); }; AppWindow.prototype.destroy = function() { return this.dispose(); }; AppWindow.prototype.dispose = function() { this.subscriptions.dispose(); BrowserWindow.prototype.destroy.call(this.browserWindow); this.browserWindow = null; return AppWindow.__super__.dispose.apply(this, arguments); }; return AppWindow; })(Emitter); }).call(this);