<commit_before>require 'coffee-react/register'
path = require 'path-extra'
fs = require 'fs-extra'
os = require 'os'
semver = require 'semver'
glob = require 'glob'

# Environments
window.remote = require('electron').remote
window.ROOT = path.join(__dirname, '..')
window.Tray = remote.require('electron').Tray
window.EXROOT = remote.getGlobal 'EXROOT'
window.APPDATA_PATH = remote.getGlobal 'APPDATA_PATH'
window.PLUGIN_PATH = path.join window.APPDATA_PATH, 'plugins'
window.POI_VERSION = remote.getGlobal 'POI_VERSION'
window.SERVER_HOSTNAME = remote.getGlobal 'SERVER_HOSTNAME'
window.MODULE_PATH = remote.getGlobal 'MODULE_PATH'
fs.ensureDirSync window.PLUGIN_PATH
fs.ensureDirSync path.join window.PLUGIN_PATH, 'node_modules'

# Shortcuts and Components
window._ = require 'underscore'
window.$ = (param) -> document.querySelector(param)
window.$$ = (param) -> document.querySelectorAll(param)
window.jQuery = require path.join(ROOT, 'components/jquery/dist/jquery')
window.React = require 'react'
window.ReactDOM = require 'react-dom'
window.ReactBootstrap = require 'react-bootstrap'
window.FontAwesome = require 'react-fontawesome'
{remoteStringify} = remote.require './lib/utils'

# Utils
Object.clone = (obj) ->
  JSON.parse JSON.stringify obj
Object.remoteClone = (obj) ->
  JSON.parse remoteStringify obj

pad = (n) ->
  if n < 10 then "0#{n}" else n
window.resolveTime = (seconds) ->
  seconds = parseInt seconds
  if seconds >= 0
    s = seconds % 60
    m = Math.trunc(seconds / 60) % 60
    h = Math.trunc(seconds / 3600)
    "#{pad h}:#{pad m}:#{pad s}"
  else
    ''
window.timeToString = (milliseconds) ->
  date = new Date(milliseconds)
  date.toTimeString().slice(0, 8)  # HH:mm:ss

## window.notify
# msg=null: Sound-only notification.
NOTIFY_DEFAULT_ICON = path.join(ROOT, 'assets', 'icons', 'icon.png')
NOTIFY_NOTIFICATION_API = true
if process.platform == 'win32' and semver.lt(os.release(), '6.2.0')
  NOTIFY_NOTIFICATION_API = false
window.notify = (msg, options) ->
  # Notification config
  enabled = config.get('poi.notify.enabled', true)
  audio = config.get('poi.notify.audio', "file://#{ROOT}/assets/audio/poi.mp3")
  volume = config.get('poi.notify.volume', 0.8)
  title = 'poi'
  icon = NOTIFY_DEFAULT_ICON
  switch options?.type
    when 'construction'
      enabled = config.get('poi.notify.construction.enabled', enabled) if enabled
      audio = config.get('poi.notify.construction.audio', audio)
    when 'expedition'
      enabled = config.get('poi.notify.expedition.enabled', enabled) if enabled
      audio = config.get('poi.notify.expedition.audio', audio)
    when 'repair'
      enabled = config.get('poi.notify.repair.enabled', enabled) if enabled
      audio = config.get('poi.notify.repair.audio', audio)
    when 'morale'
      enabled = config.get('poi.notify.morale.enabled', enabled) if enabled
      audio = config.get('poi.notify.morale.audio', audio)
    else
      enabled = config.get('poi.notify.others.enabled', enabled) if enabled
  # Overwrite by options
  if options?
    title = options.title if options.title
    icon = options.icon if options.icon
    audio = options.audio if options.audio

  # Send desktop notification
  #   According to MDN Notification API docs: https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification
  #   Parameter `sound` is not supported in any browser yet, so we play sound manually.
  return unless enabled
  if msg?
    if NOTIFY_NOTIFICATION_API
      new Notification title,
        icon: "file://#{icon}"
        body: msg
        silent: true
    else
      Tray.displayBalloon
        title: title
        icon: icon
        content: msg
  if volume > 0.0001
    sound = new Audio(audio)
    sound.volume = volume
    sound.play()

modals = []
window.modalLocked = false
window.toggleModal = (title, content, footer) ->
  modals.push
    title: title
    content: content
    footer: footer
  window.showModal() if !window.modalLocked
window.showModal = ->
  return if modals.length == 0
  {title, content, footer} = modals.shift()
  event = new CustomEvent 'poi.modal',
    bubbles: true
    cancelable: true
    detail:
      title: title
      content: content
      footer: footer
  window.dispatchEvent event

# Node modules<commit_msg>Fix misuse if Tray<commit_after>require 'coffee-react/register'
path = require 'path-extra'
fs = require 'fs-extra'
os = require 'os'
semver = require 'semver'
glob = require 'glob'

