<commit_before>path = require 'path'
{$} = require './space-pen-extensions'
_ = require 'underscore-plus'
ipc = require 'ipc'
shell = require 'shell'
{Subscriber} = require 'emissary'
fs = require 'fs-plus'

# Handles low-level events related to the window.
module.exports =
class WindowEventHandler
  Subscriber.includeInto(this)

  constructor: ->
    @reloadRequested = false

    @subscribe ipc, 'message', (message, detail) ->
      switch message
        when 'open-path'
          {pathToOpen, initialLine, initialColumn} = detail

          unless atom.project?.getPaths().length
            if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen))
              atom.project?.setPaths([pathToOpen])

          unless fs.isDirectorySync(pathToOpen)
            atom.workspace?.open(pathToOpen, {initialLine, initialColumn})

        when 'update-available'
          atom.updateAvailable(detail)

          # FIXME: Remove this when deprecations are removed
          {releaseVersion, releaseNotes} = detail
          detail = [releaseVersion, releaseNotes]
          atom.commands.dispatch atom.views.getView(atom.workspace), "window:update-available", detail

    @subscribe ipc, 'command', (command, args...) ->
      activeElement = document.activeElement
      # Use the workspace element view if body has focus
      if activeElement is document.body and workspaceElement = atom.views.getView(atom.workspace)
        activeElement = workspaceElement<commit_msg>Null guard workspace element for deprecated update-available dispatch<commit_after>path = require 'path'
{$} = require './space-pen-extensions'
_ = require 'underscore-plus'
ipc = require 'ipc'
shell = require 'shell'
{Subscriber} = require 'emissary'
fs = require 'fs-plus'

# Handles low-level events related to the window.
module.exports =
class WindowEventHandler
  Subscriber.includeInto(this)

  constructor: ->
    @reloadRequested = false

    @subscribe ipc, 'message', (message, detail) ->
      switch message
        when 'open-path'
          {pathToOpen, initialLine, initialColumn} = detail

          unless atom.project?.getPaths().length
            if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen))
              atom.project?.setPaths([pathToOpen])

          unless fs.isDirectorySync(pathToOpen)
            atom.workspace?.open(pathToOpen, {initialLine, initialColumn})

        when 'update-available'
          atom.updateAvailable(detail)

          # FIXME: Remove this when deprecations are removed
          {releaseVersion, releaseNotes} = detail
          detail = [releaseVersion, releaseNotes]
          if workspaceElement = atom.views.getView(atom.workspace)
            atom.commands.dispatch workspaceElement, "window:update-available", detail

    @subscribe ipc, 'command', (command, args...) ->
      activeElement = document.activeElement
      # Use the workspace element view if body has focus
      if activeElement is document.body and workspaceElement = atom.views.getView(atom.workspace)
        activeElement = workspaceElement
{'fraction_non_alphanumeric': 0.09977324263038549, 'fraction_numerical': 0.0, 'mean_word_length': 3.1899592944369064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1984750', 'n_tokens_mistral': 826, 'n_tokens_neox': 806, 'n_words': 215}