From 65ae175e7228f59fdee1ecb68b8a0fdf46a6506d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 13 Oct 2015 19:35:51 -0600 Subject: [PATCH] Pass explicit window global into AtomEnvironment on construction --- spec/atom-environment-spec.coffee | 4 ++-- spec/jasmine-test-runner.coffee | 2 +- spec/window-event-handler-spec.coffee | 2 +- src/atom-environment.coffee | 4 ++-- src/initialize-application-window.coffee | 2 +- src/window-event-handler.coffee | 20 ++++++++++---------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/atom-environment-spec.coffee b/spec/atom-environment-spec.coffee index 574994564..032349381 100644 --- a/spec/atom-environment-spec.coffee +++ b/spec/atom-environment-spec.coffee @@ -213,7 +213,7 @@ describe "AtomEnvironment", -> describe "::unloadEditorWindow()", -> it "saves the serialized state of the window so it can be deserialized after reload", -> - atomEnvironment = new AtomEnvironment(applicationDelegate: atom.applicationDelegate) + atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window}) spyOn(atomEnvironment, 'saveStateSync') workspaceState = atomEnvironment.workspace.serialize() @@ -231,7 +231,7 @@ describe "AtomEnvironment", -> describe "::destroy()", -> it "unsubscribes from all buffers", -> - atomEnvironment = new AtomEnvironment(applicationDelegate: atom.applicationDelegate) + atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window}) waitsForPromise -> atomEnvironment.workspace.open("sample.js") diff --git a/spec/jasmine-test-runner.coffee b/spec/jasmine-test-runner.coffee index 136be9215..00a2dcdd0 100644 --- a/spec/jasmine-test-runner.coffee +++ b/spec/jasmine-test-runner.coffee @@ -18,7 +18,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> applicationDelegate = new ApplicationDelegate() applicationDelegate.setRepresentedFilename = -> applicationDelegate.setWindowDocumentEdited = -> - window.atom = buildAtomEnvironment({applicationDelegate}) + window.atom = buildAtomEnvironment({applicationDelegate, window}) require './spec-helper' disableFocusMethods() if process.env.JANKY_SHA1 or process.env.CI diff --git a/spec/window-event-handler-spec.coffee b/spec/window-event-handler-spec.coffee index 037c15cb0..655dc149c 100644 --- a/spec/window-event-handler-spec.coffee +++ b/spec/window-event-handler-spec.coffee @@ -18,7 +18,7 @@ describe "WindowEventHandler", -> loadSettings.initialPath = initialPath loadSettings atom.project.destroy() - windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate}) + windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window}) projectPath = atom.project.getPaths()[0] afterEach -> diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index d4d88cade..39eac92a1 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -101,7 +101,7 @@ class AtomEnvironment extends Model # Call .loadOrCreate instead constructor: (params={}) -> - {@applicationDelegate} = params + {@applicationDelegate, @window} = params @state = {version: @constructor.version} @@ -652,7 +652,7 @@ class AtomEnvironment extends Model window.onerror = @previousWindowErrorHandler installWindowEventHandler: -> - @windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate}) + @windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window}) uninstallWindowEventHandler: -> @windowEventHandler?.unsubscribe() diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index 242201b32..71dac6898 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -16,7 +16,7 @@ process.env.NODE_ENV ?= 'production' unless devMode AtomEnvironment = require './atom-environment' ApplicationDelegate = require './application-delegate' -window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate}) +window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window}) atom.displayWindow() atom.loadStateSync() diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index bec5bc6cb..cf5a957ca 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -3,17 +3,17 @@ path = require 'path' fs = require 'fs-plus' listen = require './delegated-listener' -# Handles low-level events related to the window. +# Handles low-level events related to the @window. module.exports = class WindowEventHandler - constructor: ({@atomEnvironment, @applicationDelegate}) -> + constructor: ({@atomEnvironment, @applicationDelegate, @window}) -> @reloadRequested = false @subscriptions = new CompositeDisposable - @previousOnbeforeunloadHandler = window.onbeforeunload - window.onbeforeunload = @handleWindowBeforeunload - @addEventListener(window, 'focus', @handleWindowFocus) - @addEventListener(window, 'blur', @handleWindowBlur) + @previousOnbeforeunloadHandler = @window.onbeforeunload + @window.onbeforeunload = @handleWindowBeforeunload + @addEventListener(@window, 'focus', @handleWindowFocus) + @addEventListener(@window, 'blur', @handleWindowBlur) @addEventListener(document, 'keydown', @handleDocumentKeydown) @addEventListener(document, 'drop', @handleDocumentDrop) @@ -22,15 +22,15 @@ class WindowEventHandler @subscriptions.add listen(document, 'click', 'a', @handleLinkClick) @subscriptions.add listen(document, 'submit', 'form', @handleFormSubmit) - @subscriptions.add @atomEnvironment.commands.add window, + @subscriptions.add @atomEnvironment.commands.add @window, 'window:toggle-full-screen': @handleWindowToggleFullScreen 'window:close': @handleWindowClose 'window:reload': @handleWindowReload 'window:toggle-dev-tools': @handleWindowToggleDevTools if process.platform in ['win32', 'linux'] - @subscriptions.add @atomEnvironment.commands.add window, - 'window:toggle-menu-bar': @handleWindowToggleMenuBar + @subscriptions.add @atomEnvironment.commands.add @window, + '@window:toggle-menu-bar': @handleWindowToggleMenuBar @subscriptions.add @atomEnvironment.commands.add document, 'core:focus-next': @handleFocusNext @@ -54,7 +54,7 @@ class WindowEventHandler bindCommandToAction('core:cut', 'cut') unsubscribe: -> - window.onbeforeunload = @previousOnbeforeunloadHandler + @window.onbeforeunload = @previousOnbeforeunloadHandler @subscriptions.dispose() on: (target, eventName, handler) ->