# Environments
window.remote = require('electron').remote
window.ROOT = path.join(__dirname, '..')
window.Tray = remote.require('electron').Tray
window.EXROOT = remote.getGlobal 'EXROOT'
window.APPDATA_PATH = remote.getGlobal 'APPDATA_PATH'
window.PLUGIN_PATH = path.join window.APPDATA_PATH, 'plugins'
window.POI_VERSION = remote.getGlobal 'POI_VERSION'
window.SERVER_HOSTNAME = remote.getGlobal 'SERVER_HOSTNAME'
window.MODULE_PATH = remote.getGlobal 'MODULE_PATH'
fs.ensureDirSync window.PLUGIN_PATH
fs.ensureDirSync path.join window.PLUGIN_PATH, 'node_modules'

# Shortcuts and Components
window._ = require 'underscore'
window.$ = (param) -> document.querySelector(param)
window.$$ = (param) -> document.querySelectorAll(param)
window.jQuery = require path.join(ROOT, 'components/jquery/dist/jquery')
window.React = require 'react'
window.ReactDOM = require 'react-dom'
window.ReactBootstrap = require 'react-bootstrap'
window.FontAwesome = require 'react-fontawesome'
{remoteStringify} = remote.require './lib/utils'

# Utils
Object.clone = (obj) ->
  JSON.parse JSON.stringify obj
Object.remoteClone = (obj) ->
  JSON.parse remoteStringify obj

pad = (n) ->
  if n < 10 then "0#{n}" else n
window.resolveTime = (seconds) ->
  seconds = parseInt seconds
  if seconds >= 0
    s = seconds % 60
    m = Math.trunc(seconds / 60) % 60
    h = Math.trunc(seconds / 3600)
    "#{pad h}:#{pad m}:#{pad s}"
  else
    ''
window.timeToString = (milliseconds) ->
  date = new Date(milliseconds)
  date.toTimeString().slice(0, 8)  # HH:mm:ss

## window.notify
# msg=null: Sound-only notification.
NOTIFY_DEFAULT_ICON = path.join(ROOT, 'assets', 'icons', 'icon.png')
NOTIFY_NOTIFICATION_API = true
if process.platform == 'win32' and semver.lt(os.release(), '6.2.0')
  NOTIFY_NOTIFICATION_API = false
window.notify = (msg, options) ->
  # Notification config
  enabled = config.get('poi.notify.enabled', true)
  audio = config.get('poi.notify.audio', "file://#{ROOT}/assets/audio/poi.mp3")
  volume = config.get('poi.notify.volume', 0.8)
  title = 'poi'
  icon = NOTIFY_DEFAULT_ICON
  switch options?.type
    when 'construction'
      enabled = config.get('poi.notify.construction.enabled', enabled) if enabled
      audio = config.get('poi.notify.construction.audio', audio)
    when 'expedition'
      enabled = config.get('poi.notify.expedition.enabled', enabled) if enabled
      audio = config.get('poi.notify.expedition.audio', audio)
    when 'repair'
      enabled = config.get('poi.notify.repair.enabled', enabled) if enabled
      audio = config.get('poi.notify.repair.audio', audio)
    when 'morale'
      enabled = config.get('poi.notify.morale.enabled', enabled) if enabled
      audio = config.get('poi.notify.morale.audio', audio)
    else
      enabled = config.get('poi.notify.others.enabled', enabled) if enabled
  # Overwrite by options
  if options?
    title = options.title if options.title
    icon = options.icon if options.icon
    audio = options.audio if options.audio

  # Send desktop notification
  #   According to MDN Notification API docs: https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification
  #   Parameter `sound` is not supported in any browser yet, so we play sound manually.
  return unless enabled
  if msg?
    if NOTIFY_NOTIFICATION_API
      new Notification title,
        icon: "file://#{icon}"
        body: msg
        silent: true
    else
      appIcon = new Tray(path.join(ROOT, 'assets', 'icons', 'poi.ico'));
      appIcon.displayBalloon
        title: title
        icon: icon
        content: msg
      destroyAppIcon = ->
        appIcon.destroy()
      appIcon.on 'balloon-closed', destroyAppIcon

  if volume > 0.0001
    sound = new Audio(audio)
    sound.volume = volume
    sound.play()

modals = []
window.modalLocked = false
window.toggleModal = (title, content, footer) ->
  modals.push
    title: title
    content: content
    footer: footer
  window.showModal() if !window.modalLocked
window.showModal = ->
  return if modals.length == 0
  {title, content, footer} = modals.shift()
  event = new CustomEvent 'poi.modal',
    bubbles: true
    cancelable: true
    detail:
      title: title
      content: content
      footer: footer
  window.dispatchEvent event

# Node modules
{'fraction_non_alphanumeric': 0.1268090971743625, 'fraction_numerical': 0.006891798759476223, 'mean_word_length': 3.6837009144701454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5169863', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2770, 'n_words': 683}